Skip to content

Commit 85a5b3c

Browse files
authored
Merge pull request #8 from syntax-tree/link
add link handler
2 parents 86fa9f7 + 4da3daa commit 85a5b3c

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

handlers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ exports.p = require('./paragraph');
1212

1313
exports.h1 = exports.h2 = exports.h3 =
1414
exports.h4 = exports.h5 = exports.h6 = require('./heading');
15+
16+
exports.a = require('./link');

handlers/link.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
module.exports = link;
4+
5+
var all = require('../all');
6+
7+
function link(h, node) {
8+
var props = {
9+
url: node.properties.href,
10+
title: node.properties.title || null
11+
};
12+
13+
return h(node, 'link', props, all(h, node));
14+
}

tests/fixtures/a/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p><a href="http://example.com" title="example">example</a></p>
2+
<p><a href="http://example.com">example</a></p>

tests/fixtures/a/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+
}

tests/fixtures/a/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[example](http://example.com "example")
2+
3+
[example](http://example.com)

0 commit comments

Comments
 (0)