{"_id":"@braindb/mdast-util-wiki-link","name":"@braindb/mdast-util-wiki-link","dist-tags":{"latest":"0.2.0"},"versions":{"0.2.0":{"name":"@braindb/mdast-util-wiki-link","version":"0.2.0","description":"Parse and render wiki-style links","keywords":["remark","remark-plugin","markdown","gfm","micromark","micromark-plugin","mdast","mdast-util"],"repository":{"type":"git","url":"git+https://github.com/stereobooster/braindb.git","directory":"packages/mdast-util-wiki-link"},"contributors":[{"name":"Mark Hudnall","email":"me@markhudnall.com","url":"https://markhudnall.com"},{"name":"stereobooster"}],"license":"MIT","type":"module","sideEffects":false,"exports":{"types":"./dist/index.d.js","default":"./dist/index.js"},"main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.js","devDependencies":{"micromark":"^4.0.0","typescript":"^5.4.5","unist-util-visit":"^5.0.0","vite-tsconfig-paths":"^4.3.2","vitest":"^1.6.0","@braindb/micromark-extension-wiki-link":"^0.1.0"},"dependencies":{"@types/unist":"^3.0.2","mdast-util-from-markdown":"^2.0.0","mdast-util-to-markdown":"^2.1.0"},"scripts":{"test":"vitest","build":"rm -rf dist && tsc","dev":"tsc --watch","clean":"rm -rf dist"},"bugs":{"url":"https://github.com/stereobooster/braindb/issues"},"homepage":"https://github.com/stereobooster/braindb#readme","_id":"@braindb/mdast-util-wiki-link@0.2.0","_integrity":"sha512-R5DRorx8dHFNCXjUDmp9T8uEN2WOBEn0EqL25GPgxZvfqTq99ZnhcHJYzOyQVIfP7qov4lau/gDYk617e8p2JA==","_resolved":"/private/var/folders/vv/fk4322kj49bcxmxz9kbnwjv00000gp/T/856ffee7e3b8655e2caef3bde827460b/braindb-mdast-util-wiki-link-0.2.0.tgz","_from":"file:braindb-mdast-util-wiki-link-0.2.0.tgz","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-R5DRorx8dHFNCXjUDmp9T8uEN2WOBEn0EqL25GPgxZvfqTq99ZnhcHJYzOyQVIfP7qov4lau/gDYk617e8p2JA==","shasum":"b4051b38749679a002713ec245d36ccd21bf7475","tarball":"https://registry.npmjs.org/@braindb/mdast-util-wiki-link/-/mdast-util-wiki-link-0.2.0.tgz","fileCount":9,"unpackedSize":10095,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG5ofkuG5Cpw1BtnIJ9qsaEMRhtRU2lr5MKbgIHcvs0gAiBUcfMkvRdrjrk61mH808rp16h7hCnSi/UMf9Vob5+nIg=="}]},"_npmUser":{"name":"stereobooster","email":"stereobooster@gmail.com"},"directories":{},"maintainers":[{"name":"stereobooster","email":"stereobooster@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mdast-util-wiki-link_0.2.0_1715620085088_0.6458965509885128"},"_hasShrinkwrap":false}},"time":{"created":"2024-05-13T17:08:04.948Z","0.2.0":"2024-05-13T17:08:05.301Z","modified":"2024-05-13T17:08:05.667Z"},"maintainers":[{"name":"stereobooster","email":"stereobooster@gmail.com"}],"description":"Parse and render wiki-style links","homepage":"https://github.com/stereobooster/braindb#readme","keywords":["remark","remark-plugin","markdown","gfm","micromark","micromark-plugin","mdast","mdast-util"],"repository":{"type":"git","url":"git+https://github.com/stereobooster/braindb.git","directory":"packages/mdast-util-wiki-link"},"contributors":[{"name":"Mark Hudnall","email":"me@markhudnall.com","url":"https://markhudnall.com"},{"name":"stereobooster"}],"bugs":{"url":"https://github.com/stereobooster/braindb/issues"},"license":"MIT","readme":"# @braindb/mdast-util-wiki-link\n\nfork of https://github.com/landakram/mdast-util-wiki-link\n\n---\n\nExtension for [`mdast-util-from-markdown`](https://github.com/syntax-tree/mdast-util-from-markdown) and\n[`mdast-util-to-markdown`](https://github.com/syntax-tree/mdast-util-to-markdown) to support `[[Wiki Links]]`.\n\n- Parse wiki-style links and render them as anchors\n- Differentiate between \"new\" and \"existing\" wiki links by giving the parser a list of existing permalinks\n- Parse aliased wiki links i.e `[[Real Page|Page Alias]]`\n\nUsing [remark](https://github.com/remarkjs/remark)? You might want to use\n[`@braindb/remark-wiki-link`](https://github.com/stereobooster/braindb/tree/main/packages/remark-wiki-link) instead of using this package directly.\n\n## Usage\n\n### Markdown to AST\n\n```javascript\nimport fromMarkdown from \"mdast-util-from-markdown\";\nimport { syntax } from \"@braindb/micromark-extension-wiki-link\";\nimport * as wikiLink from \"@braindb/mdast-util-wiki-link\";\n\nlet ast = fromMarkdown(\"[[Test Page]]\", {\n  extensions: [syntax()],\n  mdastExtensions: [wikiLink.fromMarkdown()],\n});\n```\n\nThe AST node will look like this:\n\n```javascript\n{\n    value: 'Test Page',\n    data: {\n        alias: 'Test Page',\n        permalink: 'Test Page',\n        hName: 'a',\n        hProperties: {\n            href: 'Test Page',\n        },\n        hChildren: [{\n            type: 'text',\n            value: 'Test Page'\n        }]\n    }\n}\n```\n\n- `value`: slug of the page\n- `data.alias`: The display name for this link\n- `data.permalink`: The permalink for this page. This permalink is computed from `node.value` using `options.linkResolver`, which can be passed in when initializing the plugin.\n- `data.hProperties.href`: `href` value for the rendered `a`. This `href` is computed using `options.hrefTemplate`.\n\nThe `hName` and other `h` fields provide compatibility with [`rehype`](https://github.com/rehypejs/rehype).\n\n### AST to Markdown\n\nTaking the `ast` from the prior example, let's go back to markdown:\n\n```javascript\nimport { fromMarkdown } from \"mdast-util-from-markdown\";\nimport * as wikiLink from \"@braindb/mdast-util-wiki-link\";\n\nlet markdownString = toMarkdown(ast, {\n  extensions: [wikiLink.toMarkdown()],\n}).trim();\nconsole.log(markdownString);\n// [[Wiki Link]]\n```\n\n### Configuration options\n\nBoth `fromMarkdown` and `toMarkdown` accept configuration as an object.\n\nFor example, one may configure `fromMarkdown` like so:\n\n```javascript\nlet ast = fromMarkdown(\"[[Test Page]]\", {\n  extensions: [syntax()],\n  mdastExtensions: [\n    wikiLink.fromMarkdown({\n      linkResolver: (x) => name.replace(/ /g, \"_\").toLowerCase(),\n    }),\n  ], // <--\n});\n```\n\n#### `fromMarkdown`\n\n- `options.linkResolver (pageName: string) -> string`: A function that maps a page name to an array of possible permalinks. These possible permalinks are cross-referenced with `options.permalinks` to determine whether a page exists. If a page doesn't exist, the first element of the array is considered the permalink.\n\n  The default `linkResolver` is:\n\n  ```javascript\n  (name) => name;\n  ```\n\n- `options.linkTemplate ({ slug: string, permalink: string, alias: string | null }) -> HAST`: A function that generates \"HAST\" for link.\n\n  The default `linkTemplate` is:\n\n  ```js\n  function defaultLinkTemplate({ slug, permalink, alias }) {\n    return {\n      hName: \"a\",\n      hProperties: { href: permalink == null ? slug : permalink },\n      hChildren: [{ type: \"text\", value: alias == null ? slug : alias }],\n    };\n  }\n  ```\n\n#### `toMarkdown`\n\n- `options.aliasDivider string`: a string to be used as the divider for aliases. See the section below on [Aliasing pages](#aliasing-pages). Defaults to `\"|\"`.\n\n### Aliasing pages\n\nAliased pages are supported with the following markdown syntax:\n\n```md\n[[Real Page|Page Alias]]\n```\n\nAnd will produce this HTML when rendered:\n\n```html\n<a href=\"Real Page\">Page Alias</a>\n```\n","readmeFilename":"README.md"}