Skip to content

Commit d4b023b

Browse files
committed
Adopt Peruacru hyperlink convention
1 parent 08af031 commit d4b023b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

document.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const linkMatcher = /\s*(\w+:\/\/\S+)$/;
2+
13
export default class Document {
24
constructor(element, options = {}) {
35
const {
@@ -47,8 +49,22 @@ export default class Document {
4749
this.br = false;
4850
lift = '';
4951
}
50-
// TODO merge with prior text node
51-
this.cursor.appendChild(document.createTextNode(lift + text));
52+
const match = linkMatcher.exec(text);
53+
if (match === null) {
54+
// TODO merge with prior text node
55+
this.cursor.appendChild(document.createTextNode(lift + text));
56+
} else {
57+
// Support a hyperlink convention.
58+
if (lift !== '') {
59+
this.cursor.appendChild(document.createTextNode(lift));
60+
}
61+
const link = document.createElement('a');
62+
link.href = match[1];
63+
link.target = '_blank';
64+
link.rel = 'noreferrer';
65+
link.appendChild(document.createTextNode(text.slice(0, match.index)));
66+
this.cursor.appendChild(link);
67+
}
5268
this.carry = drop;
5369
}
5470

0 commit comments

Comments
 (0)