From d9640479740a56dcaab2896592cf149fcdff2eaf Mon Sep 17 00:00:00 2001 From: Andrew Miner Date: Tue, 24 Mar 2015 19:05:13 -0700 Subject: [PATCH] Update markdown processing to handle more cases --- .../markdown_section_controller.coffee | 40 +++++++++++++++++-- .../tutorial_page_controller.coffee | 2 +- src/scss/markdown.scss | 12 ++++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/coffee/controllers/markdown_section_controller.coffee b/src/coffee/controllers/markdown_section_controller.coffee index 52c3139d6..ffb2c9f1f 100644 --- a/src/coffee/controllers/markdown_section_controller.coffee +++ b/src/coffee/controllers/markdown_section_controller.coffee @@ -6,18 +6,21 @@ All rights reserved. ### BaseController = require './base_controller' +{Url} = require '../constants' ######################################################################################################################## module.exports = class MarkdownSectionController extends BaseController constructor: (options={})-> + if not options.modPack? then throw new Error 'options.modPack is required' options.model ?= '' options.title ?= 'Description' options.templateName = 'markdown_section' super options - @title = options.title + @modPack = options.modPack + @title = options.title # BaseController Overrides ##################################################################### @@ -30,11 +33,42 @@ module.exports = class MarkdownSectionController extends BaseController @$title.html @title @$markdownPanel.empty() - @$markdownPanel.html _.parseMarkdown @model + @$markdownPanel.html @_parseMarkdown() super # Backbone.View Overrides ###################################################################### events: -> 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 diff --git a/src/coffee/controllers/tutorial_page_controller.coffee b/src/coffee/controllers/tutorial_page_controller.coffee index bad0687b5..4fa64fd23 100644 --- a/src/coffee/controllers/tutorial_page_controller.coffee +++ b/src/coffee/controllers/tutorial_page_controller.coffee @@ -89,7 +89,7 @@ module.exports = class TutorialPageController extends BaseController for section in @model.sections controller = @_sectionControllers[index] 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 @$sectionsContainer.append controller.$el controller.render() diff --git a/src/scss/markdown.scss b/src/scss/markdown.scss index 555b792d5..3c51200e3 100644 --- a/src/scss/markdown.scss +++ b/src/scss/markdown.scss @@ -42,11 +42,23 @@ All rights reserved. td { font-family: $font-family-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"] { text-align: center; } + td[align="right"] { + text-align: right; + } } ol {