remark-wiki-link-a
v0.0.5
Published
Parse and render wiki-style links
Downloads
2
Maintainers
Readme
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]:
npm install remark-wiki-link-a
Usage
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.value
usingoptions.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 thea
when it is rendered as HTML. These are configurable withoptions.wikiLinkClassName
andoptions.newClassName
.options.newClassName
is attached whendata.exists
is false.data.hProperties.href
:href
value for the rendereda
. Thishref
is 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:false
options.mdPrefix
: ifstringify
is true, the prefix added to the Markdown link; default:""
options.mdSuffix
: ifstringify
is true, the suffix added to the Markdown link; default:".md"
options.mdSpace
: ifstringify
is true, replace space with this; default:"-"
options.htmlClass
: add this class to the HTMLa
element; default:wikilink
options.htmlPrefix
: the prefix added to the HTMLa href
link; default:""
options.htmlSuffix
: the prefix added to the HTMLa href
link; default:".html"
options.htmlSpace
: replace space with this; default:"-"