File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 1+ const linkMatcher = / \s * ( \w + : \/ \/ \S + ) $ / ;
2+
13export 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+ var 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
You can’t perform that action at this time.
0 commit comments