Browse Source

Updated highlight.js usage info

- Ref #779
pull/783/head
Vitaly Puzrin 4 years ago
parent
commit
064d602c68
  1. 4
      README.md
  2. 8
      benchmark/samples/README.md
  3. 4
      lib/index.js
  4. 2
      package.json
  5. 4
      support/api_header.md
  6. 4
      support/demo_template/index.js

4
README.md

@ -152,7 +152,7 @@ var md = require('markdown-it')({
highlight: function (str, lang) { highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) { if (lang && hljs.getLanguage(lang)) {
try { try {
return hljs.highlight(lang, str).value; return hljs.highlight(str, { language: lang }).value;
} catch (__) {} } catch (__) {}
} }
@ -172,7 +172,7 @@ var md = require('markdown-it')({
if (lang && hljs.getLanguage(lang)) { if (lang && hljs.getLanguage(lang)) {
try { try {
return '<pre class="hljs"><code>' + return '<pre class="hljs"><code>' +
hljs.highlight(lang, str, true).value + hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
'</code></pre>'; '</code></pre>';
} catch (__) {} } catch (__) {}
} }

8
benchmark/samples/README.md

@ -18,10 +18,16 @@ __v4.+ changed internals! Plugins need update. See [migration details](https://g
__Table of content__ __Table of content__
- [markdown-it](#markdown-it)
- [Install](#install) - [Install](#install)
- [Usage examples](#usage-examples) - [Usage examples](#usage-examples)
- [Simple](#simple)
- [Init with presets and options](#init-with-presets-and-options)
- [Plugins load](#plugins-load)
- [Syntax highlighting](#syntax-highlighting)
- [API](#api) - [API](#api)
- [Syntax extensions](#syntax-extensions) - [Syntax extensions](#syntax-extensions)
- [Manage rules](#manage-rules)
- [Benchmark](#benchmark) - [Benchmark](#benchmark)
- [Authors](#authors) - [Authors](#authors)
- [References / Thanks](#references--thanks) - [References / Thanks](#references--thanks)
@ -142,7 +148,7 @@ var md = require('markdown-it')({
highlight: function (str, lang) { highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) { if (lang && hljs.getLanguage(lang)) {
try { try {
return hljs.highlight(lang, str).value; return hljs.highlight(str, { language: lang }).value;
} catch (__) {} } catch (__) {}
} }

4
lib/index.js

@ -188,7 +188,7 @@ function normalizeLinkText(url) {
* highlight: function (str, lang) { * highlight: function (str, lang) {
* if (lang && hljs.getLanguage(lang)) { * if (lang && hljs.getLanguage(lang)) {
* try { * try {
* return hljs.highlight(lang, str, true).value; * return hljs.highlight(str, { language: lang, ignoreIllegals: true }).value;
* } catch (__) {} * } catch (__) {}
* } * }
* *
@ -208,7 +208,7 @@ function normalizeLinkText(url) {
* if (lang && hljs.getLanguage(lang)) { * if (lang && hljs.getLanguage(lang)) {
* try { * try {
* return '<pre class="hljs"><code>' + * return '<pre class="hljs"><code>' +
* hljs.highlight(lang, str, true).value + * hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
* '</code></pre>'; * '</code></pre>';
* } catch (__) {} * } catch (__) {}
* } * }

2
package.json

@ -55,7 +55,7 @@
"eslint": "^7.0.0", "eslint": "^7.0.0",
"express": "^4.14.0", "express": "^4.14.0",
"gh-pages": "^3.1.0", "gh-pages": "^3.1.0",
"highlight.js": "^10.0.3", "highlight.js": "^10.7.2",
"jest-worker": "^26.6.2", "jest-worker": "^26.6.2",
"markdown-it-abbr": "^1.0.4", "markdown-it-abbr": "^1.0.4",
"markdown-it-container": "^3.0.0", "markdown-it-container": "^3.0.0",

4
support/api_header.md

@ -117,7 +117,7 @@ var md = require('markdown-it')({
highlight: function (str, lang) { highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) { if (lang && hljs.getLanguage(lang)) {
try { try {
return hljs.highlight(lang, str).value; return hljs.highlight(str, { language: lang }).value;
} catch (__) {} } catch (__) {}
} }
@ -137,7 +137,7 @@ var md = require('markdown-it')({
if (lang && hljs.getLanguage(lang)) { if (lang && hljs.getLanguage(lang)) {
try { try {
return '<pre class="hljs"><code>' + return '<pre class="hljs"><code>' +
hljs.highlight(lang, str, true).value + hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
'</code></pre>'; '</code></pre>';
} catch (__) {} } catch (__) {}
} }

4
support/demo_template/index.js

@ -91,7 +91,7 @@ defaults.highlight = function (str, lang) {
if (lang && lang !== 'auto' && hljs.getLanguage(lang)) { if (lang && lang !== 'auto' && hljs.getLanguage(lang)) {
return '<pre class="hljs language-' + esc(lang.toLowerCase()) + '"><code>' + return '<pre class="hljs language-' + esc(lang.toLowerCase()) + '"><code>' +
hljs.highlight(lang, str, true).value + hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
'</code></pre>'; '</code></pre>';
} else if (lang === 'auto') { } else if (lang === 'auto') {
@ -183,7 +183,7 @@ function mdInit() {
function setHighlightedlContent(selector, content, lang) { function setHighlightedlContent(selector, content, lang) {
if (window.hljs) { if (window.hljs) {
$(selector).html(window.hljs.highlight(lang, content).value); $(selector).html(window.hljs.highlight(content, { language: lang }).value);
} else { } else {
$(selector).text(content); $(selector).text(content);
} }

Loading…
Cancel
Save