Linguistic plugin for markdown-it parser, transcribing /phonemic/ and [phonetic] notation to Unicode IPA
npm install markdown-it-phon --save
bower install markdown-it-phon --save
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>
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 ofx-sampa
- possible values:
sampa | x-sampa | z-sampa | kirshenbaum | apie | worldbet | arpabet | timit | teuthonista | napa | rfe | epa | upa | iapa | extipa | voqs | ipa
- possible values:
- to (String) -- target notation system, defaults to
ipa
- possible values:
ipa | same
- possible values:
- phonemic (Array) -- open and close bracket for output
- default:
[ "/", "/" ]
- default:
- phonetic (Array) -- open and close bracket for output
- default:
[ "[", "]" ]
- 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);
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);
};