This repository was archived by the owner on Sep 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -55,14 +55,33 @@ function is_multi_line(node) {
55
55
return par . firstChild != par . lastChild ;
56
56
}
57
57
58
+ import linkifyMatrix from './linkify-matrix' ;
59
+ import * as linkify from 'linkifyjs' ;
60
+ linkifyMatrix ( linkify ) ;
61
+
62
+ // Thieved from draft-js-export-markdown
63
+ function escapeMarkdown ( s ) {
64
+ return s . replace ( / [ * _ ` ] / g, '\\$&' ) ;
65
+ }
66
+
67
+ // Replace URLs, room aliases and user IDs with md-escaped URLs
68
+ function linkifyMarkdown ( s ) {
69
+ const links = linkify . find ( s ) ;
70
+ links . forEach ( ( l ) => {
71
+ // This may replace several instances of `l.value` at once, but that's OK
72
+ s = s . replace ( l . value , escapeMarkdown ( l . value ) ) ;
73
+ } ) ;
74
+ return s ;
75
+ }
76
+
58
77
/**
59
78
* Class that wraps commonmark, adding the ability to see whether
60
79
* a given message actually uses any markdown syntax or whether
61
80
* it's plain text.
62
81
*/
63
82
export default class Markdown {
64
83
constructor ( input ) {
65
- this . input = input ;
84
+ this . input = linkifyMarkdown ( input ) ;
66
85
67
86
const parser = new commonmark . Parser ( ) ;
68
87
this . parsed = parser . parse ( this . input ) ;
You can’t perform that action at this time.
0 commit comments