Skip to content

Commit

Permalink
fix: missing html encoding in bookmark title
Browse files Browse the repository at this point in the history
  • Loading branch information
igorlogius committed Jun 22, 2024
1 parent ad072c6 commit 4c7bfa8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ jobs:
ISSUER: ${{secrets.ISSUER}}
SECRET: ${{secrets.SECRET}}
run: curl 'https://raw.githubusercontent.com/igorlogius/meta-addon-builder/main/README' | sh



19 changes: 9 additions & 10 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* global browser */

function htmlEncode(input) {
const textArea = document.createElement("textarea");
textArea.innerText = input;
return textArea.innerHTML.split("<br>").join("\n");
}
const toHtmlEntities = (str, showInHtml = false) =>
[...str]
.map((v) => `${showInHtml ? `&amp;#` : `&#`}${v.codePointAt(0)};`)
.join(``);

async function exportJSON(bookmarkId) {
if (typeof bookmarkId !== "string") {
Expand All @@ -18,7 +17,7 @@ async function exportJSON(bookmarkId) {
dl.setAttribute("href", window.URL.createObjectURL(textFileAsBlob));
dl.setAttribute(
"download",
"export " + (bookmarkId === "root________" ? "all" : data.title) + ".json"
"export " + (bookmarkId === "root________" ? "all" : data.title) + ".json",
);
dl.setAttribute("visibility", "hidden");
dl.setAttribute("display", "none");
Expand All @@ -33,8 +32,8 @@ function rec2HtmlStr(bmTreeNode, level = 1) {
let out = "";
"\t".repeat(level);
let tmp = "";
const title =
typeof bmTreeNode.title === "string" ? htmlEncode(bmTreeNode.title) : "";
let title = typeof bmTreeNode.title === "string" ? bmTreeNode.title : "";
title = toHtmlEntities(title);
if (typeof bmTreeNode.url === "string") {
out =
out +
Expand All @@ -46,7 +45,7 @@ function rec2HtmlStr(bmTreeNode, level = 1) {
"</A>" +
"\n";
} else if (Array.isArray(bmTreeNode.children)) {
tmp = "\t".repeat(level) + "<DT><H3>" + htmlEncode(title) + "</H3>" + "\n";
tmp = "\t".repeat(level) + "<DT><H3>" + title + "</H3>" + "\n";
if (bmTreeNode.children.length > 0) {
out = out + tmp;
out = out + "\t".repeat(level) + "<DL><p>" + "\n";
Expand Down Expand Up @@ -98,7 +97,7 @@ async function exportHTML(bookmarkId) {
dl.setAttribute("href", window.URL.createObjectURL(textFileAsBlob));
dl.setAttribute(
"download",
"export " + (bookmarkId === "root________" ? "all" : data.title) + ".html"
"export " + (bookmarkId === "root________" ? "all" : data.title) + ".html",
);
dl.setAttribute("visibility", "hidden");
dl.setAttribute("display", "none");
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"description": "Import or export a branch of the bookmark tree as a JSON or HTML file",
"name": "Bookmark Branch Porter",
"permissions": ["menus", "bookmarks"],
"version": "1.4.16"
"version": "1.4.17"
}
2 changes: 1 addition & 1 deletion options.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<head>
<meta content="text/html;charset=utf-8" />
<style>
Expand Down

0 comments on commit 4c7bfa8

Please sign in to comment.