@@ -39,10 +39,6 @@ block.list = replace(block.list)
39
39
( 'def' , '\\n+(?=' + block . def . source + ')' )
40
40
( ) ;
41
41
42
- block . blockquote = replace ( block . blockquote )
43
- ( 'def' , block . def )
44
- ( ) ;
45
-
46
42
block . _tag = '(?!(?:'
47
43
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
48
44
+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
@@ -457,7 +453,7 @@ var inline = {
457
453
nolink : / ^ ! ? \[ ( (?: \[ [ ^ \] ] * \] | [ ^ \[ \] ] ) * ) \] / ,
458
454
strong : / ^ _ _ ( [ \s \S ] + ?) _ _ (? ! _ ) | ^ \* \* ( [ \s \S ] + ?) \* \* (? ! \* ) / ,
459
455
em : / ^ \b _ ( (?: [ ^ _ ] | _ _ ) + ?) _ \b | ^ \* ( (?: \* \* | [ \s \S ] ) + ?) \* (? ! \* ) / ,
460
- code : / ^ ( ` + ) \s * ( [ \s \S ] * ?[ ^ ` ] ) \s * \1(? ! ` ) / ,
456
+ code : / ^ ( ` + ) ( [ \s \S ] * ?[ ^ ` ] ) \1(? ! ` ) / ,
461
457
br : / ^ { 2 , } \n (? ! \s * $ ) / ,
462
458
del : noop ,
463
459
text : / ^ [ \s \S ] + ?(? = [ \\ < ! \[ _ * ` ] | { 2 , } \n | $ ) /
@@ -578,9 +574,11 @@ InlineLexer.prototype.output = function(src) {
578
574
if ( cap = this . rules . autolink . exec ( src ) ) {
579
575
src = src . substring ( cap [ 0 ] . length ) ;
580
576
if ( cap [ 2 ] === '@' ) {
581
- text = cap [ 1 ] . charAt ( 6 ) === ':'
577
+ text = escape (
578
+ cap [ 1 ] . charAt ( 6 ) === ':'
582
579
? this . mangle ( cap [ 1 ] . substring ( 7 ) )
583
- : this . mangle ( cap [ 1 ] ) ;
580
+ : this . mangle ( cap [ 1 ] )
581
+ ) ;
584
582
href = this . mangle ( 'mailto:' ) + text ;
585
583
} else {
586
584
text = escape ( cap [ 1 ] ) ;
@@ -661,7 +659,7 @@ InlineLexer.prototype.output = function(src) {
661
659
// code
662
660
if ( cap = this . rules . code . exec ( src ) ) {
663
661
src = src . substring ( cap [ 0 ] . length ) ;
664
- out += this . renderer . codespan ( escape ( cap [ 2 ] , true ) ) ;
662
+ out += this . renderer . codespan ( escape ( cap [ 2 ] . trim ( ) , true ) ) ;
665
663
continue ;
666
664
}
667
665
@@ -879,6 +877,9 @@ Renderer.prototype.link = function(href, title, text) {
879
877
return '' ;
880
878
}
881
879
}
880
+ if ( this . options . baseUrl && ! originIndependentUrl . test ( href ) ) {
881
+ href = resolveUrl ( this . options . baseUrl , href ) ;
882
+ }
882
883
var out = '<a href="' + href + '"' ;
883
884
if ( title ) {
884
885
out += ' title="' + title + '"' ;
@@ -888,6 +889,9 @@ Renderer.prototype.link = function(href, title, text) {
888
889
} ;
889
890
890
891
Renderer . prototype . image = function ( href , title , text ) {
892
+ if ( this . options . baseUrl && ! originIndependentUrl . test ( href ) ) {
893
+ href = resolveUrl ( this . options . baseUrl , href ) ;
894
+ }
891
895
var out = '<img src="' + href + '" alt="' + text + '"' ;
892
896
if ( title ) {
893
897
out += ' title="' + title + '"' ;
@@ -1094,8 +1098,8 @@ function escape(html, encode) {
1094
1098
}
1095
1099
1096
1100
function unescape ( html ) {
1097
- // explicitly match decimal, hex, and named HTML entities
1098
- return html . replace ( / & ( # (?: \d + ) | (?: # x [ 0 - 9 A - F a - f ] + ) | (?: \w + ) ) ; ? / g , function ( _ , n ) {
1101
+ // explicitly match decimal, hex, and named HTML entities
1102
+ return html . replace ( / & ( # (?: \d + ) | (?: # x [ 0 - 9 A - F a - f ] + ) | (?: \w + ) ) ; ? / ig , function ( _ , n ) {
1099
1103
n = n . toLowerCase ( ) ;
1100
1104
if ( n === 'colon' ) return ':' ;
1101
1105
if ( n . charAt ( 0 ) === '#' ) {
@@ -1119,6 +1123,30 @@ function replace(regex, opt) {
1119
1123
} ;
1120
1124
}
1121
1125
1126
+ function resolveUrl ( base , href ) {
1127
+ if ( ! baseUrls [ ' ' + base ] ) {
1128
+ // we can ignore everything in base after the last slash of its path component,
1129
+ // but we might need to add _that_
1130
+ // https://tools.ietf.org/html/rfc3986#section-3
1131
+ if ( / ^ [ ^ : ] + : \/ * [ ^ / ] * $ / . test ( base ) ) {
1132
+ baseUrls [ ' ' + base ] = base + '/' ;
1133
+ } else {
1134
+ baseUrls [ ' ' + base ] = base . replace ( / [ ^ / ] * $ / , '' ) ;
1135
+ }
1136
+ }
1137
+ base = baseUrls [ ' ' + base ] ;
1138
+
1139
+ if ( href . slice ( 0 , 2 ) === '//' ) {
1140
+ return base . replace ( / : [ ^ ] * / , ':' ) + href ;
1141
+ } else if ( href . charAt ( 0 ) === '/' ) {
1142
+ return base . replace ( / ( : \/ * [ ^ / ] * ) [ ^ ] * / , '$1' ) + href ;
1143
+ } else {
1144
+ return base + href ;
1145
+ }
1146
+ }
1147
+ baseUrls = { } ;
1148
+ originIndependentUrl = / ^ $ | ^ [ a - z ] [ a - z 0 - 9 + . - ] * : | ^ [ ? # ] / i;
1149
+
1122
1150
function noop ( ) { }
1123
1151
noop . exec = noop ;
1124
1152
@@ -1253,7 +1281,8 @@ marked.defaults = {
1253
1281
smartypants : false ,
1254
1282
headerPrefix : '' ,
1255
1283
renderer : new Renderer ,
1256
- xhtml : false
1284
+ xhtml : false ,
1285
+ baseUrl : null
1257
1286
} ;
1258
1287
1259
1288
/**
0 commit comments