Skip to content

Commit

Permalink
don't pretty-print code blocks that begin with "```plain" (jsdoc#1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
hegemonic committed Jul 23, 2017
1 parent f27bf19 commit a63337b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
17 changes: 14 additions & 3 deletions lib/jsdoc/util/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,21 @@ function escapeCode(source) {
* @return {string} The wrapped code snippet.
*/
function highlight(code, language) {
var langClass = language ? ' lang-' + language : '';
var classString;
var langClass = '';

return util.format('<pre class="prettyprint source%s"><code>%s</code></pre>', langClass,
escapeCode(code));
if (language && (language !== 'plain')) {
langClass = ' lang-' + language;
}

if (language !== 'plain') {
classString = util.format(' class="prettyprint source%s"', langClass);
}
else {
classString = ' class="source"';
}

return util.format('<pre%s><code>%s</code></pre>', classString, escapeCode(code));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions templates/default/static/styles/jsdoc-default.css
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ tr > th:last-child { border-right: 1px solid #ddd; }
margin: 0;
}

.prettyprint
.source
{
border: 1px solid #ddd;
width: 80%;
Expand All @@ -284,7 +284,7 @@ tr > th:last-child { border-right: 1px solid #ddd; }
width: inherit;
}

.prettyprint code
.source code
{
font-size: 100%;
line-height: 18px;
Expand Down
9 changes: 9 additions & 0 deletions test/specs/jsdoc/util/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,14 @@ describe('jsdoc/util/markdown', function() {

expect(parser('# Hello')).toBe('<h1 id="hello">Hello</h1>');
});

it('should not pretty-print code blocks that start with "```plain"', function() {
var parser = markdown.getParser();
var markdownText = '```plain\nconsole.log("foo");\n```';
var convertedText = '<pre class="source"><code>console.log(&quot;foo&quot;);\n' +
'</code></pre>';

expect(parser(markdownText)).toBe(convertedText);
});
});
});

0 comments on commit a63337b

Please sign in to comment.