Update markdown parsing to allow wiki links

Any link inside a item detail page's markdown description which does
not have a URL will be assumed to be the name of an item covered by
Crafting Guide and an URL will be added to reference the appropiate
browse page.
This commit is contained in:
Andrew Miner
2015-03-24 17:12:25 -07:00
parent 492d6854ac
commit 96ddd1bd4d
5 changed files with 46 additions and 8 deletions
@@ -113,7 +113,7 @@ module.exports = class ItemPageController extends PageController
return _.extend super,
'click a.craftingPlan': 'routeLinkClick'
'click .byline a': 'routeLinkClick'
'click .markdown': 'routeLinkClick'
'click .markdown a': 'routeLinkClick'
'click button': 'craftingPlanButtonClicked'
# Private Methods ##############################################################################
@@ -132,9 +132,9 @@ module.exports = class ItemPageController extends PageController
description = @model.compileDescription()
if description?
@$descriptionPanel.html description
@show @$descriptionPanel
@show @$descriptionSection
else
@hide @$descriptionPanel
@hide @$descriptionSection
_refreshRecipes: ->
@_recipeControllers ?= []
+4 -3
View File
@@ -32,9 +32,10 @@ switch window.location.hostname
global.env = 'production'
logger.level = Logger.INFO
global.router = new CraftingGuideRouter
global.util = require 'util'
global.views = views
global.router = new CraftingGuideRouter
global.util = require 'util'
global.views = views
global.markdown = global.markdown.markdown
global.feedbackController = new FeedbackController el:'.view__feedback'
feedbackController.render()
+28 -2
View File
@@ -8,6 +8,7 @@ All rights reserved.
BaseModel = require './base_model'
CraftingPlan = require './crafting_plan'
{Event} = require '../constants'
{Url} = require '../constants'
########################################################################################################################
@@ -22,8 +23,33 @@ module.exports = class ItemPage extends BaseModel
compileDescription: ->
return null unless @item?.description?
description = _.parseMarkdown @item.description
return description
tree = markdown.parse @item.description, '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]
for child in node[index]
logger.indent()
findLinkRefs child
logger.outdent()
findLinkRefs tree
html = markdown.renderJsonML markdown.toHTMLTree tree
return html
findComponentInItems: ->
return @_findRecipesMatching (recipe)=> recipe.requires @item.slug