You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pouchdb.apache.org by ja...@apache.org on 2026/05/16 09:39:14 UTC

(pouchdb) 01/18: refactor: use highlighting plugin instead of custom shortcode, add inline markdown filter

This is an automated email from the ASF dual-hosted git repository.

janl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pouchdb.git

commit fc6f5853af239fa1c691536bb96f143d641dee02
Author: Alex Feyerke <al...@neighbourhood.ie>
AuthorDate: Mon May 4 10:43:09 2026 +0200

    refactor: use highlighting plugin instead of custom shortcode, add inline markdown filter
---
 docs/eleventy.config.js | 57 ++++++++-----------------------------------------
 package-lock.json       | 15 ++++++++++++-
 package.json            |  7 ++++--
 3 files changed, 28 insertions(+), 51 deletions(-)

diff --git a/docs/eleventy.config.js b/docs/eleventy.config.js
index 3ff0e68e2..0f3f2ddd7 100644
--- a/docs/eleventy.config.js
+++ b/docs/eleventy.config.js
@@ -1,11 +1,10 @@
 const markdownIt = require('markdown-it');
-const Prism = require('prismjs');
-const loadLanguages = require('prismjs/components/');
 
 const LINEBREAK_PLACEHOLDER = '---linebreak-placeholder---';
 
 module.exports = eleventyConfig => {
   process.env.TZ = 'UTC';
+  eleventyConfig.addPlugin(require("@11ty/eleventy-plugin-syntaxhighlight"));
 
   eleventyConfig.addPassthroughCopy('asf.md');
   eleventyConfig.addPassthroughCopy('static');
@@ -56,14 +55,16 @@ module.exports = eleventyConfig => {
     return this.liquid.parseAndRender(content, this.context);
   });
 
-  const renderMarkdown = initMarkdown();
+  const md = markdownIt({
+    html: true,
+  });
+
+  eleventyConfig.addFilter('inlinemarkdown', content => md.renderInline(content));
   // Re-defined markdown-it lib to prevent eleventy messing with internals.
   // See: https://github.com/11ty/eleventy/issues/2438
-  eleventyConfig.setLibrary('md', { render:renderMarkdown });
-  eleventyConfig.addFilter('markdown', renderMarkdown);
-  eleventyConfig.addPairedShortcode('markdown', renderMarkdown);
-
-  eleventyConfig.addPairedShortcode('highlight', wrapCode);
+  eleventyConfig.setLibrary('md', md);
+  eleventyConfig.addFilter('markdown',  content => md.render(content));
+  eleventyConfig.addPairedShortcode('markdown',  content => md.render(content));
 
   eleventyConfig.addTransform('revert-linebreak-markers', function(content) {
     console.log('revert-linebreak-markers', this.outputPath);
@@ -78,43 +79,3 @@ module.exports = eleventyConfig => {
     },
   };
 };
-
-// Ensure consistent code style across:
-// * markdown indented code blocks
-// * markdown "fenced" code blocks
-// * liquid {% highlight ... %} code blocks
-function initMarkdown() {
-  const md = markdownIt({
-    html: true,
-  });
-
-  // Indented code blocks seem to introduce parsing differences across
-  // markdownversions, and inconsistencies with whitespace introduced
-  // by liquid templates.  The simplest option is to disable them, and
-  // require code "fences" (```) instead.
-  md.disable('code');
-
-  md.renderer.rules.fence = (tokens, idx, options, env, slf) => {
-    const { content, info } = tokens[idx];
-    const lang = info ? info.trim().split(/\s/)[0] : '';
-
-    return wrapCode(content, lang);
-  };
-
-  return md.render.bind(md);
-}
-
-function wrapCode(code, lang) {
-  let html = code.trim();
-
-  if(lang) {
-    loadLanguages([lang]);
-    html = Prism.highlight(html, Prism.languages[lang], lang);
-  }
-
-  // prevent markdown interpreter from converting multiple
-  // linebreaks in code examples into <p>...</p>
-  html = html.replaceAll(/\n(?=\n)/g, `\n${LINEBREAK_PLACEHOLDER}`);
-
-  return `<figure class="highlight"><pre data-copybutton><code class="language-${lang}">${html}</code></pre></figure>`;
-}
diff --git a/package-lock.json b/package-lock.json
index 429ef0a42..1edf8f7c9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,6 +9,7 @@
       "version": "7.0.0-prerelease",
       "license": "Apache-2.0",
       "dependencies": {
+        "@11ty/eleventy-plugin-syntaxhighlight": "^5.0.2",
         "@neighbourhoodie/websql": "2.0.4",
         "double-ended-queue": "2.1.0-0",
         "fetch-cookie": "2.2.0",
@@ -363,6 +364,19 @@
       "dev": true,
       "license": "MIT"
     },
