UNPKG

1.39 kBMarkdownView Raw
1md-attr-parser
2===========
3
4A node plugin to parse attributes (custom HTML attributes).
5
6
7## Syntax
8
9The syntax is common :
10
11```markdown
12{#thisIsAnId .thisIsAClass thisKey=thisValue}
13
14{thatKey="value" thisKey='thatValue'}
15```
16
17## Usage
18
19```js
20const parseAttr = require('md-attr-parser');
21
22
23parseAttr('{ width=500px editable=true }');
24
25parseAttr('height=500px');
26```
27
28The output is an object of the form :
29```js
30{
31 prop: { // Keep the key-value attribute
32 class: undefined, // A list of class
33 id: undefined, // The uniq id
34 },
35 eaten: '', // Every characters parsed
36}
37```
38
39For example this code will output :
40```js
41parseAttr('{ width=500px editable=true #unicorn .dangerous .cute }');
42```
43
44```js
45{
46 prop: {
47 class: ['dangerous', 'cute'],
48 id: 'unicorn',
49 width: '500px',
50 editable: 'true',
51 },
52 eaten: '{ width=500px editable=true #unicorn .dangerous .cute }',
53}
54```
55
56### Advanced usage
57
58The parsing can start at a positive offset.
59
60```js
61parseAttr('SYNTAX{ width=500px editable=true }', len('SYNTAX'));
62```
63
64A configuration can also be specified, actualy, there is only one configuration option.
65The default value of key without value.
66
67```js
68parseAttr('{ width=500px editable }', 0, {defaultValue: true});
69// or
70parseAttr('{ width=500px editable }', 0, {defaultValue: key => 'NO_VALUE_FOR_'+key.toUpperCase()});
71```
72
73## Licence
74
75MIT