Skip to content

Commit

Permalink
Update turndown integration and enhance Markdown processing features
Browse files Browse the repository at this point in the history
  • Loading branch information
tztsai committed Nov 10, 2024
1 parent fda0d58 commit ffca245
Show file tree
Hide file tree
Showing 8 changed files with 1,065 additions and 72 deletions.
2 changes: 1 addition & 1 deletion background/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ md.messages = ({storage: {defaults, state, set}, compilers, mathjax, xhr, webreq
}, sendResponse)
}
else if (req.message === 'inject') {
chrome.tabs.query({ }, (tabs) => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
for (var tab of tabs) {
if (tab.url === req.url) {
md.inject({storage: {state}})(tab.id);
Expand Down
6 changes: 3 additions & 3 deletions background/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ md.storage.defaults = (compilers) => {
},
content: {
autoreload: false,
emoji: false,
mathjax: false,
emoji: true,
mathjax: true,
mermaid: false,
syntax: true,
toc: false,
toc: true,
},
origins: {
'file://': {
Expand Down
23 changes: 9 additions & 14 deletions build/turndown/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@ cd "$(dirname "$0")"

# before
npm ci 2> /dev/null || npm i
mkdir -p tmp

# turndown.min.js
npx rollup --config rollup.mjs --input turndown.mjs --file tmp/turndown.js
# # turndown.min.js
# npx rollup --config rollup.mjs --input turndown.mjs --file turndown.js

# Replace the function containing `require` with the async function
sed -i '/var domino = require('"'"'@mixmark-io\/domino'"'"');/ {
N
s/var domino = require('"'"'@mixmark-io\/domino'"'"');\n\s*Parser.prototype.parseFromString = function (string) {/Parser.prototype.parseFromString = async function (string) {\n var domino = await import("\/vendor\/domino.min.js");/
}' tmp/turndown.js
# # Replace the function containing `require` with the async function
# sed -i '/var domino = require('"'"'@mixmark-io\/domino'"'"');/ {
# N
# s/var domino = require('"'"'@mixmark-io\/domino'"'"');\n\s*Parser.prototype.parseFromString = function (string) {/Parser.prototype.parseFromString = async function (string) {\n var domino = await import("\/vendor\/domino.min.js");/
# }' turndown.js


npx terser --compress --mangle -- tmp/turndown.js > tmp/turndown.min.js

# copy
cp tmp/turndown.min.js ../../vendor/
npx terser --compress --mangle -- turndown.js > ../../vendor/turndown.min.js

# after
rm -rf node_modules/ tmp/
rm -rf node_modules/
1 change: 1 addition & 0 deletions build/turndown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-node-resolve": "^15.3.0",
"browserify": "^17.0.1",
"rollup": "^4.25.0",
"turndown": "^7.2.0"
}
}
Loading

0 comments on commit ffca245

Please sign in to comment.