Skip to content

Commit c6c1336

Browse files
committed
Add support for ignoring from attributes
1 parent 321aa1e commit c6c1336

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

lib/one.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ var own = {}.hasOwnProperty;
99
function one(h, node, parent) {
1010
var fn = null;
1111

12-
if (node.type === 'element' && own.call(h.handlers, node.tagName)) {
13-
fn = h.handlers[node.tagName];
12+
if (node.type === 'element') {
13+
if (node.properties && node.properties.dataMdast === 'ignore') {
14+
return;
15+
}
16+
17+
if (own.call(h.handlers, node.tagName)) {
18+
fn = h.handlers[node.tagName];
19+
}
1420
} else if (own.call(h.handlers, node.type)) {
1521
fn = h.handlers[node.type];
1622
}

readme.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ An implicit sentence.
8787
# An explicit sentence.
8888
```
8989

90-
###### Ignored nodes
90+
###### Ignoring nodes
9191

9292
Some nodes are ignored and their content will not be present in MDAST.
9393
To ignore custom elements, configure a handler for their tag-name or type that
@@ -104,6 +104,18 @@ Yields:
104104
**Importance** and .
105105
```
106106

107+
To ignore a specific element from HTML, set `data-mdast` to `ignore`:
108+
109+
```html
110+
<p><strong>Importance</strong> and <em data-mdast="ignore">emphasis</em>.</p>
111+
```
112+
113+
Yields:
114+
115+
```markdown
116+
**Importance** and .
117+
```
118+
107119
## Related
108120

109121
* [`mdast-util-to-hast`][mdast-util-to-hast]

test/fixtures/ignore/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><strong>Importance</strong> and <em data-mdast="ignore">emphasis</em>.</p>

test/fixtures/ignore/index.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"fragment": true
3+
}

test/fixtures/ignore/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**Importance** and .

0 commit comments

Comments
 (0)