+    "node_modules/@11ty/eleventy-plugin-syntaxhighlight": {
+      "version": "5.0.2",
+      "resolved": "https://registry.npmjs.org/@11ty/eleventy-plugin-syntaxhighlight/-/eleventy-plugin-syntaxhighlight-5.0.2.tgz",
+      "integrity": "sha512-T6xVVRDJuHlrFMHbUiZkHjj5o1IlLzZW+1IL9eUsyXFU7rY2ztcYhZew/64vmceFFpQwzuSfxQOXxTJYmKkQ+A==",
+      "license": "MIT",
+      "dependencies": {
+        "prismjs": "^1.30.0"
+      },
+      "funding": {
+        "type": "opencollective",
+        "url": "https://opencollective.com/11ty"
+      }
+    },
     "node_modules/@11ty/eleventy-utils": {
       "version": "2.0.7",
       "resolved": "https://registry.npmjs.org/@11ty/eleventy-utils/-/eleventy-utils-2.0.7.tgz",
@@ -8936,7 +8950,6 @@
       "version": "1.30.0",
       "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.30.0.tgz",
       "integrity": "sha512-DEvV2ZF2r2/63V+tK8hQvrR2ZGn10srHbXviTlcv7Kpzw8jWiNTqbVgjO3IY8RxrrOUF8VPMQQFysYYYv0YZxw==",
-      "dev": true,
       "license": "MIT",
       "engines": {
         "node": ">=6"
diff --git a/package.json b/package.json
index e8eed0f0a..f44fb0ce6 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,8 @@
     "release": "./bin/release.sh",
     "publish-site": "./bin/publish-site.sh",
     "build-site": "node ./bin/build-site.js",
+    "build:less": "lessc docs/src/less/pouchdb/pouchdb.less docs/static/css/pouchdb.css",
+    "build11": "npm run build:less && eleventy",
     "test-coverage": "./bin/test-coverage.sh",
     "coverage": "COVERAGE=1 SERVER=pouchdb-server POUCHDB_SERVER_FLAGS=--in-memory PLUGINS=pouchdb-find ./bin/test-coverage.sh",
     "build-test": "npm run build-test-utils && npm run build-perf",
@@ -36,6 +38,8 @@
     "url": "https://github.com/apache/pouchdb.git"
   },
   "dependencies": {
+    "@11ty/eleventy-plugin-syntaxhighlight": "^5.0.2",
+    "@neighbourhoodie/websql": "2.0.4",
     "double-ended-queue": "2.1.0-0",
     "fetch-cookie": "2.2.0",
     "level": "6.0.1",
@@ -51,8 +55,7 @@
     "spark-md5": "3.0.2",
     "through2": "3.0.2",
     "uuid": "8.3.2",
-    "vuvuzela": "1.0.3",
-    "@neighbourhoodie/websql": "2.0.4"
+    "vuvuzela": "1.0.3"
   },
   "devDependencies": {
     "@11ty/eleventy": "3.1.2",