Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

When feeding code into pygments code hilighter all sections are combi…

…ned using a block of characters commented out using the source languages syntax. Languages without a single line comment style (like HTML and CSS) weren't handled properly. This has been fixed.
  • Loading branch information...
commit d502bea1dcd24869167cc5510c022ba02925d4b8 1 parent 1bf0db9
@tjbaron tjbaron authored
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/docker.js
View
16 src/docker.js
@@ -960,11 +960,13 @@ Docker.prototype.languages = {
},
css: {
extensions: [ 'css' ],
- multiLine: [ /\/\*/, /\*\// ],
+ multiLine: [ /\/\*/, /\*\// ], // for when we detect multi-line comments
+ commentStart: '/*', commentEnd: '*/' // for when we add multi-line comments
},
html: {
extensions: [ 'html', 'htm' ],
- multiLine: [ /<!--/, /-->/ ]
+ multiLine: [ /<!--/, /-->/ ],
+ commentStart: '<!--', commentEnd: '-->'
}
};
@@ -1028,7 +1030,13 @@ Docker.prototype.highlight = function(sections, language, cb){
for(var i = 0; i < sections.length; i += 1){
input.push(sections[i].code);
}
- input = input.join('\n' + params.comment + '----DIVIDER----\n');
+ // If the language we are parsing doesn't have single line comments
+ // (like HTML and CSS) we use a multi-line comment.
+ if (params.comment) {
+ input = input.join('\n' + params.comment + '----DIVIDER----\n');
+ } else {
+ input = input.join('\n' + params.commentStart + '----DIVIDER----' + params.commentEnd + '\n');
+ }
if(this.languages[language].pygment) {
pygment = this.languages[language].pygment
@@ -1037,7 +1045,7 @@ Docker.prototype.highlight = function(sections, language, cb){
// Run our input through pygments, then split the output back up into its constituent sections
this.pygments(input, pygment, function(out){
out = out.replace(/^\s*<div class="highlight"><pre>/,'').replace(/<\/pre><\/div>\s*$/,'');
- var bits = out.split(/^<span[^>]*>[^<]+(?:<\/span><span[^>]*>)?----DIVIDER----<\/span>$/gm);
+ var bits = out.split(/^<span[^>]*>[^<]+(?:<\/span><span[^>]*>)?----DIVIDER----[^<]*<\/span>$/gm);
for(var i = 0; i < sections.length; i += 1){
sections[i].codeHtml = '<div class="highlight"><pre>' + bits[i] + '</pre></div>';
sections[i].docHtml = showdown.makeHtml(sections[i].docs);
Please sign in to comment.
Something went wrong with that request. Please try again.