mdast-util-fix-relative-uris

0.1.1 • Public • Published

mdast-util-fix-relative-uris

mdast utility to fix relative URIs.

Install

npm:

npm install mdast-util-fix-relative-uris

Use

Say we have the following markdown file, example.md:

[link](about)

And our script, example.js, looks as follows:

var fs = require("fs");
var fromMarkdown = require("mdast-util-from-markdown");
var fixRelativeURIs = require("mdast-util-fix-relative-uris");

var doc = fs.readFileSync("example.md");

var tree = fromMarkdown(doc);
var baseURL = "https://www.inkdrop.app/";
var fixedTree = fixRelativeURIs(tree, baseURL);

console.log(fixedTree);

Now, running node example yields (positional info removed for brevity):

{
  type: 'root',
  children: [
    {
      type: 'paragraph',
      children: [
        {
          type: 'link',
          title: null,
          url: 'https://www.craftz.dog/about',
          children: [
            {
              type: 'text',
              value: 'link',
            }
          ],
        }
      ],
    }
  ],
}

API

fixRelativeURIs(tree, baseURI)

Fix relative URIs of links in the given mdast tree.

Parameters

  • baseURI (string) — The base URI

Returns

The given, modified, tree.

License

MIT © Takuya Matsuyama

Package Sidebar

Install

npm i mdast-util-fix-relative-uris

Weekly Downloads

3

Version

0.1.1

License

MIT

Unpacked Size

3.89 kB

Total Files

4

Last publish

Collaborators

  • craftzdog