front-matter-markdown
Version:
get the config and toc object from the markdown string.
92 lines (69 loc) • 2.36 kB
text/coffeescript
inherits = require('inherits-ex/lib/inherits')
Parser = require('kramed/lib/parser')
InlineLexer = require('./ast-inline-lexer')
Renderer = require('./ast-builder')
module.exports = class AstParser
inherits AstParser, Parser
= (src, options, renderer) ->
parser = new AstParser(options, renderer)
parser.parse src
constructor: (options)->
super
= new Renderer
parse: (src) ->
src.links = {} unless src.links
= new InlineLexer(src.links, , )
= src.reverse()
out = []
while
out = out.concat
out
tok: ->
return '' unless and .hasOwnProperty('type')
switch (.type)
when 'table'
header = []
body = []
cell = []
for i in [0....header.length]
flags = { header: true, align: this.token.align[i] }
cell = cell.concat .tablecell(
.output(.header[i]),
{ header: true, align: this.token.align[i] }
)
header = header.contact .tablerow(cell)
for i in [0....cells.length]
row = .cells[i]
cell = []
for j in [0...row.length]
cell = cell.concat .tablecell(
.output(row[j]),
{ header: false, align: this.token.align[j] }
)
body = body.concat .tablerow(cell)
return .table(header, body)
when 'blockquote_start'
body = []
while .type != 'blockquote_end'
body = body.concat
return .blockquote(body)
when 'list_start'
body = []
ordered = .ordered
while .type != 'list_end'
body = body.concat
return .list(body, ordered)
when 'list_item_start'
body = []
while .type != 'list_item_end'
body = body.concat if .type == 'text'
else
return .listitem(body)
when 'loose_item_start'
body = []
while .type != 'list_item_end'
body = body.concat
return .listitem(body)
return super