unified

Project: landakram/remark-wiki-link

Package: remark-wiki-link@1.0.4

  1. Dependents: 0
  2. Parse and render wiki-style links
  1. remark 214
  2. markdown 154
  3. remark-plugin 82
  4. gfm 21

remark-wiki-link

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]].

Looking for lower level packages? Check out 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('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',
        exists: false,
        hName: 'a',
        hProperties: {
            className: 'internal new',
            href: '#/page/test_page'
        },
        hChildren: [{
            type: 'text',
            value: 'Test Page'
        }]
    }
}

When rendered to HTML, we get:

<a class="internal new" href="#/page/test_page">Test Page</a>

Configuration options

(name) => [name.replace(/ /g, '_').toLowerCase()]
(permalink) => `#/page/${permalink}`

Aliasing pages

Aliased pages are supported with the following markdown syntax:

[[Real Page:Page Alias]]

The AST node will look like:

{
    value: 'Real Page',
    data: {
        alias: 'Page Alias',
        permalink: 'real_page',
        exists: false,
        hName: 'a',
        hProperties: {
            className: 'internal new',
            href: '#/page/real_page'
        },
        hChildren: [{
            type: 'text',
            value: 'Page Alias'
        }]
    }
}

And will produce this HTML when rendered:

<a class="internal new" href="#/page/real_page">Page Alias</a>