{"id":29946139,"url":"https://github.com/nonplain/nonplain-md-link.js","last_synced_at":"2026-04-16T17:41:40.807Z","repository":{"id":57155901,"uuid":"346449863","full_name":"nonplain/nonplain-md-link.js","owner":"nonplain","description":"Tools for markdown links in nonplain files","archived":false,"fork":false,"pushed_at":"2021-03-14T03:35:05.000Z","size":305,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-23T20:19:07.840Z","etag":null,"topics":["links","markdown","nonplain","plaintext"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nonplain-md-link","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nonplain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-10T18:13:56.000Z","updated_at":"2021-03-14T03:35:07.000Z","dependencies_parsed_at":"2022-08-30T05:32:23.076Z","dependency_job_id":null,"html_url":"https://github.com/nonplain/nonplain-md-link.js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nonplain/nonplain-md-link.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nonplain%2Fnonplain-md-link.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nonplain%2Fnonplain-md-link.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nonplain%2Fnonplain-md-link.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nonplain%2Fnonplain-md-link.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nonplain","download_url":"https://codeload.github.com/nonplain/nonplain-md-link.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nonplain%2Fnonplain-md-link.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267275033,"owners_count":24062839,"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","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["links","markdown","nonplain","plaintext"],"created_at":"2025-08-03T05:13:13.297Z","updated_at":"2026-04-16T17:41:40.761Z","avatar_url":"https://github.com/nonplain.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nonplain-md-link\n\nTools for markdown links in [nonplain files](https://github.com/nonplain/nonplain.js#what-a-nonplain-file-is).\n\n## What this library does\n\nMarkdown files often contain markdown-style links, which look like this:\n\n```\n[link inner text](/path/to/some/file/or/site)\n```\n\nThey can also sometimes contain wiki-style links when used for notetaking. Wiki-style links look like this:\n\n```\n[[/path/to/some/file/or/site]]\n```\n\nThe concept: provide a tool for gathering and working with markdown and wiki-style links within [nonplain](https://github.com/nonplain/nonplain.js) files.\n\nOnce these links are gathered, they can be analyzed and selectively edited to accomplish various goals such as:\n\n- converting links to HTML\n- re-basing links to work on your personal website\n- listing all forward links in a file\n- calculating backlinks for a file\n\n...and more.\n\n## API\n\n### Initialization\n\nTo parse a link, pass it as a string to the `Link` class upon initialization:\n\n```js\nconst Link = require(\"nonplain-md-link\").default;\n\nconst markdownLink = new Link('[my markdown link](/path/to/file.md)');\nconst wikiLink = new Link('[[/path/to/file.md]]');\n\nconsole.log(markdownLink);\n\n// Output:\n//\n// {\n//   \"initialStyle\": \"markdown\",\n//   \"innerText\": \"my markdown link\",\n//   \"path\": \"/path/to/file.md\",\n// }\n\nconsole.log(wikiLink);\n\n// Output:\n//\n// {\n//   \"initialStyle\": \"wiki\",\n//   \"innerText\": \"/path/to/file.md\",\n//   \"path\": \"/path/to/file.md\",\n// }\n```\n\nOnce a link is parsed, its contents can be used to construct new links.\n\n### Link.collectAllLinksFromContent()\n\nReturns `Link` instances for all markdown and wiki-style links within a given string.\n\n```js\nconst Link = require(\"nonplain-md-link\").default;\nconst { File } = require(\"nonplain\");\n\nconst file = new File().load('/path/to/file.md');\n\nconst linksInFileBody = Link.collectAllLinksFromContent(file.body);\n\nconsole.log(linksInFileBody);\n\n// Output:\n//\n// [\n//   {\n//     \"initialStyle\": \"markdown\",\n//     \"innerText\": \"as discussed in class\",\n//     \"path\": \"../notes/CS231n notes.md\"\n//   },\n//   {\n//     \"initialStyle\": \"markdown\",\n//     \"innerText\": \"descending the loss gradient\",\n//     \"path\": \"https://en.wikipedia.org/wiki/Gradient_descent\"\n//   },\n//   {\n//     \"initialStyle\": \"wiki\",\n//     \"innerText\": \"How to backpropagate\",\n//     \"path\": \"How to backpropagate\"\n//   }\n// ]\n```\n\n### Link.detectLinkStyle()\n\nReturns the link style (`'markdown'` or `'wiki'`) of a provided string.\n\n```js\nconst markdownLink = new Link('[my markdown link](/path/to/file.md)');\nconst wikiLink = new Link('[[/path/to/file.md]]');\n\nconsole.log(Link.detectLinkStyle(markdownLink));\n\n// Output:\n//\n// 'markdown'\n\nconsole.log(Link.detectLinkStyle(markdownLink));\n\n// Output:\n//\n// 'wiki'\n```\n\n### Link.prototype.composeHTML()\n\n```js\nlink.composeHTML([attributesStr])\n```\n\nReturns an HTML string based on the current `Link` instance. The optional argument `attributesStr` inserts custom attributes after the `href` attribute.\n\n```js\nconst link = new Link('[my markdown link](/path/to/file.md)');\n\nconsole.log(link.composeHTML());\n\n// Output:\n//\n// '\u003ca href=\"/path/to/file.md\"\u003emy markdown link\u003c/a\u003e'\n\nconst externalLinkAttributes = 'target=\"_blank\" rel=\"noreferrer\"';\nconsole.log(link.composeHTML(externalLinkAttributes));\n\n// Output:\n//\n// '\u003ca href=\"/path/to/file.md\" target=\"_blank\" rel=\"noreferrer\"\u003emy markdown link\u003c/a\u003e'\n```\n\n### Link.prototype.composeMarkdown()\n\n```js\nlink.composeMarkdown()\n```\n\nReturns a markdown link based on the current `Link` instance.\n\n```js\nconst link = new Link('[my markdown link](/path/to/file.md)');\n\nconsole.log(link.composeMarkdown());\n\n// Output:\n//\n// '[my markdown link](/path/to/file.md)'\n```\n\n### Link.prototype.composeWiki()\n\n```js\nlink.composeWiki()\n```\n\nReturns a wiki-style link based on the current `Link` instance.\n\n```js\nconst link = new Link('[my markdown link](/path/to/file.md)');\n\nconsole.log(link.composeWiki());\n\n// Output:\n//\n// '[[/path/to/file.md]]'\n```\n\n## Regex\n\nThis library exports an object containing useful [regex patterns for extracting markdown and wiki-style links](https://github.com/nonplain/nonplain-md-link.js/blob/master/src/utils/regex/index.ts) from string content. To use these patterns, import `regex` from this package:\n\n```js\nconst { regex } = require(\"nonplain-md-link\");\n```\n\n## Related work\n\n- Core nonplain library for JS: [nonplain.js](https://github.com/nonplain/nonplain.js)\n- Generate backlinks for nonplain files: [nonplain-md-backlinker.js](nonplain-md-backlinker.js)\n\n## Contributing\n\nThese tools are in progress. If your use-case requires specific functionality from this library, please contact me and we'll see what we can do together. Thanks!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnonplain%2Fnonplain-md-link.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnonplain%2Fnonplain-md-link.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnonplain%2Fnonplain-md-link.js/lists"}