@@ -7,6 +7,18 @@ var striptags = require('striptags');
77var DocMapInfo = require ( "../doc-map-info" ) ;
88var unescapeHTML = require ( "unescape-html" ) ;
99
10+
11+ function escapeOnlySingleElements ( text ) {
12+ //This could be an alternate way of detecting if markdown escaped
13+ //var html = stmd_to_html("<p>"+text+"</p>\n");
14+ //if(html === "<p>"+text+"</p>\n") { }
15+ if ( / ^ < \w + \/ ? > $ / . test ( text ) ) {
16+ return escape ( text ) ;
17+ } else {
18+ return text ;
19+ }
20+ }
21+
1022// Helper helpers
1123
1224var sortChildren = function ( child1 , child2 ) {
@@ -200,11 +212,11 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
200212 * @body
201213 *
202214 * ## Use
203- *
215+ *
204216 * ```
205217 * {{{generatedWarning}}}
206218 * ```
207- *
219+ *
208220 * MUST use triple-braces to escape HTML so it is hidden in a comment.
209221 *
210222 * Creates a warning that looks like this:
@@ -230,7 +242,7 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
230242 } ,
231243 /**
232244 * @function bit-docs-generate-html/build/make_default_helpers.makeTitle makeTitle
233- *
245+ *
234246 * Given the [bit-docs/types/docObject] context, returns a "pretty"
235247 * name that is used in the sidebar and the page header.
236248 */
@@ -288,13 +300,15 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
288300 //if there is anything in the hashParts, append it to the end of the url
289301 href = urlTo ( name ) + ( hashParts . length >= 1 ? ( "#" + hashParts . join ( "#" ) ) : "" ) ;
290302
291- return '<a href="' + href + '" title="' + stripMarkdown ( description ) + '">' + linkText + '</a>' ;
303+
304+
305+ return '<a href="' + href + '" title="' + stripMarkdown ( description ) + '">' + escapeOnlySingleElements ( linkText ) + '</a>' ;
292306 }
293307
294308 if ( httpRegExp . test ( name ) ) {
295309 linkText = parts && parts [ 2 ] ? parts [ 2 ] : name ;
296310 href = name ;
297- return '<a href="' + href + '" title="' + escape ( linkText ) + '">' + linkText + '</a>' ;
311+ return '<a href="' + href + '" title="' + escape ( linkText ) + '">' + escapeOnlySingleElements ( linkText ) + '</a>' ;
298312 }
299313
300314 return match ;
0 commit comments