-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support to front-matter #2347
Conversation
- skip front-matter when looking for note's title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test case into /tests/lib/fint-title-test.js
like below:
const testCases = [
['---\nlayout: test\n---\n # hoge', '# hoge']
]
@sosukesuzuki I've added the test. |
@daiyam
|
@sosukesuzuki It's because you have an empty line before it.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check my request
browser/lib/markdown.js
Outdated
@@ -149,6 +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 => {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need an empty callback? Please remove it if you accidentally put it there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No accident, the plugin needs it or it won't work... It used so we can parse the front-matter to extract the properties. But since we don't need to do that, the code block is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that's annoying 😄 maybe because the plugin did check if the callback function is provided or not and assume that's there 😄
browser/lib/findNoteTitle.js
Outdated
@@ -1,8 +1,18 @@ | |||
const frontMatterRegex = /^\-{3,}/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The front matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed lines.
This regex will also valid for line that started with 4 dashes. You should remove the ,
there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right.
I've checked markdown-it-front-matter
and at first there is Indicated by three or more dashes: ---
It was what I tough but I've check some libraries and all of them use a must be ---
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should stick to the traditional ---
😄
I also think if a front matter is invalid then the markdown should display it out. However, with the current behavior, if I type the code bellow, all the content of the note will be hidden.
|
@ZeroX-DG I've replaced the plugin with my own plugin so that delimiter must be 3 dashes. |
} | ||
|
||
let line = 0 | ||
while (++line < state.lineMax && state.src.substring(state.bMarks[line], state.eMarks[line]) !== '---') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we should display the markdown if the front-matter syntax is invalid. For example:
---
layout: default
-----
sdasdasdasdasd
Should display:
With the current behavior (hide all content) the user will get confuse.
Here is my suggestion for the plugin:
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
let isFrontMatterClosed = false
while (line < state.lineMax) {
line++
if (state.src.substring(state.bMarks[line], state.eMarks[line]) === '---') {
isFrontMatterClosed = true
break
}
}
state.line = line + 1
return isFrontMatterClosed
}
md.block.ruler.before('table', 'frontmatter', frontmatter, {
alt: [ 'paragraph', 'reference', 'blockquote', 'list' ]
})
}
The the modification above, the front-matter will be displayed out if it's invalid and will be hide only when it's valid.
@ZeroX-DG yes, it's better to display the invalid front-matter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This change adds support of YAML front-matter by: