Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions background/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ md.storage.defaults = (compilers) => {
content: {
autoreload: false,
emoji: false,
frontmatter: false,
mathjax: false,
mermaid: false,
syntax: true,
Expand Down
7 changes: 7 additions & 0 deletions content/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand Down
29 changes: 20 additions & 9 deletions content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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, '<div class="frontmatter">\n\n```yaml\n' + content.trim() + '\n```\n\n</div>\n\n')
}
return md.replace(full, '')
}
else if (/^\+{3}[\s\S]+?\+{3}/.test(md)) {
var [, toml] = /^\+{3}([\s\S]+?)\+{3}/.exec(md)
var title = /title = (?:'|"|`)*(.*)(?:'|"|`)*/.exec(toml)
else if (tomlMatch) {
var [full, , content] = tomlMatch
var title = /title = (?:'|"|`)*(.*)(?:'|"|`)*/.exec(content)
title && (document.title = title[1])
if (show) {
return md.replace(full, '<div class="frontmatter">\n\n```toml\n' + content.trim() + '\n```\n\n</div>\n\n')
}
return md.replace(full, '')
}
return md.replace(/^(?:-|\+){3}[\s\S]+?(?:-|\+){3}/, '')
return md
}

var favicon = () => {
Expand Down
1 change: 1 addition & 0 deletions popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var Popup = () => {
content: {
autoreload: 'Auto reload on file change',
emoji: 'Convert emoji :shortnames: into EmojiOne images',
frontmatter: 'Display yaml/toml frontmatter',
toc: 'Generate Table of Contents',
mathjax: 'Render MathJax formulas',
mermaid: 'Mermaid diagrams',
Expand Down