Skip to content

Commit 911d9f8

Browse files
committed
escapes single element content
1 parent 2344173 commit 911d9f8

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

build/build_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe("documentjs/lib/generators/html/build", function(){
182182
var renderer = results[0];
183183
var result = renderer(docObject);
184184

185-
assert.equal(result, "<html><p>This is <a href=\"something.html\" title=\"something\"><something/></a></p>\n\n</html>");
185+
assert.equal(result, "<html><p>This is <a href=\"something.html\" title=\"something\">&lt;something/&gt;</a></p>\n\n</html>");
186186
});
187187
});
188188
});

build/make_default_helpers.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ var striptags = require('striptags');
77
var DocMapInfo = require("../doc-map-info");
88
var 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

1224
var 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;

build/make_default_helpers_test.js

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"homepage": "https://github.com/bit-docs/bit-docs-generate-html#readme",
2828
"dependencies": {
29+
"can-string": "0.0.5",
2930
"enpeem": "^2.1.0",
3031
"escape-html": "^1.0.3",
3132
"fs-extra": "0.30.0",

0 commit comments

Comments
 (0)