Update markdown processing to handle more cases

This commit is contained in:
Andrew Miner
2015-03-24 19:05:13 -07:00
parent 4a45be71f9
commit d964047974
3 changed files with 50 additions and 4 deletions
@@ -6,17 +6,20 @@ All rights reserved.
### ###
BaseController = require './base_controller' BaseController = require './base_controller'
{Url} = require '../constants'
######################################################################################################################## ########################################################################################################################
module.exports = class MarkdownSectionController extends BaseController module.exports = class MarkdownSectionController extends BaseController
constructor: (options={})-> constructor: (options={})->
if not options.modPack? then throw new Error 'options.modPack is required'
options.model ?= '' options.model ?= ''
options.title ?= 'Description' options.title ?= 'Description'
options.templateName = 'markdown_section' options.templateName = 'markdown_section'
super options super options
@modPack = options.modPack
@title = options.title @title = options.title
# BaseController Overrides ##################################################################### # BaseController Overrides #####################################################################
@@ -30,11 +33,42 @@ module.exports = class MarkdownSectionController extends BaseController
@$title.html @title @$title.html @title
@$markdownPanel.empty() @$markdownPanel.empty()
@$markdownPanel.html _.parseMarkdown @model @$markdownPanel.html @_parseMarkdown()
super super
# Backbone.View Overrides ###################################################################### # Backbone.View Overrides ######################################################################
events: -> events: ->
return _.extend super, return _.extend super,
'click .markdown': 'routeLinkClick' 'click .markdown a': 'routeLinkClick'
# Private Methods ##############################################################################
_parseMarkdown: ->
return '' unless @model
tree = markdown.parse @model, 'Maruku'
refs = tree[1].references
findLinkRefs = (node)=>
logger.debug "inspecting a #{node[0]}"
if node[0] is 'link_ref'
name = node[2]
logger.debug "found a link_ref for #{name}"
item = @modPack.findItemByName node[2]
if item?
logger.debug "found related item: #{item}"
node[0] = 'link'
node[1].href = Url.item itemSlug:item.slug.item, modSlug:item.slug.mod
delete node[1].ref
else
for index in [1...node.length]
if _.isArray node[index]
logger.indent()
findLinkRefs node[index]
logger.outdent()
findLinkRefs tree
html = markdown.renderJsonML markdown.toHTMLTree tree
return html
@@ -89,7 +89,7 @@ module.exports = class TutorialPageController extends BaseController
for section in @model.sections for section in @model.sections
controller = @_sectionControllers[index] controller = @_sectionControllers[index]
if not controller? if not controller?
controller = new MarkdownSectionController title:section.title, model:section.content controller = new MarkdownSectionController title:section.title, model:section.content, modPack:@modPack
@_sectionControllers.push controller @_sectionControllers.push controller
@$sectionsContainer.append controller.$el @$sectionsContainer.append controller.$el
controller.render() controller.render()
+12
View File
@@ -42,11 +42,23 @@ All rights reserved.
td { td {
font-family: $font-family-normal; font-family: $font-family-normal;
font-size: $font-size-normal; font-size: $font-size-normal;
padding: 0.1em 0.5em;
vertical-align: middle;
}
th {
font-family: $font-family-normal;
font-size: $font-size-normal;
font-weight: bold;
vertical-align: middle;
} }
td[align="center"] { td[align="center"] {
text-align: center; text-align: center;
} }
td[align="right"] {
text-align: right;
}
} }
ol { ol {