Giter VIP home page Giter VIP logo

md-to-bemjson's Introduction

md-to-bemjson

Converts markdown to bemjson.

NPM Status Travis Status Coverage Status Dependency Status Greenkeeper badge

Requirements

Install

$ npm install md-to-bemjson

Usage

const toBemjson = require('md-to-bemjson').convertSync;
const bjson = toBemjson('# Hello world');

console.log(JSON.stringify(bjson, null, 4));

Yields:

{
    "block": "md-root",
    "content": {
        "block": "heading",
        "content": "Hello world",
        "level": 1,
        "mods": {
            "level": 1
        }
    }
}

Markdown converter to bemjson

Module use remark with several plugins and custom compiler to convert markdown to bemjson. Plugins divided into two groups: necessary(you can't disable this plugins) and optional.

Necessary plugins:

Optional plugins:

Compiler

API

constructor([options])

Options

Parameter Type Description
github Object, boolean Enables github support with remark plugin remark-github. Default false.
exportType enum remark-bemjson option. Exports to certain type with .stringify. Supported exports.
exportName string remark-bemjson option. Used with exportType=(modules, umd, YModules) stringify bemjson with exported given name.
augment Function, Object Options for augmentation resulting bemjson by every node. As function accepts bemNode and must return it.
plugins Array Options for additional plugins to be included. Plugin format: { plugin: Function, options: Object }

Options.augment

Parameter Type Description
prefix string Add prefix to all blocks. Important: for root replace original prefix.
scope string Replace root block with scope. And replace all blocks with elems.
map Object Replace block names with provided in map. Available blocks.
html Object Options for converting html to bemjson with html2bemjson.

Important: Augmentation flow is serial. Order: map, prefix, scope. Important: Other augmentations does not affect html.

convert(markdown) => Promise

Parameter Type Description
markdown string Markdown text

Asynchronously converts markdown to bemjson.

const Converter = require('md-to-bemjson');
const md2Bemjson = new Converter();

md2Bemjson.convert('# Hello world').then(bjson => console.log(JSON.stringify(bjson, null, 4)))

Yields:

{
    "block": "md-root",
    "content": {
        "block": "heading",
        "content": "Hello world",
        "level": 1,
        "mods": {
            "level": 1
        }
    }
}

convertSync(markdown) => Bemjson

Parameter Type Description
markdown string Markdown text

Synchronously converts markdown to bemjson.

const Converter = require('md-to-bemjson');
const md2Bemjson = new Converter();

console.log(JSON.stringify(md2Bemjson.convertSync('# Hello world'), null, 4));

Yields:

{
    "block": "md-root",
    "content": {
        "block": "heading",
        "content": "Hello world",
        "level": 1,
        "mods": {
            "level": 1
        }
    }
}

stringify(markdown [, options]) => Promise

Parameter Type Description
markdown string Markdown text
options Object Options prefixed with export*. Important: Creates new processor. For better performance set options via constructor.

Asynchronously converts and stringify markdown to bemjson module with exports.

const Converter = require('md-to-bemjson');
const md2Bemjson = new Converter();

md2Bemjson.stringify('# Hello world').then(content => console.log(content))

Yields:

module.exports = {
    block: 'md-root',
    content: {
        block: 'heading',
        content: 'Hello world',
        "level": 1,
        mods: {
            'level': 1
        }
    }
};

stringifySync(markdown [, options]) => String

Parameter Type Description
markdown string Markdown text
options Object Options prefixed with export*. Important: Creates new processor. For better performance set options via constructor.

Synchronously converts and stringify markdown to bemjson module with exports.

const Converter = require('md-to-bemjson');
const md2Bemjson = new Converter();

console.log(md2Bemjson.stringifySync('# Hello world'));

Yields:

module.exports = {
    block: 'md-root',
    content: {
        block: 'heading',
        content: 'Hello world',
        level: 1,
        mods: {
            'level': 1
        }
    }
};

static convert(markdown [, options]) => Promise

Parameter Type Description
markdown string Markdown text
options Object plugin options

Asynchronously converts markdown to bemjson.

const toBemjson = require('md-to-bemjson').convert;

toBemjson('# Hello world').then(bjson => console.log(JSON.stringify(bjson, null, 4)))

Yields:

{
   "block": "md-root",
   "content": {
       "block": "heading",
       "content": "Hello world",
       "level": 1,
       "mods": {
           "level": 1
       }
   }
}

static convertSync(markdown [, options]) => Bemjson

Parameter Type Description
markdown string Markdown text
options Object plugin options

Synchronously converts markdown to bemjson.

const toBemjson = require('md-to-bemjson').convertSync;

console.log(JSON.stringify(toBemjson('# Hello world'), null, 4));

Yields:

{
    "block": "md-root",
    "content": {
        "block": "heading",
        "content": "Hello world",
        "level": 1,
        "mods": {
            "level": 1
        }
    }
}

static stringify(markdown [, options]) => Promise

Parameter Type Description
markdown string Markdown text
options Object plugin options

Asynchronously converts and stringify markdown to bemjson module with exports.

const toBemjsonString = require('md-to-bemjson').stringify;

toBemjsonString('# Hello world').then(bjson => console.log(JSON.stringify(bjson, null, 4)));

Yields:

module.exports = {
    block: 'md-root',
    content: {
        block: 'heading',
        content: 'Hello world',
        level: 1,
        mods: {
            level: 1
        }
    }
};

static stringifySync(markdown [, options]) => String

Parameter Type Description
markdown string Markdown text
options Object plugin options

Synchronously converts and stringify markdown to bemjson module with exports.

const toBemjsonString = require('md-to-bemjson').stringifySync;

console.log(toBemjsonString('# Hello world'));

Yields:

module.exports = {
    block: 'md-root',
    content: {
        block: 'heading',
        content: 'Hello world',
        level: 1,
        mods: {
            'level': 1
        }
    }
};

License

Code and documentation copyright 2017 YANDEX LLC. Code released under the Mozilla Public License 2.0.

md-to-bemjson's People

Contributors

birhoff avatar greenkeeper[bot] avatar qfox avatar yeti-or avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

plotnikovn

md-to-bemjson's Issues

An in-range update of @types/sinon is breaking the build 🚨

The devDependency @types/sinon was updated from 5.0.2 to 5.0.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Html inside fields should be parsed correctly

For now we have chunks:

<a href="#buttontype">`type`</a>

β†’

[
  { block: 'html', content: '<a href="#buttontype">' },
  { block: 'inline-code', content: 'type' },
  { block: 'html', content: '</a>' }
]

Expected:

[
  {
    tag: 'a',
    attrs: { href: '#buttontype' },
    content: [
      { block: 'inline-code', content: 'type' }
    ]
]

An in-range update of bluebird is breaking the build 🚨

The dependency bluebird was updated from 3.5.3 to 3.5.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

bluebird is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v3.5.4
  • Proper version check supporting VSCode(#1576)
Commits

The new version differs by 6 commits.

  • e0222e3 Release v3.5.4
  • 4b9fa33 missing --expose-gc flag (#1586)
  • 63b15da docs: improve and compare Promise.each and Promise.mapSeries (#1565)
  • 9dcefe2 .md syntax fix for coming-from-other-languages.md (#1584)
  • b97c0d2 added proper version check supporting VSCode (#1576)
  • 499cf8e Update jsdelivr url in docs (#1571)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of lerna is breaking the build 🚨

Version 3.3.1 of lerna was just published.

Branch Build failing 🚨
Dependency lerna
Current Version 3.3.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

lerna is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes v3.3.1

Bug Fixes

  • create: Upgrade whatwg-url to ^7.0.0 (00842d6)
  • import: Handle filepaths with spaces more robustly (#1655) (b084293)
  • prompt: Upgrade inquirer to ^6.2.0 (ebb7ee4)
  • publish: Tell yarn to stop creating git tags (2a6f0a4), closes #1662
  • run-lifecycle: Remove repetitive error logging (b8915e7)
Commits

The new version differs by 13 commits.

  • 5da1319 chore(release): publish v3.3.1
  • 367bf4e test(integration): Avoid inexplicable snapshot comparison errors on Windows
  • 5880788 test(helpers): Replace normalize-test-root with augmented placeholder serialization
  • ed16536 test(helpers): Make serialize-tempdir placeholder consistent with normalize-test-root
  • 00842d6 fix(create): Upgrade whatwg-url to ^7.0.0
  • ebb7ee4 fix(prompt): Upgrade inquirer to ^6.2.0
  • b8d11b8 chore(deps): Update eslint + jest
  • 7bd3179 chore: flailing around trying avoid 'no visual difference' snapshot garbage on Windows
  • b8915e7 fix(run-lifecycle): Remove repetitive error logging
  • a379266 chore(helpers): Normalize newlines to coddle windows
  • 2a6f0a4 fix(publish): Tell yarn to stop creating git tags
  • ac0baa7 test(integration): avoid quoting arguments to coddle windows
  • b084293 fix(import): Handle filepaths with spaces more robustly (#1655)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of lodash is breaking the build 🚨

The dependency lodash was updated from 4.17.10 to 4.17.11.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

lodash is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Tables should be parsed as defined here

| Col1 | Col2 | Col3 | Col4 |
| ---- | ---- | ---- | ---- |
| field1 | field2 | f3 | f4 |
| g1 | g2 | g3 | g4 |
| ---- | ---- | ---- | ---- |
| l1 | l2 |

β†’

{
  block: 'table',
  head: ['Col1', 'Col2', 'Col3', 'Col4'],
  body: [
    ['field1', 'field2', 'f3', 'f4'],
    ['g1', 'g2', 'g3', 'g4'],
    ['----', '----', '----', '----'],
    ['l1', 'l2']
  ]
}

line number/position in output?

I'm experimenting with this project to compile markdown as part of a documentation-driven development project I'm working on.

Is it possible (easy?) to get position information in the output of convert?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.