Browse Source

Demo: mpre highlight langs + auto mode + debug info

pull/186/head
Vitaly Puzrin 9 years ago
parent
commit
ddb75866b9
  1. 7
      package.json
  2. 2
      support/demo_template/index.jade
  3. 84
      support/demo_template/index.js

7
package.json

@ -13,7 +13,9 @@
"repository": "markdown-it/markdown-it", "repository": "markdown-it/markdown-it",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "index.js",
"bin": { "markdown-it": "bin/markdown-it.js" }, "bin": {
"markdown-it": "bin/markdown-it.js"
},
"scripts": { "scripts": {
"test": "make test" "test": "make test"
}, },
@ -41,6 +43,7 @@
"coveralls": "~2.11.6", "coveralls": "~2.11.6",
"eslint": "0.24.0", "eslint": "0.24.0",
"eslint-plugin-nodeca": "^1.0.0", "eslint-plugin-nodeca": "^1.0.0",
"highlight.js": "^9.1.0",
"istanbul": "*", "istanbul": "*",
"jade": "~1.11.0", "jade": "~1.11.0",
"markdown-it-abbr": "^1.0.2", "markdown-it-abbr": "^1.0.2",
@ -55,8 +58,8 @@
"markdown-it-sup": "^1.0.0", "markdown-it-sup": "^1.0.0",
"markdown-it-testgen": "~0.1.3", "markdown-it-testgen": "~0.1.3",
"marked": "0.3.5", "marked": "0.3.5",
"stylus": "~0.53.0",
"mocha": "*", "mocha": "*",
"stylus": "~0.53.0",
"uglify-js": "*" "uglify-js": "*"
} }
} }

2
support/demo_template/index.jade

@ -14,8 +14,6 @@ html
script(src='https://cdn.jsdelivr.net/bootstrap/3.2.0/js/bootstrap.min.js') script(src='https://cdn.jsdelivr.net/bootstrap/3.2.0/js/bootstrap.min.js')
link(rel='stylesheet' href='https://cdn.jsdelivr.net/bootstrap/3.2.0/css/bootstrap.css') link(rel='stylesheet' href='https://cdn.jsdelivr.net/bootstrap/3.2.0/css/bootstrap.css')
script(src='https://cdn.jsdelivr.net/highlight.js/9.1.0/highlight.min.js')
script(src='https://cdn.jsdelivr.net/highlight.js/9.1.0/languages/stylus.min.js')
link(rel='stylesheet' href='https://cdn.jsdelivr.net/highlight.js/9.1.0/styles/github.min.css') link(rel='stylesheet' href='https://cdn.jsdelivr.net/highlight.js/9.1.0/styles/github.min.css')
script(src='markdown-it.js') script(src='markdown-it.js')

84
support/demo_template/index.js

