@ -258,6 +258,9 @@ function htmlFormatMsg(msg, mentions) {
}
}
function markout ( msg , chr , tag ) {
function markout ( msg , chr , tag ) {
if ( $ . Options . postsMarkout . val === 'ignore' )
return msg ;
function isWhiteSpacesBetween ( i , j ) {
function isWhiteSpacesBetween ( i , j ) {
j ++ ;
j ++ ;
for ( i += 1 ; i < j ; i ++ ) {
for ( i += 1 ; i < j ; i ++ ) {
@ -375,20 +378,19 @@ function htmlFormatMsg(msg, mentions) {
}
}
// changing the string
// changing the string
if ( chr === '`' ) {
if ( chr === '`' && $ . Options . postsMarkout . val === 'apply' ) { // if $.Options.postsMarkout.val === 'clear' then ` does not escapes anythyng so it needs to be handled like other tags
for ( i = 0 ; i < p . length ; i ++ ) {
for ( i = 0 ; i < p . length ; i ++ ) {
if ( p [ i ] . a > - 1 ) {
if ( p [ i ] . a > - 1 ) {
if ( p [ i ] . t === - 1 || ( p [ i ] . t === 0 && p [ i ] . a > i ) ) {
if ( p [ i ] . t === - 1 || ( p [ i ] . t === 0 && p [ i ] . a > i ) ) {
if ( p [ i ] . k > 1 )
if ( p [ i ] . k > 1 )
t = '<' + tag + '>' + Array ( p [ i ] . k ) . join ( chr ) ;
t = Array ( p [ i ] . k ) . join ( chr ) ;
else
else
t = '<' + tag + '>' ;
t = '' ;
j = p [ i ] . a ;
j = p [ i ] . a ;
t = t + msg . str . slice ( p [ i ] . i + p [ i ] . k , p [ j ] . i ) ;
t = t + msg . str . slice ( p [ i ] . i + p [ i ] . k , p [ j ] . i ) ;
if ( p [ j ] . k > 1 )
if ( p [ j ] . k > 1 )
t = t + Array ( p [ i ] . k ) . join ( chr ) + '</' + tag + '>' ;
t = t + Array ( p [ i ] . k ) . join ( chr ) ;
else
t = '<' + tag + '>' + t + '</' + tag + '>' ;
t = t + '</' + tag + '>' ;
msg . htmlEntities . push ( t . replace ( /&(?!lt;|gt;)/g , '&' ) ) ;
msg . htmlEntities . push ( t . replace ( /&(?!lt;|gt;)/g , '&' ) ) ;
htmlEntityEncoded = '>' + ( msg . htmlEntities . length - 1 ) . toString ( ) + '<' ;
htmlEntityEncoded = '>' + ( msg . htmlEntities . length - 1 ) . toString ( ) + '<' ;
msg . str = msg . str . slice ( 0 , p [ i ] . i ) + htmlEntityEncoded + msg . str . slice ( p [ j ] . i + p [ j ] . k ) ;
msg . str = msg . str . slice ( 0 , p [ i ] . i ) + htmlEntityEncoded + msg . str . slice ( p [ j ] . i + p [ j ] . k ) ;
@ -400,18 +402,25 @@ function htmlFormatMsg(msg, mentions) {
}
}
}
}
} else {
} else {
if ( $ . Options . postsMarkout . val === 'apply' ) {
t = '</' + tag + '>' ;
tag = '<' + tag + '>' ;
} else { // $.Options.postsMarkout.val === 'clear' so we're clearing markup
t = '' ;
tag = '' ;
}
for ( i = 0 ; i < p . length ; i ++ ) {
for ( i = 0 ; i < p . length ; i ++ ) {
if ( p [ i ] . a > - 1 ) {
if ( p [ i ] . a > - 1 ) {
if ( p [ i ] . t === - 1 || ( p [ i ] . t === 0 && p [ i ] . a > i ) ) {
if ( p [ i ] . t === - 1 || ( p [ i ] . t === 0 && p [ i ] . a > i ) ) {
if ( p [ i ] . k > 1 )
if ( p [ i ] . k > 1 )
msg . htmlEntities . push ( '<' + tag + '>' + Array ( p [ i ] . k ) . join ( chr ) ) ;
msg . htmlEntities . push ( tag + Array ( p [ i ] . k ) . join ( chr ) ) ;
else
else
msg . htmlEntities . push ( '<' + tag + '>' ) ;
msg . htmlEntities . push ( tag ) ;
} else if ( p [ i ] . t === 1 || ( p [ i ] . t === 0 && p [ i ] . a < i ) ) {
} else if ( p [ i ] . t === 1 || ( p [ i ] . t === 0 && p [ i ] . a < i ) ) {
if ( p [ i ] . k > 1 )
if ( p [ i ] . k > 1 )
msg . htmlEntities . push ( Array ( p [ i ] . k ) . join ( chr ) + '</' + tag + '>' ) ;
msg . htmlEntities . push ( Array ( p [ i ] . k ) . join ( chr ) + t ) ;
else
else
msg . htmlEntities . push ( '</' + tag + '>' ) ;
msg . htmlEntities . push ( t ) ;
}
}
htmlEntityEncoded = '>' + ( msg . htmlEntities . length - 1 ) . toString ( ) + '<' ;
htmlEntityEncoded = '>' + ( msg . htmlEntities . length - 1 ) . toString ( ) + '<' ;
msg . str = msg . str . slice ( 0 , p [ i ] . i ) + htmlEntityEncoded + msg . str . slice ( p [ i ] . i + p [ i ] . k ) ;
msg . str = msg . str . slice ( 0 , p [ i ] . i ) + htmlEntityEncoded + msg . str . slice ( p [ i ] . i + p [ i ] . k ) ;
@ -477,7 +486,7 @@ function htmlFormatMsg(msg, mentions) {
// handling links
// handling links
for ( i = 0 ; i < msg . str . length - 7 ; i ++ ) {
for ( i = 0 ; i < msg . str . length - 7 ; i ++ ) {
if ( msg . str . slice ( i , i + 2 ) === '](' ) {
if ( msg . str . slice ( i , i + 2 ) === '](' && $ . Options . postsMarkout . val !== 'ignore' ) {
// FIXME there can be text with [] inside [] or links with () we need to handle it too
// FIXME there can be text with [] inside [] or links with () we need to handle it too
j = getSubStrStart ( msg . str , i - 2 , '[' , true , '' ) ;
j = getSubStrStart ( msg . str , i - 2 , '[' , true , '' ) ;
if ( j < i - 1 ) {
if ( j < i - 1 ) {
@ -505,6 +514,7 @@ function htmlFormatMsg(msg, mentions) {
} else {
} else {
if ( getSubStrEnd ( msg . str , i + 1 , whiteSpacesUrl , false , '' ) < k ) // use only first word as href target, others drop silently
if ( getSubStrEnd ( msg . str , i + 1 , whiteSpacesUrl , false , '' ) < k ) // use only first word as href target, others drop silently
k = getSubStrEnd ( msg . str , i + 1 , whiteSpacesUrl , false , '' ) ;
k = getSubStrEnd ( msg . str , i + 1 , whiteSpacesUrl , false , '' ) ;
if ( $ . Options . postsMarkout . val === 'apply' ) {
msg = msgAddHtmlEntity ( msg , j - 1 , getSubStrEnd ( msg . str , k + 1 , ')' , true , '' ) + 2 ,
msg = msgAddHtmlEntity ( msg , j - 1 , getSubStrEnd ( msg . str , k + 1 , ')' , true , '' ) + 2 ,
newHtmlEntityLink ( _htmlFormatMsgLinkTemplateExternal ,
newHtmlEntityLink ( _htmlFormatMsgLinkTemplateExternal ,
proxyURL ( msg . str . slice ( i , k + 1 ) ) ,
proxyURL ( msg . str . slice ( i , k + 1 ) ) ,
@ -519,6 +529,28 @@ function htmlFormatMsg(msg, mentions) {
. replace ( /&(?!lt;|gt;)/g , '&' )
. replace ( /&(?!lt;|gt;)/g , '&' )
)
)
) ;
) ;
} else { // $.Options.postsMarkout.val === 'clear' so we're clearing markup
str = msg . str . slice ( i , k + 1 ) ;
msg = msgAddHtmlEntity ( msg , j - 1 , getSubStrEnd ( msg . str , k + 1 , ')' , true , '' ) + 2 ,
applyHtml ( // we're trying to clear markup inside [] of []()
markout ( markout ( markout ( markout (
{ str : linkName , htmlEntities : msg . htmlEntities } ,
'*' , 'b' ) , // bold
'~' , 'i' ) , // italic
'_' , 'u' ) , // underlined
'-' , 's' ) // striketrough
)
. replace ( /&(?!lt;|gt;)/g , '&' )
) ;
// here we put link target as plain text to handle it usual way (search http[s]:// and so on)
i = msg . i + 1
msg . str = msg . str . slice ( 0 , i ) + ' ' + str + msg . str . slice ( i ) ;
/ * a l t e r n a t i v e l y w e c o u l d s e t u p i t a s l i n k i t s e l f b u t I s u p p o s e y o u d o n ' t w a n t i t
msg = msgAddHtmlEntity ( msg , msg . i + 1 , msg . i + 1 ,
' ' + newHtmlEntityLink ( _htmlFormatMsgLinkTemplateExternal ,
proxyURL ( str ) , str )
) ; * /
}
}
}
i = msg . i + 1 ;
i = msg . i + 1 ;
}
}