Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions browser/lib/findNoteTitle.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
const frontMatterRegex = /^\-{3,}/
Copy link
Member

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.

Copy link
Contributor Author

@daiyam daiyam Sep 8, 2018

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 ---.

Copy link
Member

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 --- 😄


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

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

splitted.splice(0, index + 1)
}

splitted.some((line, index) => {
const trimmedLine = line.trim()
const trimmedNextLine = splitted[index + 1] === undefined ? '' : splitted[index + 1].trim()
Expand Down
1 change: 1 addition & 0 deletions browser/lib/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {})
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 😄


const deflate = require('markdown-it-plantuml/lib/deflate')
this.md.use(require('markdown-it-plantuml'), '', {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"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
3 changes: 2 additions & 1 deletion tests/lib/find-title-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ test('findNoteTitle#find should return a correct title (string)', t => {
['hoge\n====\nfuga', 'hoge'],
['====', '===='],
['```\n# hoge\n```', '```'],
['hoge', 'hoge']
['hoge', 'hoge'],
['---\nlayout: test\n---\n # hoge', '# hoge']
]

testCases.forEach(testCase => {
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5735,6 +5735,10 @@ 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