@@ -980,17 +980,38 @@ var parseInline = function(block) {
980
980
// Parse string content in block into inline children,
981
981
// using refmap to resolve references.
982
982
var parseInlines = function ( block ) {
983
- // trim() removes non-ASCII whitespaces, vertical tab, form feed and so on.
983
+ // String.protoype. trim() removes non-ASCII whitespaces, vertical tab, form feed and so on.
984
984
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim#return_value
985
985
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#white_space
986
986
// Removes only ASCII tab and space.
987
- this . subject = block . _string_content . replace ( / ^ [ \t \r \n ] + | [ \t \r \n ] + $ / g , "" )
987
+ this . subject = trim ( block . _string_content )
988
988
this . pos = 0 ;
989
989
this . delimiters = null ;
990
990
this . brackets = null ;
991
991
while ( this . parseInline ( block ) ) { }
992
992
block . _string_content = null ; // allow raw string to be garbage collected
993
993
this . processEmphasis ( null ) ;
994
+
995
+ function trim ( str ) {
996
+ var start = 0 ;
997
+ for ( ; start < str . length ; start ++ ) {
998
+ if ( ! isSpace ( str . charCodeAt ( start ) ) ) {
999
+ break ;
1000
+ }
1001
+ }
1002
+ var end = str . length - 1 ;
1003
+ for ( ; end >= start ; end -- ) {
1004
+ if ( ! isSpace ( str . charCodeAt ( end ) ) ) {
1005
+ break ;
1006
+ }
1007
+ }
1008
+ return str . slice ( start , end + 1 ) ;
1009
+
1010
+ function isSpace ( c ) {
1011
+ // U+0020 = space, U+0009 = tab, U+000A = LF, U+000D = CR
1012
+ return c === 0x20 || c === 9 || c === 0xa || c === 0xd ;
1013
+ }
1014
+ }
994
1015
} ;
995
1016
996
1017
// The InlineParser object.
0 commit comments