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

remark-interactive-words

v1.0.0

Published

A Remark plugin to transform words into interactive, clickable links with a #slug. It's built to facilitate Aided Reading (AR) on digital devices. You can easily integrate it with your existing remark plugins to achieve a word-wise interactivity and funct

Downloads

5

Readme

remark-interactive-words

remark-interactive-words is a plugin for remark. It's built to facilitate Aided Reading (AR) on digital devices.

Intro

Designed to transform markdown by replacing words with interactive, clickable links with a #slug for programmatic use, remark-interactive-words is developed by Russ Fugal for SARAs Books LLC to support Aided Reading (AR) automation. This plugin integrates seamlessly with the remark ecosystem.

remark

Contents

What is this?

unified is a project that transforms content with abstract syntax trees (ASTs). remark adds support for markdown to unified. mdast is a specification for representing markdown in a syntax tree. It implements unist. It can represent several flavors of markdown, such as CommonMark and GitHub Flavored Markdown.

remark-interactive-words leverages mdast, inspecting and modifying the AST to create its interactive functionality. This plugin works with markdown as structured data.

When should I use this?

remark-interactive-words is a plugin for remark. It's built to facilitate Aided Reading (AR) on digital devices. You can easily integrate it with your existing remark plugins to achieve word-wise interactivity and functionality in your markdown documents.

API

To install the remark-interactive-words plugin, run the following command in your terminal:

npm install remark-interactive-words

The default export is remarkInteractiveWords.

remark().use(remarkInteractiveWords, options)

Generate markdown with linked words. Looks for all Text Nodes and transforms all but descendants of excludingNodes.

const excludingNodes = [
    'code',
    'inlineCode',
    'link',
    'linkReference',
    'html'
]

slug

remarkInteractiveWords matches words with wordRegex and transforms them to transformTo Nodes with a #slug for programatic use.

const wordRegex = /([a-z]+['’][a-z]+)|[a-z]{2,}/gi;

function getWordSlug(word: string): string {
    return word.toLowerCase().replace("’", "'");
}

interface InteractiveWordsOptions

Via the options object, you can customize the behavior of remark-interactive-words. Specific words can be excluded from transformation by passing an array of words to exceptions. You can also customize the transformation by passing a helper function. The helper function is called with a HelperInput object and should return an array of HelperResult objects.

interface InteractiveWordsOptions {
  transformTo: 'link' | 'linkReference'
  exceptions?: string[] // array of words to exclude from transformation
  helper?: (input: HelperInput) => HelperResult[]
}

interface HelperInput {
    input: string;
    exceptions?: string[];
}

interface HelperResult {
    text: string;
    transform: boolean;
    wordSlug?: string;
}

Examples

Example: 'This is a test.'

After installation, you can require and use remark-interactive-words as follows:

import { remark } from 'remark';
import remarkInteractiveWords from 'remark-interactive-words';
import { InteractiveWordsOptions } from 'remark-interactive-words';

const options: InteractiveWordsOptions = {
    transformTo: 'link'
};

const input = 'This is a test.';
const expectedOutput = '[This](#this) [is](#is) a [test](#test).';

const processor = remark().use(remarkInteractiveWords);
const output = processor.processSync(input);

expect(String(output)).toEqual(expectedOutput);

Syntax

Syntax tree

Types

Contribute

We welcome contributions to remark-interactive-words. Please see the contributing guidelines for more information.

Sponsor

remark-interactive-words is an open-source project that is supported by the community. If you find it useful, please consider supporting us via GitHub Sponsors.

License

MIT © Russ Fugal