From 6e43d0c23e7e4106aa62f96418a49bfecd97c8f5 Mon Sep 17 00:00:00 2001 From: Mario Kahlhofer Date: Tue, 19 Oct 2021 11:00:15 +0200 Subject: [PATCH 1/3] Replace marked with markdown-it --- lib/index.js | 13 +++++++------ package.json | 10 ++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index 7e36978..3ea3185 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,8 @@ var Q = require('q'); var debug = require('debug'); var path = require('path'); -var marked = require('marked'); +var markdownIt = require('markdown-it'); +var markdownItAttrs = require('markdown-it-attrs'); var hljs = require('highlight.js'); var yaml = require('js-yaml'); var mustache = require('mustache'); @@ -60,8 +61,7 @@ function Cleaver(document, options, includePath) { this.slides = []; this.override = false; - marked.setOptions({ - gfm: true, + this.md = markdownIt({ highlight: function (code, lang) { try { return hljs.highlight(lang, code).value; @@ -69,7 +69,8 @@ function Cleaver(document, options, includePath) { return code; } } - }); + }) + .use(markdownItAttrs); } @@ -274,7 +275,7 @@ Cleaver.prototype.renderSlideshow = function () { * @return {string} The formatted slide */ Cleaver.prototype.renderSlide = function (content) { - return marked(content); + return this.md.render(content); }; @@ -295,7 +296,7 @@ Cleaver.prototype.renderAuthorSlide = function (content) { * @param {string} The full document * @return {Array.} A list of all slides */ -Cleaver.prototype.slice = function(document) { +Cleaver.prototype.slice = function (document) { var cuts = document.split(/\n(?=\-\-)/); var slices = []; var nlIndex; diff --git a/package.json b/package.json index 126cbb6..0227733 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,12 @@ "version": "0.8.6", "author": "Jordan Scales ", "description": "30-second slideshows for hackers", - "keywords": ["markdown", "static", "slideshow", "presentation"], + "keywords": [ + "markdown", + "static", + "slideshow", + "presentation" + ], "bin": { "cleaver": "./bin/cleaver" }, @@ -18,7 +23,8 @@ "debug": "^3.1.0", "highlight.js": "~9.12.0", "js-yaml": "3.10.0", - "marked": "^0.3.7", + "markdown-it": "^12.2.0", + "markdown-it-attrs": "^4.1.0", "mustache": "^2.3.0", "q": "1.5.1", "tiny-lr": "^1.0.5" From 448ade4c9b1219acae875778f8a90497862d62c4 Mon Sep 17 00:00:00 2001 From: Mario Kahlhofer Date: Tue, 19 Oct 2021 11:03:26 +0200 Subject: [PATCH 2/3] Bump higlight.js to 11.3 --- lib/index.js | 10 ++++++---- package.json | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index 3ea3185..2b66862 100644 --- a/lib/index.js +++ b/lib/index.js @@ -63,11 +63,13 @@ function Cleaver(document, options, includePath) { this.md = markdownIt({ highlight: function (code, lang) { - try { - return hljs.highlight(lang, code).value; - } catch (e) { - return code; + if (lang && hljs.getLanguage(lang)) { + try { + return hljs.highlight(code, { language: lang }).value; + } catch (__) { } } + + return ''; // use external default escaping } }) .use(markdownItAttrs); diff --git a/package.json b/package.json index 0227733..3e40bdc 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dependencies": { "commander": "~2.12.2", "debug": "^3.1.0", - "highlight.js": "~9.12.0", + "highlight.js": "^11.3.1", "js-yaml": "3.10.0", "markdown-it": "^12.2.0", "markdown-it-attrs": "^4.1.0", From 2b2b8decf6b8df13183c277a1856a95928c51437 Mon Sep 17 00:00:00 2001 From: Mario Kahlhofer Date: Tue, 19 Oct 2021 14:36:39 +0200 Subject: [PATCH 3/3] Allow HTML tags in source as marked did it --- lib/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/index.js b/lib/index.js index 2b66862..bcc7157 100644 --- a/lib/index.js +++ b/lib/index.js @@ -62,6 +62,7 @@ function Cleaver(document, options, includePath) { this.override = false; this.md = markdownIt({ + html: true, highlight: function (code, lang) { if (lang && hljs.getLanguage(lang)) { try {