Skip to content

wavesheep/markdown-it-plain-text

Repository files navigation

markdown-it-plain-text

GitHub GitHub Workflow Status codecov GitHub file size in bytes npm

plain text extractor for markdown-it

Install

nodejs

npm install markdown-it-plain-text

browser (CDN)

uncompressed

https://cdn.jsdelivr.net/gh/wavesheep/markdown-it-plain-text@0.3.0/dist/markdown-it-plain-text.js

compressed

https://cdn.jsdelivr.net/gh/wavesheep/markdown-it-plain-text@0.3.0/dist/markdown-it-plain-text.min.js

Usage examples

Node.js

const MarkdownIt = require('markdown-it');
const plainText = require('markdown-it-plain-text');

const md = new MarkdownIt();
md.use(plainText);

md.render('your markdown content')

// Here are plain text result
md.plainText

Browser

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

const md = window.markdownit().use(window.markdownItPlainTextPlugin);

Typescript

If you load the script in ts, you will get the ts(2339) error. You can fix it with

(md as any).plainText

or

// @ts-ignore
md.plainText

Generation rule

  1. extract text, fence, html_block, code_block,code_inline, html_inline, emoji content directly
  2. add space at closing tag to prevent words from sticking together
  3. remove redundant white spaces from result

LICENSE

MIT