Skip to content

Commit

Permalink
Merge remote-tracking branch 'tjbaron/htmlfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
jbt committed Feb 15, 2014
2 parents 4a2a925 + d502bea commit 58ffb6d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/docker.js
Expand Up @@ -924,11 +924,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: '-->'
}
};

Expand Down Expand Up @@ -985,7 +987,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
Expand All @@ -994,7 +1002,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);
Expand Down

0 comments on commit 58ffb6d

Please sign in to comment.