{"id":20853930,"url":"https://github.com/landakram/mdast-util-wiki-link","last_synced_at":"2025-06-24T22:31:49.400Z","repository":{"id":48953575,"uuid":"304779702","full_name":"landakram/mdast-util-wiki-link","owner":"landakram","description":"Extensions for mdast to support [[Wiki Links]].","archived":false,"fork":false,"pushed_at":"2024-04-09T13:12:28.000Z","size":607,"stargazers_count":14,"open_issues_count":3,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-12T18:13:45.268Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/landakram.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-17T02:17:13.000Z","updated_at":"2024-12-14T05:23:51.000Z","dependencies_parsed_at":"2024-06-18T18:36:11.771Z","dependency_job_id":null,"html_url":"https://github.com/landakram/mdast-util-wiki-link","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":"0.16666666666666663","last_synced_commit":"8b0fb25c9d7eaab21a7344c307f30004ff87235b"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/landakram/mdast-util-wiki-link","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/landakram%2Fmdast-util-wiki-link","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/landakram%2Fmdast-util-wiki-link/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/landakram%2Fmdast-util-wiki-link/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/landakram%2Fmdast-util-wiki-link/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/landakram","download_url":"https://codeload.github.com/landakram/mdast-util-wiki-link/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/landakram%2Fmdast-util-wiki-link/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261766772,"owners_count":23206687,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T03:23:48.801Z","updated_at":"2025-06-24T22:31:49.376Z","avatar_url":"https://github.com/landakram.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mdast-util-wiki-link\n\n[![npm version](https://badge.fury.io/js/mdast-util-wiki-link.svg)](https://badge.fury.io/js/mdast-util-wiki-link) [![Build Status](https://travis-ci.org/landakram/mdast-util-wiki-link.svg?branch=master)](https://travis-ci.org/landakram/mdast-util-wiki-link)\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[`remark-wiki-link`](https://github.com/landakram/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 'micromark-extension-wiki-link'\nimport * as wikiLink from '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        exists: false,\n        hName: 'a',\n        hProperties: {\n            className: 'internal new',\n            href: '#/page/test_page'\n        },\n        hChildren: [{\n            type: 'text',\n            value: 'Test Page'\n        }]\n    }\n}\n```\n\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.pageResolver`, which can be passed in when initializing the plugin. \n* `data.exists`: Whether the page exists. A page exists if its permalink is found in `options.permalinks`, passed when initializing the plugin.\n* `data.hProperties.className`: Classes that are automatically attached to the `a` when it is rendered as HTML. These are configurable with `options.wikiLinkClassName` and `options.newClassName`. `options.newClassName` is attached when `data.exists` is false.\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 'mdast-util-wiki-link'\n\nlet markdownString = toMarkdown(ast, { extensions: [wikiLink.toMarkdown()] }).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: [wikiLink.fromMarkdown({ permalinks: ['wiki_page'] })] // \u003c--\n})\n```\n\n#### `fromMarkdown`\n\n* `options.permalinks [String]`: An array of permalinks that should be considered existing pages. If a wiki link is parsed and its permalink matches one of these permalinks, `node.data.exists` will be true.\n* `options.pageResolver (pageName: String) -\u003e [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 `pageResolver` is:\n\n```javascript\n(name) =\u003e [name.replace(/ /g, '_').toLowerCase()]\n```\n\n* `options.hrefTemplate (permalink: String) -\u003e String`: A function that maps a permalink to some path. This path is used as the `href` for the rendered `a`.\n\n  The default `hrefTemplate` is:\n  \n```javascript\n(permalink) =\u003e `#/page/${permalink}`\n```\n\n* `options.wikiLinkClassName [String]`: a class name that is attached to any rendered wiki links. Defaults to `\"internal\"`.\n* `options.newClassName [String]`: a class name that is attached to any rendered wiki links that do not exist. Defaults to `\"new\"`.\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```\n[[Real Page:Page Alias]]\n```\n\nAnd will produce this HTML when rendered:\n\n```\n\u003ca class=\"internal new\" href=\"#/page/real_page\"\u003ePage Alias\u003c/a\u003e\n```\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flandakram%2Fmdast-util-wiki-link","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flandakram%2Fmdast-util-wiki-link","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flandakram%2Fmdast-util-wiki-link/lists"}