@bouzuya/expand-markdown-anchors
v1.3.1
Published
expand-markdown-anchors
Downloads
5
Readme
expand-markdown-anchors
expand-markdown-anchors
Installation
$ npm install @bouzuya/expand-markdown-anchors
Usage
import * as assert from 'assert';
import { expand, init, match } from 'expand-markdown-anchors';
assert.deepStrictEqual(expand('[user/repo][]'), [
'[user/repo]: https://github.com/user/repo'
]);
assert.deepStrictEqual(match('[user/repo][]'), [
'user/repo'
]);
assert.deepStrictEqual(expand('[npm:pkg][]'), [
'[npm:pkg]: https://www.npmjs.com/package/pkg'
]);
assert.deepStrictEqual(expand('[rfc:9999][]'), [
'[rfc:9999]: https://tools.ietf.org/html/rfc9999'
]);
assert.deepStrictEqual(expand('[vscode:bouzuya.bs-code][]'), [
'[vscode:bouzuya.bs-code]: https://marketplace.visualstudio.com/items?itemName=bouzuya.bs-code'
]);
// use custom rules
const { expand: myExpand, match: myMatch } = init([
(s) => s === 'a/b' ? 'http://example.com' : null
]);
assert.deepStrictEqual(myExpand('[text][a/b]'), [
'[a/b]: http://example.com'
]);
assert.deepStrictEqual(myMatch('[text][a/b]'), ['a/b']);
assert.deepStrictEqual(myMatch('[text][c/d]'), []);