commonmark-wikiwords
v3.1.0
Published
Convert WikiWords to links in commonmark source
Downloads
9
Readme
WikiWords for commonmark.js
This package offers an AST transformer for adding WikiWords syntax to CommonMark.
Usage
var commonmark = require("commonmark");
var wikiwords = require("commonmark-wikiwords");
var reader = new commonmark.Parser();
var writer = new commonmark.HtmlRenderer();
var parsed = reader.parse(src);
var transformed = wikiwords.transform(parsed);
var htmlSrc = writer.render(transformed);
WikiWord Syntax
This package has a looser definition of WikiWords.
In addition to FooBar
and FooBarBaz
, it supports FooBBar
and
FooB
.
This follow the exact definition of WikiCase on C2 Wiki, which does not allow these. If strict compliance is useful, please file a bug.
To avoid forming wikiwords, C2 suggests embedding an empty
string. You can do something
similar in commonmark: Foo<!-- -->Bar
.
Highlighting Nonexistent Links
You can also pass a callback to style links based on their name. This is useful for styling links that don't yet exist.
var commonmark = require("commonmark");
var wikiwords = require("commonmark-wikiwords");
var reader = new commonmark.Parser();
var writer = new commonmark.HtmlRenderer();
var parsed = reader.parse(src);
var transformed = wikiwords.transform(parsed, name =>
name === "foo" ? "exciting-page" : null
);
var htmlSrc = writer.render(transformed);