@ -5,6 +5,63 @@
var mdurl = require('mdurl'); var mdurl = require('mdurl');
var hljs = require('highlight.js/lib/highlight.js');
hljs.registerLanguage('actionscript', require('highlight.js/lib/languages/actionscript'));
hljs.registerLanguage('apache', require('highlight.js/lib/languages/apache'));
hljs.registerLanguage('arduino', require('highlight.js/lib/languages/arduino'));
hljs.registerLanguage('armasm', require('highlight.js/lib/languages/armasm'));
hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'));
hljs.registerLanguage('asciidoc', require('highlight.js/lib//languages/asciidoc'));
hljs.registerLanguage('avrasm', require('highlight.js/lib/languages/avrasm'));
hljs.registerLanguage('bash', require('highlight.js/lib/languages/bash'));
hljs.registerLanguage('clojure', require('highlight.js/lib/languages/clojure'));
hljs.registerLanguage('cmake', require('highlight.js/lib/languages/cmake'));
hljs.registerLanguage('coffeescript', require('highlight.js/lib/languages/coffeescript'));
hljs.registerLanguage('cpp', require('highlight.js/lib/languages/cpp'));
hljs.registerLanguage('css', require('highlight.js/lib/languages/css'));
hljs.registerLanguage('diff', require('highlight.js/lib/languages/diff'));
hljs.registerLanguage('django', require('highlight.js/lib/languages/django'));
hljs.registerLanguage('dockerfile', require('highlight.js/lib/languages/dockerfile'));
hljs.registerLanguage('ruby', require('highlight.js/lib/languages/ruby'));
hljs.registerLanguage('fortran', require('highlight.js/lib/languages/fortran'));
hljs.registerLanguage('glsl', require('highlight.js/lib/languages/glsl'));
hljs.registerLanguage('go', require('highlight.js/lib/languages/go'));
hljs.registerLanguage('groovy', require('highlight.js/lib/languages/groovy'));
hljs.registerLanguage('handlebars', require('highlight.js/lib/languages/handlebars'));
hljs.registerLanguage('haskell', require('highlight.js/lib/languages/haskell'));
hljs.registerLanguage('ini', require('highlight.js/lib/languages/ini'));
hljs.registerLanguage('java', require('highlight.js/lib/languages/java'));
hljs.registerLanguage('javascript', require('highlight.js/lib/languages/javascript'));
hljs.registerLanguage('json', require('highlight.js/lib/languages/json'));
hljs.registerLanguage('less', require('highlight.js/lib/languages/less'));
hljs.registerLanguage('lisp', require('highlight.js/lib/languages/lisp'));
hljs.registerLanguage('livescript', require('highlight.js/lib/languages/livescript'));
hljs.registerLanguage('lua', require('highlight.js/lib/languages/lua'));
hljs.registerLanguage('makefile', require('highlight.js/lib/languages/makefile'));
hljs.registerLanguage('matlab', require('highlight.js/lib/languages/matlab'));
hljs.registerLanguage('mipsasm', require('highlight.js/lib/languages/mipsasm'));
hljs.registerLanguage('perl', require('highlight.js/lib/languages/perl'));
hljs.registerLanguage('nginx', require('highlight.js/lib/languages/nginx'));
hljs.registerLanguage('objectivec', require('highlight.js/lib/languages/objectivec'));
hljs.registerLanguage('php', require('highlight.js/lib/languages/php'));
hljs.registerLanguage('python', require('highlight.js/lib/languages/python'));
hljs.registerLanguage('rust', require('highlight.js/lib/languages/rust'));
hljs.registerLanguage('scala', require('highlight.js/lib/languages/scala'));
hljs.registerLanguage('scheme', require('highlight.js/lib/languages/scheme'));
hljs.registerLanguage('scss', require('highlight.js/lib/languages/scss'));
hljs.registerLanguage('smalltalk', require('highlight.js/lib/languages/smalltalk'));
hljs.registerLanguage('stylus', require('highlight.js/lib/languages/stylus'));
hljs.registerLanguage('swift', require('highlight.js/lib/languages/swift'));
hljs.registerLanguage('tcl', require('highlight.js/lib/languages/tcl'));
hljs.registerLanguage('tex', require('highlight.js/lib/languages/tex'));
hljs.registerLanguage('typescript', require('highlight.js/lib/languages/typescript'));
hljs.registerLanguage('verilog', require('highlight.js/lib/languages/verilog'));
hljs.registerLanguage('vhdl', require('highlight.js/lib/languages/vhdl'));
hljs.registerLanguage('yaml', require('highlight.js/lib/languages/yaml'));
var mdHtml, mdSrc, permalink, scrollMap; var mdHtml, mdSrc, permalink, scrollMap;
var defaults = { var defaults = {
@ -22,25 +79,30 @@ var defaults = {
}; };
defaults.highlight = function (str, lang) { defaults.highlight = function (str, lang) {
if (!defaults._highlight || !window.hljs) { return ''; } var esc = mdHtml.utils.escapeHtml;
var hljs = window.hljs,
esc = mdHtml.utils.escapeHtml;
if (lang && hljs.getLanguage(lang)) {
try { try {
return '<pre class="hljs"><code>' + if (!defaults._highlight) {
throw 'highlighting disabled';
}
if (lang && lang !== 'auto' && hljs.getLanguage(lang)) {
return '<pre class="hljs language-' + esc(lang.toLowerCase()) + '"><code>' +
hljs.highlight(lang, str).value + hljs.highlight(lang, str).value +
'</code></pre>'; '</code></pre>';
} catch (__) { /**/ }
}
/* try { } else if (lang === 'auto') {
var result = hljs.highlightAuto(str); var result = hljs.highlightAuto(str);
return '<pre class="hljs ' + esc(result.language) + '"><code>' +
console.log('highlight language: ' + result.language + ', relevance: ' + result.relevance);
return '<pre class="hljs language-' + esc(result.language) + '"><code>' +
result.value + result.value +
'</code></pre>'; '</code></pre>';
} catch (__) {} */ }
} catch (__) { /**/ }
return '<pre class="hljs"><code>' + esc(str) + '</code></pre>'; return '<pre class="hljs"><code>' + esc(str) + '</code></pre>';
}; };

Loading…
Cancel
Save