Browse Source

Add remark compiler

simov 8 years ago
parent
commit
e394a821a4

+ 6 - 0
background/background.js

@@ -9,6 +9,7 @@ chrome.storage.sync.get((res) => {
     theme: 'github',
     compiler: 'marked',
     marked: md.marked.defaults,
+    remark: md.remark.defaults,
     showdown: md.showdown.defaults,
     content: {
       toc: false,
@@ -47,6 +48,10 @@ chrome.storage.sync.get((res) => {
     options.marked = md.marked.defaults
     options.showdown = md.showdown.defaults
   }
+  // v2.8 -> v2.9
+  if (!options.remark) {
+    options.remark = md.remark.defaults
+  }
 
   chrome.storage.sync.set(options)
 
@@ -175,6 +180,7 @@ chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
       theme: 'github',
       compiler: 'marked',
       marked: md.marked.defaults,
+      remark: md.remark.defaults,
       showdown: md.showdown.defaults,
       content: {toc: false, scroll: true},
       raw: false

+ 25 - 0
background/remark.js

@@ -0,0 +1,25 @@
+
+md.remark = {
+  defaults: {
+    gfm: true,
+    yaml: true,
+    commonmark: false,
+    footnotes: false,
+    pedantic: false,
+    breaks: false,
+    sanitize: false
+    // blocks (Array.<string>, default: list of block HTML elements)
+  },
+  compile: (markdown, sendResponse) => {
+    chrome.storage.sync.get('remark', (res) => {
+      var html = remark.unified()
+        .use(remark.parse, res.remark)
+        .use(remark.stringify)
+        .use(remarkSlug)
+        .use(remarkHTML, res.remark) // sanitize
+        .processSync(markdown)
+        .contents
+      sendResponse({message: 'html', html})
+    })
+  }
+}

+ 10 - 1
content/popup.js

@@ -78,7 +78,7 @@ var ui = {
     'theme', 'compiler', 'content'
   ],
   compilers: [
-    'showdown', 'marked'
+    'marked', 'remark', 'showdown'
   ],
   description: {
     compiler: {
@@ -91,6 +91,15 @@ var ui = {
         smartLists: 'Use smarter list behavior\nthan the original markdown',
         smartypants: 'Use "smart" typographic punctuation\nfor things like quotes and dashes'
       },
+      remark: {
+        gfm: 'Toggle GFM (GitHub Flavored Markdown)',
+        yaml: 'Enables raw YAML front matter to be detected at the top',
+        commonmark: 'Toggle CommonMark mode',
+        footnotes: 'Toggle reference footnotes and inline footnotes',
+        pedantic: 'Don\'t fix any of the original markdown\nbugs or poor behavior',
+        breaks: 'Exposes newline characters inside paragraphs as breaks',
+        sanitize: 'Toggle HTML tag rendering'
+      },
       showdown: {
         disableForced4SpacesIndentedSublists: "Disables the requirement of indenting nested sublists by 4 spaces",
         encodeEmails: "Encode e-mail addresses through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities",

+ 4 - 0
manifest.json

@@ -18,8 +18,12 @@
   "background" : {
     "scripts": [
       "/vendor/marked.min.js",
+      "/vendor/remark.min.js",
+      "/vendor/remark-html.min.js",
+      "/vendor/remark-slug.min.js",
       "/vendor/showdown.min.js",
       "/background/marked.js",
+      "/background/remark.js",
       "/background/showdown.js",
       "/background/background.js"
     ],

File diff suppressed because it is too large
+ 0 - 0
vendor/remark-html.min.js


File diff suppressed because it is too large
+ 0 - 0
vendor/remark-slug.min.js


File diff suppressed because it is too large
+ 6 - 0
vendor/remark.min.js


Some files were not shown because too many files changed in this diff