Skip to content

Commit

Permalink
update turndown script
Browse files Browse the repository at this point in the history
  • Loading branch information
tztsai committed Nov 8, 2024
1 parent e6a80fb commit 77f2b15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
6 changes: 2 additions & 4 deletions build/domino/domino.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Import necessary modules from the @mixmark-io/domino package
import { createWindow, createDocument } from '@mixmark-io/domino';
import { createDocument } from "domino";

// Export the modules for use in your project
export { createWindow, createDocument };
export default createDocument;
2 changes: 1 addition & 1 deletion build/turndown/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mkdir -p tmp

# turndown.min.js
npx rollup --config rollup.mjs --input turndown.mjs --file tmp/turndown.js
npx browserify tmp/turndown.js > tmp/turndown.js
# npx browserify tmp/turndown.js > tmp/turndown.js
npx terser --compress --mangle -- tmp/turndown.js > tmp/turndown.min.js

# copy
Expand Down
18 changes: 8 additions & 10 deletions content/turndown.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
if (!window.TurndownScript) {
const turndownScript = document.createElement('script');
turndownScript.src = chrome.runtime.getURL('vendor/turndown/turndown.browser.umd.js');
document.head.appendChild(turndownScript);
window.TurndownScript = turndownScript;
}

window.TurndownScript.onload = () => {
const turndownScript = document.createElement('script');
turndownScript.src = chrome.runtime.getURL('vendor/turndown.min.js');
const dominoScript = document.createElement('script');
dominoScript.src = chrome.runtime.getURL('vendor/domino.min.js');
turndownScript.onload = () => {
const turndownService = new TurndownService();
const markdown = turndownService.turndown(document.documentElement.outerHTML);
console.log(markdown);

// Create a new window to display the Markdown
const markdownWindow = window.open('', '_blank');
markdownWindow.document.write('<pre>' + markdownWindow.document.createTextNode(markdown).textContent + '</pre>');
};
};
document.head.appendChild(dominoScript);
document.head.appendChild(turndownScript);

0 comments on commit 77f2b15

Please sign in to comment.