Un-nest and organize html helpers

This commit is contained in:
Tom MacWright 2015-07-10 12:09:50 -04:00
parent 9a03c7fb0e
commit 77152ef520

View File

@ -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 '<code>' + autolink(paths, type.name) + '</code>';
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 '<code>[' + formatType(type.expression, paths) + ']</code>';
case 'TypeApplication':
return formatType(type.expression, paths) + '<' +
type.applications.map(function (application) {
return formatType(application, paths);
}).join(', ') + '>';
type.applications.map(recurse).join(', ') + '>';
}
}