项目作者: greybax

项目描述 :
Helper methods for remark
高级语言: JavaScript
项目地址: git://github.com/greybax/remark-helpers.git
创建时间: 2016-07-18T20:09:18Z
项目社区:https://github.com/greybax/remark-helpers

开源协议:

下载


remark-helpers

NPM version
Build Status
Coveralls Status
Dependency Status
DevDependency Status

Basically, with remark-helpers you can find desire elements in markdown document
and process them in html or plaintext format.

Bunch of helpers for working with remark.

Very important to notice, that this package is very simple and doesn’t contain
any smart and/or complicated logic, that’s why it’s tightly coupled with
remark API for AST tree (MDAST). Check it out first.

Install

  1. npm install --save remark-helpers

Usage

  1. var md = require('remark-helpers');
  2. md.ast('# title'); // mdast format see more https://github.com/wooorm/mdast
  3. md.html(`*italic*`); // <p><em>italic</em></p>
  4. md.text('**`plaintext`**'); // plaintext
  5. md.md(some_mdast_tree); // markdown text

Look into tests for more examples.

API

html(input)

Return html.

input

Type: string / AST

text(input)

Return plain text.

input

Type: string / AST

ast(input)

Return AST tree for current text.

input

Type: string

md(input)

Return markdown for current input text.

input

Type: string / AST

Bunch of shortcut helpers. Based on MDAST

  1. const isType = (node, type) => node.type === type;
  2. const isDepth = (node, depth) => node.depth === depth;
  3. const hasChildren = (node) => node.children ? true : false;
  4. const isRoot = node => isType(node, "root");
  5. const isParagraph = node => isType(node, "paragraph");
  6. const isBlockquote = node => isType(node, 'blockquote');
  7. const isHeading = node => isType(node, 'heading');
  8. const isCode = node => isType(node, 'code');
  9. const isInlineCode = node => isType(node, 'inlineCode');
  10. const isYaml = node => isType(node, 'yaml');
  11. const isHtml = node => isType(node, 'html');
  12. const isList = node => isType(node, 'list');
  13. const isListItem = node => isType(node, 'listItem');
  14. const isTable = node => isType(node, 'table');
  15. const isTableRow = node => isType(node, 'tableRow');
  16. const isTableCell = node => isType(node, 'tableCell');
  17. const isThematicBreak = node => isType(node, 'thematicBreak');
  18. const isBreak = node => isType(node, 'break');
  19. const isEmphasis = node => isType(node, 'emphasis');
  20. const isStrong = node => isType(node, 'strong');
  21. const isDelete = node => isType(node, 'delete');
  22. const isLink = node => isType(node, 'link');
  23. const isImage = node => isType(node, 'image');
  24. const isFootnote = node => isType(node, 'footnote');
  25. const isLinkReference = node => isType(node, 'linkReference');
  26. const isImageReference = node => isType(node, 'imageReference');
  27. const isFootnoteReference = node => isType(node, 'footnoteReference');
  28. const isDefinition = node => isType(node, 'definition');
  29. const isFootnoteDefinition = node => isType(node, 'footnoteDefinition');
  30. const isText = node => isType(node, 'Text');

License

MIT © Aleksandr Filatov