Skip to content

Commit

Permalink
Escape the tag title
Browse files Browse the repository at this point in the history
  • Loading branch information
benlau committed Feb 1, 2022
1 parent 8c58013 commit af5b22e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<a class="joplinTagLinksLink" href="#" ${js}>${item.title}</a>`
const title = escapeHtml(item.title)
return `<a class="joplinTagLinksLink" href="#" ${js}>${title}</a>`
})
return `<div>${links.join("\n")}</div>`
} else if (message.type == "openTag") {
Expand Down
6 changes: 3 additions & 3 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}

0 comments on commit af5b22e

Please sign in to comment.