0.0.5 • Published 6 years ago
remark-wiki-link-a v0.0.5
remark-wiki-link-a
This remark plugin parses and renders [[Wiki Links]]. It is derived from the plugin by landakram.
- Parse wiki-style links and render them as anchors
- Parse aliased wiki links i.e
[[Real Page:Page Alias]]
Installation
npm:
npm install remark-wiki-link-aUsage
const unified = require('unified')
const markdown = require('remark-parse')
const wikiLinkPlugin = require('remark-wiki-link-a');
let processor = unified()
.use(markdown, { gfm: true })
.use(wikiLinkPlugin)When the processor is run, wiki links will be parsed to a wikiLink node.
If we have this markdown string:
[[Test Page]]A node will be created that looks like this:
{
value: 'Test Page',
data: {
alias: 'Test Page',
permalink: 'Test-Page.html',
exists: false,
hName: 'a',
hProperties: {
className: 'wikilink',
href: 'Test-Page.html'
},
hChildren: [{
type: 'text',
value: 'Test Page'
}]
}
}data.alias: The display name for this linkdata.permalink: The permalink for this page. This permalink is computed fromnode.valueusingoptions.pageResolver, which can be passed in when initializing the plugin.data.exists: Whether the page exists. A page exists if its permalink is found inoptions.permalinks, passed when initializing the plugin.data.hProperties.className: Classes that are automatically attached to theawhen it is rendered as HTML. These are configurable withoptions.wikiLinkClassNameandoptions.newClassName.options.newClassNameis attached whendata.existsis false.data.hProperties.href:hrefvalue for the rendereda. Thishrefis computed usingoptions.hrefTemplate.
When rendered to HTML, we get:
<a class="wikilink" href="Test-Page.html">Test Page</a>Configuration options
options.stringify: iftrue, replaces the wiki links by traditional links in Markdown; default:falseoptions.mdPrefix: ifstringifyis true, the prefix added to the Markdown link; default:""options.mdSuffix: ifstringifyis true, the suffix added to the Markdown link; default:".md"options.mdSpace: ifstringifyis true, replace space with this; default:"-"options.htmlClass: add this class to the HTMLaelement; default:wikilinkoptions.htmlPrefix: the prefix added to the HTMLa hreflink; default:""options.htmlSuffix: the prefix added to the HTMLa hreflink; default:".html"options.htmlSpace: replace space with this; default:"-"