A markdown-it plugin to process [[wikirefs]].
Note that this plugin only parses the input -- it is up to you to assign appropriate linking information and/or index relationships (between files).
🕸 Weave a semantic web in your 🎋 WikiBonsai digital garden.
Install with npm:
$ npm install markdown-it-wikirefs
import markdownIt from 'markdown-it';
import wikirefs_plugin from 'markdown-it-wikirefs';
const md = markdownIt();
const options = {
resolveHtmlHref: (env: any, fname: string) => {
const extname: string = wikirefs.isMedia(fname) ? path.extname(fname) : '';
fname = fname.replace(extname, '');
return '/' + fname.trim().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '') + extname;
},
resolveHtmlText: (env: any, fname: string) => fname.replace(/-/g, ' '),
resolveEmbedContent: (env: any, fname: string) => fname + ' content',
};
md.use(wikirefs_plugin, options);
md.render('[[wikilink]]');
Require style imports work as well:
const wikirefs_plugin = require('markdown-it-wikirefs');
// if you encounter issues, try:
const wikirefs_plugin = require('markdown-it-wikirefs').default;
For syntax specifications, see the wikirefs repo.
For render output:
resolveHtmlText
resolveHtmlHref
resolveEmbedContent
For wikiembeds
-- note:
path.extname(filename)
is used to identify the file extension which determines how the embed should be formatted.- Check for self-references and cycles when defining
opts.resolveEmbedContent()
.
For metadata population:
addAttr
addLink
addEmbed
prepFile
(useful for clearing a cache for the current markdown file per render)
These are options wikiattrs-specific options. If markdown-it-wikirefs
is being used in conjunction with markdown-it-caml
, attrs
options may be set in markdown-it-caml
and will apply to markdown-it-wikirefs
as well.
A boolean property that toggles parsing and rendering wikiattrs on/off.
A boolean property that toggles rendering wikiattrs on/off. This is useful in the scenario where wikiattrs are used for metadata and not for display purposes; like a yaml-stand-in.
A string to be rendered in the wikiattrs' attrbox.
A base url that is applied to all urls internally.
CSS classnames may be overridden here.
Classname for wikiattrs. Default is attr
.
Classname for wikilinks. Default is link
.
Classname for typed wikilinks. Default is type
.
Classname for valid wikirefs. Default is wiki
.
Classname for invalid wikirefs. Default is invalid
.
Classname for wikiref type. Default is reftype__
and combined with the slugified form of the user-defined reftype.
Classname for document type. Default is doctype__
and combined with the slugified form of the user-defined doctype.
Classname for the wikiattr attrbox. Default is attrbox
.
Classname for the wikiattr attrbox title. Default is attrbox-title
.
These are options wikilinks-specific options.
A boolean property that toggles parsing/rendering wikilinks on/off.
A function which takes in markdown-it's env
var and the fname
extracted from a wikilink [[fname]]
. It should return a string which is the name of the file's document type or undefined
if no document type exists. (Relevant file data should be stored in env
, but if not fname
can be used to search for the file instead.)
A function which takes in markdown-it's env
var and the fname
extracted from a wikilink [[fname]]
. It should return the content of an embedded markdown file. Be sure to handle self references and cycles with care when re-using the markdown-it instance to re-render content (e.g. md.render(content)
).
A function which takes in markdown-it's env
var and the fname
extracted from a wikilink [[fname]]
. It should return the url of the wikilink-ed file or undefined
if no such file exists. If no such file exists, the wikilink will render as disabled and marked as invalid. (Relevant file data should be stored in env
, but if not fname
can be used to search for the file instead.)
It is recommended to override the default, but there is a default returns: '/' + fname.trim().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '')
.
A function which takes in markdown-it's env
var and the fname
extracted from a wikilink [[fname]]
. It should return a string representing the text to populate the a tag's innertext of the wikilink-ed file -- this is often its title -- or undefined
if no such file exists. If no such file exists, the filename will be used to populate innertext instead. Be sure to apply any text formatting such as lower-casing here. (Relevant file data should be stored in env
, but if not fname
can be used to search for the file instead.)
It is recommended to override the default, but there is a default which returns: fname.replace('-', ' ')
.