From 6472717eaa1441b1f2315280c18712f60eeb6acf Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Thu, 13 Feb 2020 13:23:18 -0800 Subject: [PATCH] Improve example for invoking highlight.js --- docs/USING_ADVANCED.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/USING_ADVANCED.md b/docs/USING_ADVANCED.md index ee8b3126..81df205b 100644 --- a/docs/USING_ADVANCED.md +++ b/docs/USING_ADVANCED.md @@ -20,8 +20,10 @@ const marked = require('marked'); // `highlight` example uses `highlight.js` marked.setOptions({ renderer: new marked.Renderer(), - highlight: function(code) { - return require('highlight.js').highlightAuto(code).value; + highlight: function(code, language) { + const hljs = require('highlight.js'); + const validLanguage = hljs.getLanguage(language) ? language : 'plaintext'; + return hljs.highlight(validLanguage, code).value; }, pedantic: false, gfm: true,