From 2de077d39f85a68b97dc2cc73a3c3316e799f82c Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 24 Feb 2021 16:06:13 -0600 Subject: [PATCH] docs: highlight code --- package.json | 5 +++-- scripts/build-docs.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d689f2c..4a1883a 100644 --- a/package.json +++ b/package.json @@ -27,13 +27,14 @@ "verror": "^1.8.1" }, "devDependencies": { - "eslint": "^7.14.0", + "eslint": "^7.20.0", "eslint-config-standard": "^16.0.2", "eslint-plugin-import": "^2.22.1", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^4.2.1", + "eslint-plugin-promise": "^4.3.1", "front-matter": "^4.0.2", "get-port": "^5.1.1", + "highlight.js": "^10.6.0", "husky": "^4.2.5", "marked": "^2.0.0", "tap": "14.11.0" diff --git a/scripts/build-docs.js b/scripts/build-docs.js index 867cbc8..bbd62e0 100644 --- a/scripts/build-docs.js +++ b/scripts/build-docs.js @@ -2,6 +2,16 @@ const fs = require('fs/promises') const path = require('path') const marked = require('marked') const fm = require('front-matter') +const { highlight, highlightAuto } = require('highlight.js') + +marked.use({ + highlight: (code, lang) => { + if (!lang) { + return highlightAuto(code).value + } + return highlight(lang, code).value + } +}) function tocHTML (toc) { let html = '