npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@portaljs/remark-wiki-link

v1.2.0

Published

Parse and render wiki-style links in markdown especially Obsidian style links.

Downloads

672

Readme

remark-wiki-link

Parse and render wiki-style links in markdown especially Obsidian style links.

What is this ?

Using obsidian, when we type in wiki link syntax for eg. [[wiki_link]] it would parse them as anchors.

Features supported

  • [x] Support [[Internal link]]
  • [x] Support [[Internal link|With custom text]]
  • [x] Support [[Internal link#heading]]
  • [x] Support [[Internal link#heading|With custom text]]
  • [x] Support ![[Document.pdf]]
  • [x] Support ![[Image.png]]
  • Supported image formats are jpg, jpeg, png, apng, webp, gif, svg, bmp, ico
  • Unsupported image formats will display a raw wiki link string, e.g. [[Image.xyz]].

Future support:

  • [ ] Support ![[Audio.mp3]]
  • [ ] Support ![[Video.mp4]]
  • [ ] Support ![[Embed note]]
  • [ ] Support ![[Embed note#heading]]

Installation

npm install @portaljs/remark-wiki-link

Usage

import unified from "unified";
import markdown from "remark-parse";
import wikiLinkPlugin from "@portaljs/remark-wiki-link";

const processor = unified().use(markdown).use(wikiLinkPlugin);

Configuration options

pathFormat

Type: "raw" | "obisidan-absolute" | "obsidian-short" Default: "raw"

  • "raw": use this option for regular relative or absolute paths (or Obsidian relative paths), e.g. [[../some/folder/file]] or [[[/some/folder/file]]],
  • "obsidian-absolute": use this option for Obsidian absolute paths, i.e. paths with no leading /, e.g. [[some/folder/file]]
  • "obsidian-short": use this option for Obsidian shortened paths, e.g. [[file]] to resolve them to absolute paths. Note that apart from setting this value, you will also need to pass a list of paths to files in your content folder, and pass it as permalinks option. You can generate this list yourself or use our util function getPermalinks. See below for more info.

[!note] Wiki link format in Obsidian can be configured in Settings -> Files & Links -> New link format.

aliasDivider

Type: single character string Default: "|"

Alias divider character used in your wiki links. E.g. [[/some/folder/file|Alias]]

permalinks

Type: Array<string> Default: []

A list of permalinks you want to match your wiki link paths with. Wiki links with matched permalinks will have node.data.exists property set to true. Wiki links with no matching permalinks will also have additional class new set.

wikiLinkResolver

Type: (name: string) => Array<string> Default: (name: string) => name.replace(/\/index$/, "") (simplified; see source code for full version)

A function that will take the wiki link target page (e.g. "/some/folder/file" in [[/some/folder/file#Some Heading|Some Alias]] wiki link) and return an array of pages to which the wiki link can be resolved (one of them will be used, depending on wheather pemalinks are passed, and if match is found).

If permalinks are passed, the resulting array will be matched against these permalinks to find the match. The matching pemalink will be used as node's href (or src for images).

If no matching permalink is found, the first item from the array returned by this function will be used as a node's href (or src for images). So, if you want to write a custom wiki link -> url

newClassName

Type: string Default: "new"

Class name added to nodes created for wiki links for which no matching permalink (passed in permalinks option) was found.

wikiLinkClassName

Type: string Default: "internal"

Class name added to all wiki link nodes.

hrefTemplate

Type: (permalink: string) => string Default: (permalink: string) => permalink

A function that will be used to convert a matched permalink of the wiki link to href (or src for images).

markdownFolder ❌ (deprecated as of version 1.1.0)

A string that points to the content folder, that will be used to resolve Obsidian shortened wiki link path format.

Instead of using this option, use e.g. getPermalinks util function exported from this package to generate a list of permalinks from your content folder, and pass it explicitly as permalinks option.

Generating list of permalinks from content folder with getPermalinks

If you're using shortened path format for your Obsidian wiki links, in order to resolve them correctly to paths they point to, you need to set option.pathFormat: "obsidian-short" but also provide the plugin with a list of permalinks that point to files in your content folder as option.permalinks. You can use your own script to generate this list or use our util function getPermalinks like so:

import unified from "unified";
import markdown from "remark-parse";
import wikiLinkPlugin from "@portaljs/remark-wiki-link";
import { getPermalinks } from "@portaljs/remark-wiki-link";

const permalinks = await getPermalinks("path-to-your-content-folder");

const processor = unified().use(markdown).use(wikiLinkPlugin, {
  pathFormat: "obsidian-short",
  permalinks,
});

Running tests

pnpm nx test remark-wiki-link