mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-16 19:21:52 +00:00
Merge pull request #2347 from daiyam/front-matter
add support to front-matter
This commit is contained in:
@@ -3,6 +3,17 @@ export function findNoteTitle (value) {
|
|||||||
let title = null
|
let title = null
|
||||||
let isInsideCodeBlock = false
|
let isInsideCodeBlock = false
|
||||||
|
|
||||||
|
if (splitted[0] === '---') {
|
||||||
|
let line = 0
|
||||||
|
while (++line < splitted.length) {
|
||||||
|
if (splitted[line] === '---') {
|
||||||
|
splitted.splice(0, line + 1)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
splitted.some((line, index) => {
|
splitted.some((line, index) => {
|
||||||
const trimmedLine = line.trim()
|
const trimmedLine = line.trim()
|
||||||
const trimmedNextLine = splitted[index + 1] === undefined ? '' : splitted[index + 1].trim()
|
const trimmedNextLine = splitted[index + 1] === undefined ? '' : splitted[index + 1].trim()
|
||||||
|
|||||||
24
browser/lib/markdown-it-frontmatter.js
Normal file
24
browser/lib/markdown-it-frontmatter.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
'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) {
|
||||||
|
if (state.src.substring(state.bMarks[line], state.eMarks[line]) === '---') {
|
||||||
|
state.line = line + 1
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
md.block.ruler.before('table', 'frontmatter', frontmatter, {
|
||||||
|
alt: [ 'paragraph', 'reference', 'blockquote', 'list' ]
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -149,6 +149,7 @@ class Markdown {
|
|||||||
})
|
})
|
||||||
this.md.use(require('markdown-it-kbd'))
|
this.md.use(require('markdown-it-kbd'))
|
||||||
this.md.use(require('markdown-it-admonition'))
|
this.md.use(require('markdown-it-admonition'))
|
||||||
|
this.md.use(require('./markdown-it-frontmatter'))
|
||||||
|
|
||||||
const deflate = require('markdown-it-plantuml/lib/deflate')
|
const deflate = require('markdown-it-plantuml/lib/deflate')
|
||||||
this.md.use(require('markdown-it-plantuml'), '', {
|
this.md.use(require('markdown-it-plantuml'), '', {
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ test('findNoteTitle#find should return a correct title (string)', t => {
|
|||||||
['hoge\n====\nfuga', 'hoge'],
|
['hoge\n====\nfuga', 'hoge'],
|
||||||
['====', '===='],
|
['====', '===='],
|
||||||
['```\n# hoge\n```', '```'],
|
['```\n# hoge\n```', '```'],
|
||||||
['hoge', 'hoge']
|
['hoge', 'hoge'],
|
||||||
|
['---\nlayout: test\n---\n # hoge', '# hoge']
|
||||||
]
|
]
|
||||||
|
|
||||||
testCases.forEach(testCase => {
|
testCases.forEach(testCase => {
|
||||||
|
|||||||
Reference in New Issue
Block a user