mirror of
https://github.com/wassname/side-by-side.git
synced 2026-09-09 11:34:24 +08:00
Initial project setup
Featuring: - middleman setup - dummy controller and index page - markdown reader and its qunit tests - travis integration
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
angular.module("sideBySide").factory("markdownReader", () ->
|
||||
return (source) ->
|
||||
read_meta = (block, inlineLexer) ->
|
||||
meta = {}
|
||||
lexed = inlineLexer.output(block.text)
|
||||
for line in lexed.split("\n")
|
||||
match = /([^:]*):(.*)/.exec(line)
|
||||
meta[match[1].trim()] = match[2].trim()
|
||||
return meta
|
||||
|
||||
read_content = (lexed) ->
|
||||
get_section = (lexed) ->
|
||||
items = []
|
||||
while lexed.length > 0
|
||||
if lexed[0]["type"] == "heading"
|
||||
break
|
||||
items.push(lexed.shift())
|
||||
return items
|
||||
|
||||
content = []
|
||||
|
||||
while lexed.length > 0
|
||||
if lexed[0]["type"] == "heading"
|
||||
heading = lexed.shift().text
|
||||
else
|
||||
heading = ''
|
||||
|
||||
text = get_section(lexed)
|
||||
text.links = lexed.links
|
||||
content.push({
|
||||
section: heading
|
||||
text: marked.parser(text)
|
||||
})
|
||||
|
||||
return content
|
||||
|
||||
lexed = marked.lexer(source)
|
||||
meta = lexed.shift()
|
||||
inlineLexer = new marked.InlineLexer(lexed.links)
|
||||
|
||||
return {
|
||||
meta: read_meta(meta, inlineLexer)
|
||||
content: read_content(lexed)
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user