/markdown-it-phon

Linguistic extension for markdown-it parser transcribing /phonemic/ and [phonetic] notation to Unicode IPA

MIT LicenseMIT

markdown-it-phon

Build Status NPM version Coverage Status

Linguistic plugin for markdown-it parser, transcribing /phonemic/ and [phonetic] notation to Unicode IPA

Install

node.js

npm install markdown-it-phon --save

Browser

bower install markdown-it-phon --save

Use

foo //bar// /[baz]/ /quuz/ [lorem] [/ipsum/]

is turned (with default settings) into

<p>foo <span class="phonemic ipa" lang="unk">/bar/</span> <span class="phonetic ipa" lang="unk">[baz]</span> <span class="ipa" lang="unk">quuz</span> <span class="ipa" lang="unk">[lorem]</span> <span class="ipa" lang="unk">[ipsum]</span></p>

Init

var md = require('markdown-it')();
var phon = require('markdown-it-phon');

md.use(phon [, options]);

Options are not mandatory:

  • lang (String) -- a BCP47 language code, defaults to unk for unknown
  • from (String) -- source notation system, defaults to z-sampa which is a superset of x-sampa
    • possible values: sampa | x-sampa | z-sampa | kirshenbaum | apie | worldbet | arpabet | timit | teuthonista | napa | rfe | epa | upa | iapa | extipa | voqs | ipa
  • to (String) -- target notation system, defaults to ipa
    • possible values: ipa | same
  • phonemic (Array) -- open and close bracket for output
    • default: [ "/", "/" ]
  • phonetic (Array) -- open and close bracket for output
    • default: [ "[", "]" ]
  • start (String) -- defaults to /
  • end (String) -- defaults to /

Differences in browser. If you load the script directly into the page without using a package system, the module will add itself globally with the name markdownitPhon. Init code will look a bit different in this case:

var md = window.markdownit().use(window.markdownitPhon);

change output

By default, IPA is rendered as appropriate unicode chars, but you can change the renderer function as you wish.

Render as i blocks:

// ...
// initialize

md.renderer.rules.phon = function(token, idx) {
  return '<i class="ipa">' + token[idx].markup + '</i>';
};

Or use a custom transliterator:

// ...
// initialize

var translit = require('transliteration')

md.renderer.rules.phon = function(token, idx) {
  return translit.slugify(token[idx].content);
};

License

MIT