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:
Vit Brunner
2013-06-17 23:02:22 +01:00
parent a78bdb9c4a
commit 46b3033e2a
2 changed files with 8 additions and 8 deletions
@@ -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...