Explorar o código

Strip yaml/toml frontmatter and set the page title

simov %!s(int64=2) %!d(string=hai) anos
pai
achega
826fb9ad2e
Modificáronse 5 ficheiros con 15 adicións e 6 borrados
  1. 0 1
      background/compilers/remark.js
  2. 0 1
      build/README.md
  3. 0 1
      build/remark/package.json
  4. 0 2
      build/remark/remark.mjs
  5. 15 1
      content/index.js

+ 0 - 1
background/compilers/remark.js

@@ -22,7 +22,6 @@ md.compilers.remark = (() => {
         .use(state.remark.breaks ? remark.breaks : undefined)
         .use(remark.stringify)
         .use(remark.slug)
-        .use(remark.frontmatter, ['yaml', 'toml'])
         .use(remark.html, state.remark) // sanitize
         .processSync(markdown)
         .value

+ 0 - 1
build/README.md

@@ -40,7 +40,6 @@ sh build/package.sh
 | remark              | ^14.0.2
 | remark-breaks       | ^3.0.2
 | remark-footnotes    | ^4.0.1
-| remark-frontmatter  | ^4.0.1
 | remark-gfm          | ^3.0.1
 | remark-html         | ^15.0.1
 | remark-slug         | ^7.0.1

+ 0 - 1
build/remark/package.json

@@ -6,7 +6,6 @@
   "dependencies": {
     "remark": "^14.0.2",
     "remark-breaks": "^3.0.2",
-    "remark-frontmatter": "^4.0.1",
     "remark-gfm": "^3.0.1",
     "remark-html": "^15.0.1",
     "remark-slug": "^7.0.1"

+ 0 - 2
build/remark/remark.mjs

@@ -6,7 +6,6 @@ import gfm from 'remark-gfm'
 import breaks from 'remark-breaks'
 import html from 'remark-html'
 import slug from 'remark-slug'
-import frontmatter from 'remark-frontmatter'
 
 
 export {
@@ -17,5 +16,4 @@ export {
   breaks,
   html,
   slug,
-  frontmatter,
 }

+ 15 - 1
content/index.js

@@ -113,7 +113,7 @@ var update = () => {
 }
 
 var render = (md) => {
-  state.markdown = md
+  state.markdown = frontmatter(md)
   chrome.runtime.sendMessage({
     message: 'markdown',
     compiler: state.compiler,
@@ -218,6 +218,20 @@ var toc = (() => {
   }
 })()
 
+var frontmatter = (md) => {
+  if (/^-{3}[\s\S]+?-{3}/.test(md)) {
+    var [, yaml] = /^-{3}([\s\S]+?)-{3}/.exec(md)
+    var title = /title: (?:'|")*(.*)(?:'|")*/.exec(yaml)
+    title && (document.title = title[1])
+  }
+  else if (/^\+{3}[\s\S]+?\+{3}/.test(md)) {
+    var [, toml] = /^\+{3}([\s\S]+?)\+{3}/.exec(md)
+    var title = /title = (?:'|"|`)*(.*)(?:'|"|`)*/.exec(toml)
+    title && (document.title = title[1])
+  }
+  return md.replace(/^(?:-|\+){3}[\s\S]+?(?:-|\+){3}/, '')
+}
+
 var favicon = () => {
   var favicon = document.createElement('link')
   favicon.rel = 'icon'