@stereobooster/remark-wiki-link
v2.1.0
Published
Parse and render wiki-style links
Downloads
71
Maintainers
Readme
@stereobooster/remark-wiki-link
Fork of remark-wiki-link to simplify options.
⚠️ This plugin is affected by the new parser in remark (micromark
, see remarkjs/remark#536
). For remark 12, use v0.0.x of this package. For remark 13+, use v1.0.0 or above.
This remark plugin parses and renders [[Wiki Links]]
.
- Parse wiki-style links and render them as anchors
- Parse aliased wiki links i.e
[[Real Page:Page Alias]]
Looking for lower level packages? Check out @stereobooster/mdast-util-wiki-link for working with ASTs and micromark-extension-wiki-link for working with tokens.
Usage
const unified = require('unified')
const markdown = require('remark-parse')
const wikiLinkPlugin = require('@stereobooster/remark-wiki-link');
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',
hName: 'a',
hProperties: {
href: 'Test Page'
},
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.linkResolver
, which can be passed in when initializing the plugin.data.h...
: provide compatibility withrehype
. Computed fromdata
usingoptions.linkTemplate
Configuration options
options.linkResolver (pageName: String) -> String
: A function that maps a page name to a permalink.options.linkTemplate (opts: { permalink: string, alias: string }) -> hast
: A function that creates hast representation of wiki link. Default value is:
function defaultLinkTemplate ({ permalink, alias }: LinkTemplateProps) {
return {
hName: 'a',
hProperties: { href: permalink },
hChildren: [{ type: 'text', value: alias }]
}
}
options.aliasDivider [String]
: a string to be used as the divider for aliases. See the section below on Aliasing pages. Defaults to":"
.
Aliasing pages
Aliased pages are supported with the following markdown syntax:
[[Real Page:Page Alias]]
And will produce this HTML when rendered:
<a href="Real Page">Page Alias</a>