@@ -126,7 +126,7 @@ sf.init = function() {
126
126
sf . formatter . appendChild ( icon ) ;
127
127
continue ;
128
128
}
129
-
129
+
130
130
// Set up code for each icon
131
131
icon . fillers = sf . tags [ t ] . fillers ;
132
132
icon . onclick = function ( event ) {
@@ -171,20 +171,29 @@ sf.init = function() {
171
171
event . target . parentElement . prepend ( sf . formatter ) ;
172
172
sf . formatter . style . width = event . target . offsetWidth + "px" ;
173
173
event . target . style . resize = "auto" ;
174
-
175
174
}
176
175
}
177
176
}
178
177
179
178
// Initial background formatting loop.
179
+ // This just checks for new comments
180
180
setInterval ( function ( ) {
181
181
sf . format ( ) ;
182
182
} , 300 ) ;
183
183
}
184
184
185
- // This is a 1 second timeout for page load, since I am
186
- // too lazy to figure out real page load times
187
- setTimeout ( sf . init , 1000 ) ;
185
+ // Simply a .5 second timer after page load. JS onload doesn't seem
186
+ // to work very well.
187
+ setTimeout ( function ( ) {
188
+ var messages = document . getElementsByClassName ( "comment-text" ) ;
189
+ if ( messages . length == 0 ) {
190
+ sf . init ( ) ;
191
+ } else {
192
+ for ( var i = 0 ; i < messages . length ; i ++ ) {
193
+ messages [ i ] . innerHTML = sf . parse ( messages [ i ] . innerHTML ) ;
194
+ }
195
+ }
196
+ } , 500 ) ;
188
197
189
198
// Function to format comments that are not already
190
199
// formatted
@@ -213,11 +222,17 @@ sf.parseMD = function(text) {
213
222
// Bold, then italics
214
223
text = text . replace ( / \* \* ( .* ?) \* \* / g, "<b>$1</b>" ) ;
215
224
text = text . replace ( / \* ( .* ?) \* / g, "<i>$1</i>" ) ;
225
+
226
+ text = text . replace ( / ` ` ` ( ( .| \n * ) * ?) ` ` ` / gm, "<code>$1</code>" ) ;
227
+ text = text . replace ( / ` ( .* ?) ` / g, "<code>$1</code>" ) ;
228
+
229
+ // Don't format links that already have a tag with them
216
230
text = text . replace ( / ( h t t p s : | h t t p : | w w w \. ) ( [ ^ \" \> \< ] * $ ) / gm, "<a href='$1$2'>$1$2</a>" ) ;
231
+
217
232
return text ;
218
233
}
219
234
220
- // Custom regex SFML * parser. It parses differently than HTML . Instead
235
+ // Custom regex SFCode * parser. It parses differently than BBcode . Instead
221
236
// Of replacing [b] with <b>, it it replaces both tags with
222
237
// text between them. Therefore, "[b][b]Hello[/b][/b]" will not work.
223
238
// It doesn't really matter though, and won't be changed unless it
0 commit comments