@@ -27,8 +27,6 @@ export default class Markdown {
27
27
28
28
const parser = new commonmark . Parser ( ) ;
29
29
this . parsed = parser . parse ( this . input ) ;
30
-
31
- this . renderer = new commonmark . HtmlRenderer ( { safe : false } ) ;
32
30
}
33
31
34
32
isPlainText ( ) {
@@ -58,9 +56,10 @@ export default class Markdown {
58
56
}
59
57
60
58
toHTML ( ) {
61
- const real_paragraph = this . renderer . paragraph ;
59
+ const renderer = new commonmark . HtmlRenderer ( { safe : false } ) ;
60
+ const real_paragraph = renderer . paragraph ;
62
61
63
- this . renderer . paragraph = function ( node , entering ) {
62
+ renderer . paragraph = function ( node , entering ) {
64
63
// If there is only one top level node, just return the
65
64
// bare text: it's a single line of text and so should be
66
65
// 'inline', rather than unnecessarily wrapped in its own
@@ -75,11 +74,7 @@ export default class Markdown {
75
74
}
76
75
} ;
77
76
78
- var rendered = this . renderer . render ( this . parsed ) ;
79
-
80
- this . renderer . paragraph = real_paragraph ;
81
-
82
- return rendered ;
77
+ return renderer . render ( this . parsed ) ;
83
78
}
84
79
85
80
/*
@@ -89,17 +84,18 @@ export default class Markdown {
89
84
* (to fix https://github.com/vector-im/riot-web/issues/2870)
90
85
*/
91
86
toPlaintext ( ) {
92
- const real_paragraph = this . renderer . paragraph ;
87
+ const renderer = new commonmark . HtmlRenderer ( { safe : false } ) ;
88
+ const real_paragraph = renderer . paragraph ;
93
89
94
90
// The default `out` function only sends the input through an XML
95
91
// escaping function, which causes messages to be entity encoded,
96
92
// which we don't want in this case.
97
- this . renderer . out = function ( s ) {
93
+ renderer . out = function ( s ) {
98
94
// The `lit` function adds a string literal to the output buffer.
99
95
this . lit ( s ) ;
100
96
} ;
101
97
102
- this . renderer . paragraph = function ( node , entering ) {
98
+ renderer . paragraph = function ( node , entering ) {
103
99
// If there is only one top level node, just return the
104
100
// bare text: it's a single line of text and so should be
105
101
// 'inline', rather than unnecessarily wrapped in its own
@@ -117,10 +113,6 @@ export default class Markdown {
117
113
}
118
114
} ;
119
115
120
- var rendered = this . renderer . render ( this . parsed ) ;
121
-
122
- this . renderer . paragraph = real_paragraph ;
123
-
124
- return rendered ;
116
+ return renderer . render ( this . parsed ) ;
125
117
}
126
118
}
0 commit comments