diff --git a/background/storage.js b/background/storage.js index 8f5e403..e4c7295 100644 --- a/background/storage.js +++ b/background/storage.js @@ -49,6 +49,7 @@ md.storage.defaults = (compilers) => { content: { autoreload: false, emoji: false, + frontmatter: false, mathjax: false, mermaid: false, syntax: true, diff --git a/content/index.css b/content/index.css index 63b8dd9..2f6d949 100644 --- a/content/index.css +++ b/content/index.css @@ -68,6 +68,13 @@ pre#_markdown, overflow-y: auto; } +.frontmatter pre, +.frontmatter pre code { + white-space: pre-wrap !important; + word-wrap: break-word !important; + overflow-wrap: break-word !important; +} + @media (max-width: 576px) { /*Extra small - none*/ .markdown-theme { width: auto !important; } } diff --git a/content/index.js b/content/index.js index b7cf50e..47cc1b5 100644 --- a/content/index.js +++ b/content/index.js @@ -117,7 +117,7 @@ var render = (md) => { chrome.runtime.sendMessage({ message: 'markdown', compiler: state.compiler, - markdown: frontmatter(state.markdown) + markdown: frontmatter(state.markdown, state.content.frontmatter) }, (res) => { state.html = res.html if (state.content.emoji) { @@ -233,18 +233,29 @@ 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) +var frontmatter = (md, show) => { + var yamlMatch = /^(-{3})([\s\S]+?)(-{3})/.exec(md) + var tomlMatch = /^(\+{3})([\s\S]+?)(\+{3})/.exec(md) + + if (yamlMatch) { + var [full, , content] = yamlMatch + var title = /title: (?:'|")*(.*)(?:'|")*/.exec(content) title && (document.title = title[1]) + if (show) { + return md.replace(full, '