Selaa lähdekoodia

Update marked to v9

simov 2 vuotta sitten
vanhempi
sitoutus
41f374db87

+ 10 - 4
background/compilers/marked.js

@@ -6,16 +6,17 @@ md.compilers.marked = (() => {
     breaks: false,
     gfm: true,
     pedantic: false,
-    sanitize: false,
+    // plugins
+    linkify: true,
     smartypants: false,
-    langPrefix: 'language-' // prism
   }
 
   var description = {
     breaks: 'Enable GFM line breaks\n(requires the gfm option to be true)',
     gfm: 'Enable GFM\n(GitHub Flavored Markdown)',
     pedantic: 'Don\'t fix any of the original markdown\nbugs or poor behavior',
-    sanitize: 'Ignore any HTML\nthat has been input',
+    // plugins
+    linkify: 'Autoconvert URL-like text to links',
     smartypants: 'Use "smart" typographic punctuation\nfor things like quotes and dashes'
   }
 
@@ -23,7 +24,12 @@ md.compilers.marked = (() => {
     defaults,
     description,
     compile: (markdown) =>
-      marked.parse(markdown, state.marked)
+      new marked.marked(
+        state.marked,
+        marked.headings(),
+        state.marked.linkify ? marked.linkify() : () => {},
+        state.marked.smartypants ? marked.smartypants() : () => {},
+      ).parse(markdown)
   })
 
   return Object.assign(ctor, {defaults, description})

+ 7 - 0
background/storage.js

@@ -174,5 +174,12 @@ md.storage.migrations = (state) => {
       sup: false,
       tasklists: false,
     })
+
+  }
+  if (state.marked.linkify === undefined) {
+    Object.assign(state.marked, {
+      linkify: true,
+    })
+    delete state.marked.sanitize
   }
 }

+ 4 - 1
build/README.md

@@ -44,7 +44,10 @@ sh build/package.sh
 | markdown-it-sub     | ^1.0.0
 | markdown-it-sup     | ^1.0.0
 | markdown-it-task-lists | ^2.1.1
-| marked              |  4.2.5
+| marked                | ^9.0.0
+| marked-gfm-heading-id | ^3.0.8
+| marked-linkify-it     | ^3.1.4
+| marked-smartypants    | ^1.1.3
 | mathjax             |  3.2.2
 | mermaid             |  9.4.0
 | mithril             |  1.1.6

+ 14 - 1
build/marked/build.sh

@@ -3,4 +3,17 @@
 # set current working directory to directory of the shell script
 cd "$(dirname "$0")"
 
-curl https://cdnjs.cloudflare.com/ajax/libs/marked/4.2.5/marked.min.js --output ../../vendor/marked.min.js
+# before
+npm install
+mkdir -p tmp
+
+# marked.min.js
+npx rollup --config rollup.js --input marked.mjs --file tmp/marked.js
+npx terser --compress --mangle -- tmp/marked.js > tmp/marked.min.js
+
+# copy
+cp tmp/marked.min.js ../../vendor/
+
+# after
+rm -r tmp/
+rm -rf node_modules/ package-lock.json

+ 12 - 0
build/marked/marked.mjs

@@ -0,0 +1,12 @@
+
+import {Marked as marked} from 'marked'
+import {gfmHeadingId as headings} from 'marked-gfm-heading-id'
+import linkify from 'marked-linkify-it'
+import {markedSmartypants as smartypants} from 'marked-smartypants'
+
+export {
+  marked,
+  headings,
+  linkify,
+  smartypants,
+}

+ 22 - 0
build/marked/package.json

@@ -0,0 +1,22 @@
+{
+  "name": "markdown-viewer",
+  "version": "0.0.0",
+  "description": "Markdown Viewer / Browser Extension",
+  "private": true,
+  "dependencies": {
+    "marked": "^9.0.0",
+    "marked-gfm-heading-id": "^3.0.8",
+    "marked-linkify-it": "^3.1.4",
+    "marked-smartypants": "^1.1.3"
+  },
+  "devDependencies": {
+    "@rollup/plugin-commonjs": "^23.0.2",
+    "@rollup/plugin-node-resolve": "^15.0.1",
+    "rollup": "^2.35.1",
+    "rollup-plugin-polyfill-node": "^0.11.0",
+    "terser": "^5.5.1"
+  },
+  "engines": {
+    "node": ">=14.0.0"
+  }
+}

+ 21 - 0
build/marked/rollup.js

@@ -0,0 +1,21 @@
+
+var common = require('@rollup/plugin-commonjs')
+var resolve = require('@rollup/plugin-node-resolve')
+var node = require('rollup-plugin-polyfill-node')
+
+
+export default {
+  context: 'window',
+  moduleContext: {id: 'window'},
+
+  plugins: [
+    common(),
+    resolve(),
+    node(),
+  ],
+
+  output: {
+    format: 'iife',
+    name: 'marked',
+  },
+}