Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
nonplain-md-link
Advanced tools
Tools for markdown links in nonplain files.
Markdown files often contain markdown-style links, which look like this:
[link inner text](/path/to/some/file/or/site)
They can also sometimes contain wiki-style links when used for notetaking. Wiki-style links look like this:
[[/path/to/some/file/or/site]]
The concept: provide a tool for gathering and working with markdown and wiki-style links within nonplain files.
Once these links are gathered, they can be analyzed and selectively edited to accomplish various goals such as:
...and more.
To parse a link, pass it as a string to the Link
class upon initialization:
const Link = require("nonplain-md-link").default;
const markdownLink = new Link('[my markdown link](/path/to/file.md)');
const wikiLink = new Link('[[/path/to/file.md]]');
console.log(markdownLink);
// Output:
//
// {
// "initialStyle": "markdown",
// "innerText": "my markdown link",
// "path": "/path/to/file.md",
// }
console.log(wikiLink);
// Output:
//
// {
// "initialStyle": "wiki",
// "innerText": "/path/to/file.md",
// "path": "/path/to/file.md",
// }
Once a link is parsed, its contents can be used to construct new links.
Returns Link
instances for all markdown and wiki-style links within a given string.
const Link = require("nonplain-md-link").default;
const { File } = require("nonplain");
const file = new File().load('/path/to/file.md');
const linksInFileBody = Link.collectAllLinksFromContent(file.body);
console.log(linksInFileBody);
// Output:
//
// [
// {
// "initialStyle": "markdown",
// "innerText": "as discussed in class",
// "path": "../notes/CS231n notes.md"
// },
// {
// "initialStyle": "markdown",
// "innerText": "descending the loss gradient",
// "path": "https://en.wikipedia.org/wiki/Gradient_descent"
// },
// {
// "initialStyle": "wiki",
// "innerText": "How to backpropagate",
// "path": "How to backpropagate"
// }
// ]
Returns the link style ('markdown'
or 'wiki'
) of a provided string.
const markdownLink = new Link('[my markdown link](/path/to/file.md)');
const wikiLink = new Link('[[/path/to/file.md]]');
console.log(Link.detectLinkStyle(markdownLink));
// Output:
//
// 'markdown'
console.log(Link.detectLinkStyle(markdownLink));
// Output:
//
// 'wiki'
link.composeHTML([attributesStr])
Returns an HTML string based on the current Link
instance. The optional argument attributesStr
inserts custom attributes after the href
attribute.
const link = new Link('[my markdown link](/path/to/file.md)');
console.log(link.composeHTML());
// Output:
//
// '<a href="/path/to/file.md">my markdown link</a>'
const externalLinkAttributes = 'target="_blank" rel="noreferrer"';
console.log(link.composeHTML(externalLinkAttributes));
// Output:
//
// '<a href="/path/to/file.md" target="_blank" rel="noreferrer">my markdown link</a>'
link.composeMarkdown()
Returns a markdown link based on the current Link
instance.
const link = new Link('[my markdown link](/path/to/file.md)');
console.log(link.composeMarkdown());
// Output:
//
// '[my markdown link](/path/to/file.md)'
link.composeWiki()
Returns a wiki-style link based on the current Link
instance.
const link = new Link('[my markdown link](/path/to/file.md)');
console.log(link.composeWiki());
// Output:
//
// '[[/path/to/file.md]]'
This library exports an object containing useful regex patterns for extracting markdown and wiki-style links from string content. To use these patterns, import regex
from this package:
const { regex } = require("nonplain-md-link");
These 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!
FAQs
Tools for markdown links in nonplain files
The npm package nonplain-md-link receives a total of 4 weekly downloads. As such, nonplain-md-link popularity was classified as not popular.
We found that nonplain-md-link demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.