mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
front-matter must be delimited by ---
This commit is contained in:
@@ -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)
|
||||
|
||||
21
browser/lib/markdown-it-frontmatter.js
Normal file
21
browser/lib/markdown-it-frontmatter.js
Normal file
@@ -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' ]
|
||||
})
|
||||
}
|
||||
@@ -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'), '', {
|
||||
|
||||
Reference in New Issue
Block a user