md-attr-parser
A parser for markdown's attributes
Last updated a year ago by ache .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install md-attr-parser 
SYNC missed versions from official npm registry.

md-attr-parser

A node plugin to parse attributes (custom HTML attributes).

Syntax

The syntax is common :

{#thisIsAnId .thisIsAClass thisKey=thisValue}

{thatKey="value" thisKey='thatValue'}

Usage

const parseAttr = require('md-attr-parser');


parseAttr('{ width=500px editable=true }');

parseAttr('height=500px');

The output is an object of the form :

{
  prop: {               // Keep the key-value attribute
    class: undefined,   // A list of class
    id: undefined,      // The uniq id
  },
  eaten: '',            // Every characters parsed
}

For example this code will output :

parseAttr('{ width=500px editable=true #unicorn .dangerous .cute }');
{
  prop: {
    class: ['dangerous', 'cute'],
    id: 'unicorn',
    width: '500px',
    editable: 'true',
  },
  eaten: '{ width=500px editable=true #unicorn .dangerous .cute }',
}

Advanced usage

The parsing can start at a positive offset.

parseAttr('SYNTAX{ width=500px editable=true }', len('SYNTAX'));

A configuration can also be specified, actualy, there is only one configuration option. The default value of key without value.

parseAttr('{ width=500px editable }', 0, {defaultValue: true});
// or
parseAttr('{ width=500px editable }', 0, {defaultValue: key => 'NO_VALUE_FOR_'+key.toUpperCase()});

Licence

MIT

Current Tags

  • 1.3.0                                ...           latest (a year ago)

10 Versions

  • 1.3.0                                ...           a year ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.6                                ...           2 years ago
  • 1.1.5                                ...           3 years ago
  • 1.1.4                                ...           3 years ago
  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 36
Last Day 0
Last Week 10
Last Month 86
Dependencies (0)
None
Dev Dependencies (8)

Copyright 2014 - 2016 © taobao.org |