remark-wikilinks
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

remark-wikilinks

A remark plugin that is a replacement for remark-wiki-link.

Differences between this and remark-wiki-link:

  • Supports path segments
  • Supports the pipe trick
  • How the pageResolver function works
  • Removed permalinks option in favor of using pageResolver return value.

Installation

npm:

npm install remark-wikilinks

yarn:

yarn add remark-wikilinks

Usage

const unified = require('unified');
const markdown = require('remark-parse');
const wikiLinksPlugin = require('remark-wikilinks');
let processor = unified().use(markdown, { gfm: true }).use(wikiLinksPlugin);

When the processor is run, wiki links will be parsed to a wikiLink node.

Configuration

Most of the configuration is the same as remark-wiki-link.

  • options.pageResolver (pageName: string) -> PageResolution: A function returns a possible permalink and whether or not the page exists.

    The default pageResolver is:

function pageResolver(pageName) {
    return {
        slug: pageName.replace(/ /g, '_').toLowerCase(),
        exists: true,
    };
}
  • options.hrefTemplate (permalink: string, segment: string) -> string: A function that maps a permalink and a page segment to some path. This path is used as the href for the rendered a.

    The default hrefTemplate is:

function hrefTemplate(permalink, segment) {
    if (segment.length > 0) return `/wiki/${permalink}#${segment}`;
    return `/wiki/${permalink}`;
}
  • options.wikiLinkClassName: A class name that is attached to any rendered wiki links. Defaults to "internal".
  • options.newClassName: A class name that is attached to any rendered wiki links that do not exist. Defaults to "new".
  • options.aliasDivider: A string for page aliases. Defaults to "|"
  • options.segmentCharacter: A string that prefixes the page segment. Defaults to "#".
  • options.pipeTrickRemove: A regex that specifies what to remove when using the pipe trick. Defaults to / *([A-Za-z0-9_-]+:|, [A-Za-z0-9_-]+|\([A-Za-z0-9_-]+\)|#[A-Za-z0-9_-]+) */g.

Readme

Keywords

none

Package Sidebar

Install

npm i remark-wikilinks

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

13.4 kB

Total Files

7

Last publish

Collaborators

  • c1200