@paperist/remark-crossref
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@paperist/remark-crossref

LICENSE NPM standard-readme compliant

wooorm/remark plugin for corss-references inspired by pandoc-crossref

Table of Contents

Install

npm i remark @paperist/remark-crossref

Usage

const unified = require('unified');
const parser = require('remark-parse');
const crossref = require('@paperist/remark-crossref');

const markdown = `
# Heading {#sec:first}

See sec.[@sec:first].
`;

const processor = unified()
  .use(parser)
  .use(crossref);
const ast = processor.parse(markdown);

processor.run(ast).then((ast) => {
  console.dir(ast, { depth: null });
});

AST

See also mdast, unist.

CrossReferenceLabel

CrossReferenceLabel extends Literal.

interface CrossReferenceLabel extends Literal {
  type: 'crossReferenceLabel';
  label: string;
  options: { [key: string]: any };
}

For example, the following markdown:

# Heading {#sec:first}

Yields:

{
  "type": "heading",
  "depth": 1,
  "children": [
    {
      "type": "text",
      "value": "Heading "
    },
    {
      "type": "crossReferenceLabel",
      "value": "{#sec:first}",
      "label": "sec:first",
      "options": {}
    }
  ]
}

CrossReference

CrossReference extends Literal.

interface CrossReference extends Literal {
  type: 'crossReference';
  identifiers: string[];
}

For example, the following markdown:

See sec.[@sec:first;@sec:second]

Yields:

{
  "type": "paragraph",
  "children": [
    {
      "type": "text",
      "value": "See sec."
    },
    {
      "type": "crossReference",
      "value": "[@sec:first;@sec:second]",
      "identifiers": ["sec:first", "sec:second"]
    }
  ]
}

Contribute

PRs accepted.

License

MIT (c) 3846masa

Package Sidebar

Install

npm i @paperist/remark-crossref

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

42.7 kB

Total Files

15

Last publish

Collaborators

  • 3846masa
  • paperist-owner