@stereobooster/remark-wiki-link
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

@stereobooster/remark-wiki-link

Fork of remark-wiki-link to simplify options.

npm version Build Status

⚠️ 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 link
  • data.permalink: The permalink for this page. This permalink is computed from node.value using options.linkResolver, which can be passed in when initializing the plugin.
  • data.h...: provide compatibility with rehype. Computed from data using options.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>

Package Sidebar

Install

npm i @stereobooster/remark-wiki-link

Weekly Downloads

4

Version

2.1.0

License

MIT

Unpacked Size

27.3 kB

Total Files

16

Last publish

Collaborators

  • stereobooster