Skip to content

Commit

Permalink
front-matter must be delimited by ---
Browse files Browse the repository at this point in the history
  • Loading branch information
daiyam committed Sep 8, 2018
1 parent bfd4d7f commit 90f791d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
6 changes: 2 additions & 4 deletions browser/lib/findNoteTitle.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const frontMatterRegex = /^\-{3,}/

export function findNoteTitle (value) {
const splitted = value.split('\n')
let title = null
let isInsideCodeBlock = false

if (frontMatterRegex.exec(splitted[0])) {
if (splitted[0] === '---') {
let index = 0
while (++index < splitted.length && !frontMatterRegex.exec(splitted[index])) {
while (++index < splitted.length && splitted[index] !== '---') {
}

splitted.splice(0, index + 1)
Expand Down
21 changes: 21 additions & 0 deletions browser/lib/markdown-it-frontmatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

module.exports = function frontMatterPlugin (md) {
function frontmatter (state, startLine, endLine, silent) {
if (startLine !== 0 || state.src.substr(startLine, state.eMarks[0]) !== '---') {
return false
}

let line = 0
while (++line < state.lineMax && state.src.substring(state.bMarks[line], state.eMarks[line]) !== '---') {
}

state.line = line + 1

return true
}

md.block.ruler.before('table', 'frontmatter', frontmatter, {
alt: [ 'paragraph', 'reference', 'blockquote', 'list' ]
})
}
2 changes: 1 addition & 1 deletion browser/lib/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Markdown {
})
this.md.use(require('markdown-it-kbd'))
this.md.use(require('markdown-it-admonition'))
this.md.use(require('markdown-it-front-matter'), fm => {})
this.md.use(require('./markdown-it-frontmatter'))

const deflate = require('markdown-it-plantuml/lib/deflate')
this.md.use(require('markdown-it-plantuml'), '', {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"markdown-it-admonition": "^1.0.4",
"markdown-it-emoji": "^1.1.1",
"markdown-it-footnote": "^3.0.0",
"markdown-it-front-matter": "^0.1.2",
"markdown-it-imsize": "^2.0.1",
"markdown-it-kbd": "^1.1.1",
"markdown-it-multimd-table": "^2.0.1",
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5735,10 +5735,6 @@ markdown-it-footnote@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/markdown-it-footnote/-/markdown-it-footnote-3.0.1.tgz#7f3730747cacc86e2fe0bf8a17a710f34791517a"

markdown-it-front-matter@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/markdown-it-front-matter/-/markdown-it-front-matter-0.1.2.tgz#e50bf56e77e6a4f5ac4ffa894d4d45ccd9896b20"

markdown-it-imsize@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/markdown-it-imsize/-/markdown-it-imsize-2.0.1.tgz#cca0427905d05338a247cb9ca9d968c5cddd5170"
Expand Down

0 comments on commit 90f791d

Please sign in to comment.