mirror of
https://github.com/wassname/side-by-side.git
synced 2026-09-09 11:34:24 +08:00
Fix markdown metadata reading
Was breaking on trailing whitespace, which is markdown for <br> and something people could commonly put after metadata, as it makes things more readable when processed by regular markdown.
This commit is contained in:
@@ -14,9 +14,9 @@ angular.module("sideBySide").factory("markdownReader", () ->
|
||||
# @return [Object] Meta properties
|
||||
readMeta = (text, inlineLexer) ->
|
||||
meta = {}
|
||||
lexed = inlineLexer.output(text)
|
||||
for line in lexed.split("\n")
|
||||
match = /([^:]*):(.*)/.exec(line)
|
||||
for line in text.split("\n")
|
||||
lexed = inlineLexer.output(line)
|
||||
match = /([^:]*):(.*)/.exec(lexed)
|
||||
meta[match[1].trim()] = match[2].trim()
|
||||
return meta
|
||||
|
||||
@@ -53,10 +53,10 @@ angular.module("sideBySide").factory("markdownReader", () ->
|
||||
|
||||
lexed = marked.lexer(source)
|
||||
meta = lexed.shift()
|
||||
inlineLexer = new marked.InlineLexer(lexed.links)
|
||||
meta = readMeta(meta.text, new marked.InlineLexer(lexed.links))
|
||||
|
||||
return {
|
||||
meta: readMeta(meta.text, inlineLexer)
|
||||
meta: meta
|
||||
content: readContent(lexed)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
test("markdownReader", () ->
|
||||
testCases = [{
|
||||
tested: """
|
||||
Title: Universal Declaration of Human Rights
|
||||
Title: Universal Declaration of Human Rights
|
||||
Author: John Peters Humphrey
|
||||
Date: 1948
|
||||
Source: http://en.wikisource.org/wiki/Universal_Declaration_of_Human_Rights
|
||||
Date: 1948
|
||||
Source: http://en.wikisource.org/wiki/Universal_Declaration_of_Human_Rights
|
||||
|
||||
## 1
|
||||
All human beings are born *free* and equal in dignity and rights...
|
||||
|
||||
Reference in New Issue
Block a user