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:
@@ -113,7 +113,7 @@ module.exports = class ItemPageController extends PageController
|
|||||||
return _.extend super,
|
return _.extend super,
|
||||||
'click a.craftingPlan': 'routeLinkClick'
|
'click a.craftingPlan': 'routeLinkClick'
|
||||||
'click .byline a': 'routeLinkClick'
|
'click .byline a': 'routeLinkClick'
|
||||||
'click .markdown': 'routeLinkClick'
|
'click .markdown a': 'routeLinkClick'
|
||||||
'click button': 'craftingPlanButtonClicked'
|
'click button': 'craftingPlanButtonClicked'
|
||||||
|
|
||||||
# Private Methods ##############################################################################
|
# Private Methods ##############################################################################
|
||||||
@@ -132,9 +132,9 @@ module.exports = class ItemPageController extends PageController
|
|||||||
description = @model.compileDescription()
|
description = @model.compileDescription()
|
||||||
if description?
|
if description?
|
||||||
@$descriptionPanel.html description
|
@$descriptionPanel.html description
|
||||||
@show @$descriptionPanel
|
@show @$descriptionSection
|
||||||
else
|
else
|
||||||
@hide @$descriptionPanel
|
@hide @$descriptionSection
|
||||||
|
|
||||||
_refreshRecipes: ->
|
_refreshRecipes: ->
|
||||||
@_recipeControllers ?= []
|
@_recipeControllers ?= []
|
||||||
|
|||||||
@@ -32,9 +32,10 @@ switch window.location.hostname
|
|||||||
global.env = 'production'
|
global.env = 'production'
|
||||||
logger.level = Logger.INFO
|
logger.level = Logger.INFO
|
||||||
|
|
||||||
global.router = new CraftingGuideRouter
|
global.router = new CraftingGuideRouter
|
||||||
global.util = require 'util'
|
global.util = require 'util'
|
||||||
global.views = views
|
global.views = views
|
||||||
|
global.markdown = global.markdown.markdown
|
||||||
|
|
||||||
global.feedbackController = new FeedbackController el:'.view__feedback'
|
global.feedbackController = new FeedbackController el:'.view__feedback'
|
||||||
feedbackController.render()
|
feedbackController.render()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ All rights reserved.
|
|||||||
BaseModel = require './base_model'
|
BaseModel = require './base_model'
|
||||||
CraftingPlan = require './crafting_plan'
|
CraftingPlan = require './crafting_plan'
|
||||||
{Event} = require '../constants'
|
{Event} = require '../constants'
|
||||||
|
{Url} = require '../constants'
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
@@ -22,8 +23,33 @@ module.exports = class ItemPage extends BaseModel
|
|||||||
|
|
||||||
compileDescription: ->
|
compileDescription: ->
|
||||||
return null unless @item?.description?
|
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: ->
|
findComponentInItems: ->
|
||||||
return @_findRecipesMatching (recipe)=> recipe.requires @item.slug
|
return @_findRecipesMatching (recipe)=> recipe.requires @item.slug
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ $color-error-new: #CD0000;
|
|||||||
$color-footer: #3D1D09;
|
$color-footer: #3D1D09;
|
||||||
$color-footer-text: #FFFFFF;
|
$color-footer-text: #FFFFFF;
|
||||||
$color-link: #0000FF;
|
$color-link: #0000FF;
|
||||||
|
$color-link-subtle: #545A99;
|
||||||
$color-text: #000000;
|
$color-text: #000000;
|
||||||
|
|
||||||
// Z-Index Layers //////////////////////////////////////////////////////////////////////////////////
|
// Z-Index Layers //////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -7,6 +7,16 @@ All rights reserved.
|
|||||||
|
|
||||||
.markdown {
|
.markdown {
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: $color-link-subtle;
|
||||||
|
text-decoration: none;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: $color-link;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-family: $font-family-normal;
|
font-family: $font-family-normal;
|
||||||
font-size: $font-size-large;
|
font-size: $font-size-large;
|
||||||
|
|||||||
Reference in New Issue
Block a user