Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inkdropapp/mdast-util-fix-relative-uris
Resolve relative URIs in MDAST
https://github.com/inkdropapp/mdast-util-fix-relative-uris
markdown mdast micromark remark
Last synced: 20 days ago
JSON representation
Resolve relative URIs in MDAST
- Host: GitHub
- URL: https://github.com/inkdropapp/mdast-util-fix-relative-uris
- Owner: inkdropapp
- License: mit
- Created: 2021-03-31T07:44:17.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-04-02T02:48:45.000Z (over 3 years ago)
- Last Synced: 2024-04-09T15:12:17.068Z (9 months ago)
- Topics: markdown, mdast, micromark, remark
- Language: JavaScript
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mdast-util-fix-relative-uris
**[mdast][]** utility to fix relative URIs.
## Install
[npm][]:
```sh
npm install mdast-util-fix-relative-uris
```## Use
Say we have the following markdown file, `example.md`:
```markdown
[link](about)
```And our script, `example.js`, looks as follows:
```js
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):
```js
{
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][license] © [Takuya Matsuyama][author]
[mdast]: https://github.com/syntax-tree/mdast
[npm]: https://docs.npmjs.com/cli/install
[license]: LICENSE
[author]: https://www.craftz.dog/