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

@digitallinguistics/ling-md

v0.2.3

Published

A JS library to convert linguistics-flavored markdown to HTML.

Downloads

16

Readme

ling-md

A JS library to convert linguistics-flavored markdown to HTML.

This library uses markdown-it for converting markdown, with a few custom extensions specific to the ling-md format (see Notes below for details). It also enables several commonly-used markdown extensions that are also relevant to linguistics (such as footnotes).

After conversion, you'll probably still want to apply additional CSS styles to the HTML. For example, grammatical glosses like ^^fut^^ are converted to abbreviation tags such as <abbr>fut</abbr>, but abbreviation tags are not styled in smallcaps by default.

Usage

Install the library:

npm i @digitallinguistics/ling-md

Create a new parser instance and parse the linguistics-flavored markdown:

import Parser from '@digitallinguistics/ling-md'

const markdown = `The word *perro* in Spanish means ''dog''.`
const parser   = new Parser({ /* options */ })
const html     = parser.parse(markdown)

console.log(html) // <p>The word <i>perro</i> in Spanish means <q>dog</q>.</p>

Features

The library enables the following features by default:

Linguistics

| Feature | Markdown | HTML | | ------------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------ | | grammatical glosses | ^^fut^^ | <abbr class="gl">fut</abbr> | | inline examples | The word *perro* is Spanish. | <p>The word <i>perro</i> is Spanish.</p> | | inline translations | The word *perro* means ''dog''. | <p>The word <i>perro</i> means <q>dog</q>.</p> | | interlinear glosses | ```iglninakupendani-na-ku-pend-a1sg.SUBJ-PRES-2sg.OBJ-love-INDI love you``` | See documentation here. |

General

| Feature | Markdown | HTML | | ---------------------- | ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- | | alerts | > [!note]> Note Text | See documentation here. | | block attributes | # Heading {#intro} | <h1 id=intro>Heading</h1> | | bracketed spans | [/lɪŋˈɡwɪstɪks/]{.phon} | <span class="phon">/lɪŋˈɡwɪstɪks/</span> | | checklists | See documentation here. | | | definition lists | See documentation here. | | | fenced code attributes | ```js {.code-example}console.log('Hello world!')``` | <pre><code class="language-js code-example">console.log('Hello world!')</code></pre> | | footnotes | Here is a footnote reference,[^1] and some more text.\n\n[^1]: Here is the footnote. | See example here. | | header anchors | # Header Title | <h1 id="header-title">Header Title</h1> | | HTML | <b>bold</b> | <b>bold</b> | | inline attributes | *perro*{.example lang=spa} | <i class="example" lang="spa>perro</i> | | inserted text | ++inserted text++ | <ins>inserted text</ins> | | marked text | ==marked text== | <mark>marked text</mark> | | math (LaTeX) | Euler’s identity $e^{i\pi}+1=0$ is a beautiful formula in $\mathbb{R}^2$. | (Outputs an image.) | | smart quotes | "Hello world!" | “Hello world!” | | tables | See documentation here. | | | strikethrough | ~~This was mistaken text.~~ | <s>This was mistaken text.</s> | | subscript | ~subscript~ | <sub>subscript</sub> | | summary + details | See documentation here. | | | superscript | ^superscript^ | <sup>superscript</sup> | | table captions | See documentation here | | | table of contents | [[toc]] | See documentation here. | | typography | -- --- ... 1st 2nd 3rd 4th 1/3 3/4 | – — … 1<sup>st</sup> 2<sup>nd</sup> 3<sup>rd</sup> 4<sup>th</sup> ⅓ ¾ |

Usage Notes

  • Most markdown libraries convert single asterisks (*perro*) to emphasis (<em>perro</em>), but ling-md converts them to idiomatic text (<i>perro</i>). Use **double asterisks** for bold instead. (See "you're using <em> wrong" by Facundo Corradini for more information.)

  • Attributes may be added in a variety of formats. See the attributes-parser library for a complete list. The most common ones are:

    • .className > class="className"
    • #name > id="name"
    • attr=val > attr="val" (data-* attributes also work)
  • There is no markdown shortcut for underlining. Use the <u> tag instead.

  • You can enter interlinear glossed examples in Scription format, using fenced code blocks, like so:

    ```igl
    ninakupenda
    ni-na-ku-pend-a
    1sg.SUBJ-PRES-2sg.OBJ-love-IND
    I love you
    ```

    Note that you can enter multiple examples in a single code block, separated by a blank line.

    You can also pass options to both the scription2dlx and dlx2html libraries by including those options in the YAML header of the interlinear, like so:

    ```igl
    ---
    dlx2html:
      glosses: true
    scription2dlx:
      emphasis: false
    ---
    
    ninakupenda
    ni-na-ku-pend-a
    1sg.SUBJ-PRES-2sg.OBJ-love-IND
    I love you
    ```

API

marked

Provides access to the marked instance for further customization.

parse(md)

Parse a markdown string using the current options and return HTML.

Options

| Option | Type | Default | Description | | --------------- | --------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | dlx2html | Object | See documentation here. | Options to pass to dlx2html (the library that converts interlinear examples to HTML). If options are provided in a YAML header within fenced code blocks, those options override these ones. | | markdown | Object | { html: true, typographer: true} | Options to pass to markdown-it. typographer and html are enabled by default. | | plugins | Object | {} | Options to pass to any of the markdown-it plugins. Each key should be the name of the plugin, and the value is the options to pass to it. Example: { '@mdit/plugin-alert': { /* options */ } } You can see a complete list of the markdown-it plugins that are used in this library in the source code here. | | translations | span\|q | span | Whether to use <span class=tln> or a <q> element for translations. <span>s will wrap the inner text in single quotes. | | scription2dlx | Object | See documentation here. | Options to pass to scription2html (the library that parses interlinear examples). If options are provided in a YAML header within fenced code blocks, those options override these ones. |