From af5b22e64e546f6d2b4c397197d8d670c61eefed Mon Sep 17 00:00:00 2001 From: Ben Lau Date: Wed, 2 Feb 2022 00:34:12 +0800 Subject: [PATCH] Escape the tag title --- README.md | 4 ++++ src/index.ts | 10 +++++++++- src/manifest.json | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cf3d30b..3290d41 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,9 @@ Tag Links is a Joplin plugin that inserts a list of tags of the note at the footer automatically. Those tags are clickable to search notes by the tag. +![screenshot](https://raw.githubusercontent.com/benlau/joplin-plugin-tag-links/main/docs/screenshot.jpg) +Known Issues +- It does not works with the "Automatic backlinks" plugin +- It could not refresh immediately when the tags are updated. \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 5d6f60d..b6012d9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,13 +3,21 @@ import { ContentScriptType } from 'api/types'; const contentScriptId = "joplin-plugin-tag-links" +const escape = document.createElement('textarea'); + +function escapeHtml(html) { + escape.textContent = html; + return escape.innerHTML; +} + async function onMessage(message:any ) { if (message.type === "renderTags") { const activeNote = await joplin.workspace.selectedNote(); const tags = await joplin.data.get(["notes", activeNote.id, "tags"]) const links = tags.items.map( (item) => { const js = `onclick="webviewApi.postMessage('${contentScriptId}', {type:'openTag', tagId:'${item.id}'});return false;"` - return `${item.title}` + const title = escapeHtml(item.title) + return `${title}` }) return `
${links.join("\n")}
` } else if (message.type == "openTag") { diff --git a/src/manifest.json b/src/manifest.json index 4a83c19..1f9807a 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -4,9 +4,9 @@ "app_min_version": "1.7", "version": "0.1.0", "name": "Tag Links", - "description": "Insert links of tag at the bottom of the note automatically", + "description": "Insert the link of tags at the footer automatically", "author": "Ben Lau", - "homepage_url": "", - "repository_url": "", + "homepage_url": "https://github.com/benlau/joplin-plugin-tag-links", + "repository_url": "https://github.com/benlau/joplin-plugin-tag-links", "keywords": [] } \ No newline at end of file