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

micromark-extension-wikirefs

v0.0.6-mm

Published

Micromark syntax extension for wikirefs (including [[wikilinks]]).

Downloads

18

Readme

micromark-extension-wikirefs

A WikiBonsai Project NPM package

A micromark syntax extension for wikirefs (including [[wikilinks]]), providing the low-level modules for integrating with the micromark tokenizer and the micromark HTML compiler.

You probably shouldn’t use this package directly, but instead use mdast-util-wikirefs with mdast or remark-wikirefs with remark.

Note that this plugin only parses the input -- it is up to you to assign appropriate linking information and/or index relationships between files.

🕸 Weave a semantic web in your 🎋 WikiBonsai digital garden.

Install

This package is ESM only. Install micromark-extension-wikirefs on npm.

npm install micromark-extension-wikirefs

Use

WikiRefs

To use all wiki constructs, use wikirefs:

import micromark from 'micromark';
import { syntaxWikiRefs, htmlWikiRefs } from 'micromark-extension-wikirefs';

// in order to use wikiembeds, a micromark wrapper function will be required
// see WikiEmbeds below for examples
let content = micromark('[[fname]]', {
  extensions: [syntaxWikiRefs()],
  htmlExtensions: [htmlWikiRefs()],
});

Specific serialization examples below...

WikiAttrs

The serialized result will be the following. To get an abstract syntax tree, use mdast-util-wikirefs instead.

:attrtype::[[fname]]

While data is extracted and stored in data tokens, no HTML is generated at the micromark level. To render directly to html, use mdast-util-wikirefs.

To only use wikiattr constructs:

import micromark from 'micromark';
import { syntaxWikiAttrs, htmlWikiAttrs } from 'micromark-extension-wikirefs';

let content = micromark(':attrtype::[[fname]]\n', {
    extensions: [syntaxWikiAttrs()],
    htmlExtensions: [htmlWikiAttrs()],
});

WikiLinks

The serialized result will be the following. To get an abstract syntax tree, use mdast-util-wikirefs instead.

[[fname]]
<p><a class="wikilink" href="/fname-url" data-href="/fname-url">title</a></p>

To only use wikilink constructs:

import micromark from 'micromark';
import { syntaxWikiLinks, htmlWikiLinks } from 'micromark-extension-wikirefs';

let content = micromark('[[fname]]', {
  extensions: [syntaxWikiLinks()],
  htmlExtensions: [htmlWikiLinks()],
});

WikiEmbeds

The serialized result will be the following. To get an abstract syntax tree, use mdast-util-wikirefs instead.

![[fname]]
![[audio.mp3]]
![[image.png]]
![[video.mp4]]
<!-- markdown embeds -->
<p>
  <div class="embed-wrapper">
    <div class="embed-title">
      <a class="wiki embed doctype__doctype" href="/tests/fixtures/embed-doc" data-href="/tests/fixtures/embed-doc">
        embedded document
      </a>
    </div>
    <div class="embed-link">
      <a href="/tests/fixtures/embed-doc" data-href="/tests/fixtures/embed-doc">
        <i class="link-icon"></i>
      </a>
    </div>
    <div class="embed-content">
      <p>Here is some content.</p>
    </div>
  </div>
</p>
<!-- media embeds (audio, img, video) -->
<!-- audio -->
<p>
  <span class="embed-media" src="audio.mp3" alt="audio.mp3">
    <audio class="embed-audio" controls src="/tests/fixtures/audio.mp3"></audio>
  </span>
</p>
<!-- image -->
<p>
  <span class="embed-media" src="image.png" alt="image.png">
    <img class="embed-image" src="/tests/fixtures/image.png">
  </span>
</p>
<!-- video -->
<p>
  <span class="embed-media" src="video.mp4" alt="video.mp4">
    <video class="embed-audio" controls src="/tests/fixtures/video.mp4"></video>
  </span>
</p>

To only use wikiembed constructs:

import micromark from 'micromark';
import { syntaxWikiEmbeds, htmlWikiEmbeds } from 'micromark-extension-wikirefs';

function wrapMicromark(content) {
  const opts = {
    resolveEmbedContent: (filename: string) => {
      // see [test runner](https://github.com/wikibonsai/remark-wikirefs/blob/main/micromark-extension-wikirefs/test/tests/runner.ts) for full example
      return filename + ' embed content';
    }
  };
  return micromark(content, {
      extensions: [syntaxWikiEmbeds()],
      htmlExtensions: [htmlWikiEmbeds(opts)]
  });
}
let content = wrapMicromark('![[fname]]');

Syntax

For more on syntax specification, see the wikirefs repo.

Options

It is strongly recommended to provide the following options for best linking results:

  • resolveHtmlText
  • resolveHtmlHref
  • resolveEmbedContent

For wikiembeds -- note:

Syntax Options

// defaults
let syntaxOpts = {
  attrs: {
    enable: true,
    render: true,
    title: 'Attributes',
  },
  links: {
    enable: true,
  },
  embeds: {
    enable: true,
    title: 'Embed Content',
    errorContent: 'Error: Content not found for ',
  },
};

HTML Options

// defaults
let htmlOpts = {
    resolveHtmlHref: (fname: string) => {
      const extname: string = wikirefs.isMedia(fname) ? path.extname(fname) : '';
      fname = fname.replace(extname, '');
      return '/' + fname.trim().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '') + extname;
    },
    resolveHtmlText: (fname: string) => fname.replace(/-/g, ' '),
    resolveEmbedContent: (fname: string) => fname + ' embed content',
    baseUrl: '',
    cssNames: {
      // wiki
      wiki: 'wiki',
      invalid: 'invalid',
      // kinds
      attr: 'attr',
      link: 'link',
      type: 'type',
      embed: 'embed',
      reftype: 'reftype__',
      doctype: 'doctype__',
      // attr
      attrbox: 'attrbox',
      attrboxTitle: 'attrbox-title',
      // embed
      embedWrapper: 'embed-wrapper',
      embedTitle: 'embed-title',
      embedLink: 'embed-link',
      embedContent: 'embed-content',
      embedLinkIcon: 'embed-link-icon',
      linkIcon: 'link-icon',
      embedMedia: 'embed-media',
      embedAudio: 'embed-audio',
      embedDoc: 'embed-doc',
      embedImage: 'embed-image',
      embedVideo: 'embed-video',
    } as OptCssNames,
    attrs: {
      enable: true,
      render: true,
      title: 'Attributes',
    } as OptAttr,
    links: {
      enable: true,
    },
    embeds: {
      enable: true,
      title: 'Embed Content',
      errorContent: 'Error: Content not found for ',
    },
  };

Options Descriptions

See remark-wikirefs readme for option descriptions.