Skip to content

Commit

Permalink
add domino to vendor and fix turndown package
Browse files Browse the repository at this point in the history
  • Loading branch information
tztsai committed Nov 8, 2024
1 parent dde7284 commit e6a80fb
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 0 deletions.
18 changes: 18 additions & 0 deletions background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
importScripts('/vendor/markdown-it.min.js')
importScripts('/vendor/marked.min.js')
importScripts('/vendor/remark.min.js')
importScripts('/vendor/turndown.min.js')
importScripts('/vendor/domino.min.js')
importScripts('/background/compilers/markdown-it.js')
importScripts('/background/compilers/marked.js')
importScripts('/background/compilers/remark.js')
Expand Down Expand Up @@ -34,6 +36,22 @@ importScripts('/background/icon.js')

chrome.tabs.onUpdated.addListener(detect.tab)
chrome.runtime.onMessage.addListener(messages)

chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "convertToMarkdown",
title: "Convert to Markdown",
contexts: ["page"]
});
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "convertToMarkdown") {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["/content/turndown.js"]
});
}
});

icon()
})()
18 changes: 18 additions & 0 deletions build/domino/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# set current working directory to directory of the shell script
cd "$(dirname "$0")"

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

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

# copy
cp tmp/domino.min.js ../../vendor/

# after
rm -rf node_modules/ tmp/
5 changes: 5 additions & 0 deletions build/domino/domino.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Import necessary modules from the @mixmark-io/domino package
import { createWindow, createDocument } from '@mixmark-io/domino';

// Export the modules for use in your project
export { createWindow, createDocument };
7 changes: 7 additions & 0 deletions build/domino/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-node-resolve": "^15.3.0",
"@mixmark-io/domino": "^2.2.0"
}
}
15 changes: 15 additions & 0 deletions build/domino/rollup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';

export default {
input: 'node_modules/@mixmark-io/domino/lib/index.js',
output: {
file: 'tmp/domino.js',
format: 'umd',
name: 'domino'
},
plugins: [
commonjs(),
resolve()
]
};
1 change: 1 addition & 0 deletions build/turndown/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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 terser --compress --mangle -- tmp/turndown.js > tmp/turndown.min.js

# copy
Expand Down
1 change: 1 addition & 0 deletions build/turndown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dependencies": {
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-node-resolve": "^15.3.0",
"browserify": "^17.0.1",
"turndown": "^7.2.0"
}
}
16 changes: 16 additions & 0 deletions content/turndown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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 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>');
};

0 comments on commit e6a80fb

Please sign in to comment.