Feather Wiki

A tiny tool for simple, self-contained wikis!

Extensions /

Marked.js Replacement

Created:

By default, Feather Wiki uses a custom Markdown parser modified from md.js, but some people who use Markdown extensively and are used to more robust features offered by other apps have found this fairly limiting. If you're one of those people, then you can replace the default Markdown parser in Feather Wiki with the vastly more powerful Marked.js to get a more reliable parser with extra features.

Installation #

Add the following code to the "Custom JS" text area in your Wiki Settings:

/**** Replace Parser with Marked.js ****/
FW.ready(() => {
var markedScript = document.createElement('script');
document.body.appendChild(markedScript);
markedScript.onload = () => {
  window.md = window.marked.parse;
  FW.emit('render');
}
markedScript.src = 'https://cdn.jsdelivr.net/npm/marked/marked.min.js';
});
/**** End Replace Parser with Marked.js ****/

Then click "Update" in the Wiki Settings, save your wiki using the "Save Wiki" button, and load your newly-saved wiki to see the new parser in action!

What It Does #

This script downloads the newest minified version of Marked.js from the jsDelivr CDN and replaces Feather Wiki's built-in Markdown parser with Marked's parse function once it's finished downloading. It then triggers Feather Wiki to re-render the page using Marked, and subsequently use Marked to parse Markdown from then on while the Feather Wiki is loaded. By default, Marked offers "GitHub Flavored Markdown" (GFM), which allows the use of tables among many other expected features.

It is possible to customize your Marked experience with a little bit of JavaScript knowhow by referencing the Marked Advanced Usage documentation and changing Marked's options before replacing the window.md function.

Be Aware #

This script downloads Marked.js from an external website, so you must be connected to the internet to use it unless you download the script to the same folder as your Feather Wiki file and change the last line to markedScript.src = './marked.min.js';.
Either way, the minified Marked.js file itself is ~48 kilobytes, so also be aware of that—this will not affect the vast majority of people, but I mention it only because Feather Wiki itself aims to have a tiny file size.

Also be aware that this replacement may cause a quick flicker when your Feather Wiki is first loaded as Marked is swapped in, and there may be a (very) brief moment where unparsed markdown is visible. Once your page is loaded, this should not happen again as a result of this replacement, but I wanted to mention it in case anyone noticed and wondered.

Interesting Note #

Using this same strategy, you can replace the Markdown parser with nearly any other parser (so long as it has a JavaScript library)! For example, see this discussion for some guidance on how to use AsciiDoc instead of Markdown. Mentions of "Markdown" throughout Feather Wiki will remain, but the parser will expect AsciiDoc on pages instead of Markdown.