From 77152ef520a2a4b2f25cf20940102cf7fd8efaae Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Fri, 10 Jul 2015 12:09:50 -0400 Subject: [PATCH] Un-nest and organize html helpers --- streams/output/lib/html_helpers.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/streams/output/lib/html_helpers.js b/streams/output/lib/html_helpers.js index f084292..63ac03a 100644 --- a/streams/output/lib/html_helpers.js +++ b/streams/output/lib/html_helpers.js @@ -18,6 +18,17 @@ function slug(p) { return p ? slugg(p) : ''; } +/** + * Format a description and target as a Markdown link. + * + * @param {string} description the text seen as the link + * @param {string} href where the link goes + * @return {string} markdown formatted link + */ +function markdownLink(description, href) { + return '[`' + description + '`](' + href + ')'; +} + /** * Format link & tutorial tags with simple code inline tags. * @@ -31,10 +42,6 @@ function formatInlineTags(text) { var output = ''; var tokens = inlineLex(text); - function markdownLink(description, href) { - return '[`' + description + '`](' + href + ')'; - } - for (var i = 0; i < tokens.length; i++) { if (tokens[i].type === 'text') { output += tokens[i].capture[0]; @@ -81,22 +88,21 @@ function autolink(paths, text) { * // generates String */ function formatType(type, paths) { + function recurse(element) { + return formatType(element, paths); + } switch (type.type) { case 'NameExpression': return '' + autolink(paths, type.name) + ''; case 'UnionType': - return type.elements.map(function (element) { - return formatType(element, paths); - }).join(' or '); + return type.elements.map(recurse).join(' or '); case 'AllLiteral': return 'Any'; case 'OptionalType': return '[' + formatType(type.expression, paths) + ']'; case 'TypeApplication': return formatType(type.expression, paths) + '<' + - type.applications.map(function (application) { - return formatType(application, paths); - }).join(', ') + '>'; + type.applications.map(recurse).join(', ') + '>'; } }