@ -311,9 +311,8 @@ function postToElemDM(dmData, localUser, remoteUser) {
}
}
// convert message text to html, featuring @users and links formating.
// convert message text to html, featuring @users and links formating.
function htmlFormatMsg ( msg ) {
function htmlFormatMsg ( msg , opt ) {
// TODO: add options for emotions; msg = $.emotions(msg);
// TODO: add options for emotions; msg = $.emotions(msg);
// TODO make markup optionally mutable ?
function getSubStrStart ( str , startPoint , stopChars , isStopCharMustExist , stopCharsTrailing ) {
function getSubStrStart ( str , startPoint , stopChars , isStopCharMustExist , stopCharsTrailing ) {
for ( var i = startPoint ; i > - 1 ; i -- ) {
for ( var i = startPoint ; i > - 1 ; i -- ) {
@ -349,8 +348,8 @@ function htmlFormatMsg(msg) {
return i ;
return i ;
}
}
function markout ( msg , chr , tag ) {
function markout ( msg , markoutOpt , chr , tag ) {
if ( $ . Options . postsMarkout . val === 'ignore' )
if ( markoutOpt === 'ignore' )
return msg ;
return msg ;
function isWhiteSpacesBetween ( i , j ) {
function isWhiteSpacesBetween ( i , j ) {
@ -516,7 +515,7 @@ function htmlFormatMsg(msg) {
}
}
// changing the string
// changing the string
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
if ( chr === '`' && markoutOpt === 'apply' ) { // if markoutOpt === 'clear' then ` does not escape 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 ) ) {
@ -540,10 +539,10 @@ function htmlFormatMsg(msg) {
}
}
}
}
} else {
} else {
if ( $ . Options . postsMarkout . val === 'apply' ) {
if ( markoutOpt === 'apply' ) {
t = '</' + tag + '>' ;
t = '</' + tag + '>' ;
tag = '<' + tag + '>' ;
tag = '<' + tag + '>' ;
} else { // $.Options.postsMarkout.val === 'clear' so we're clearing markup
} else { // markoutOpt === 'clear' so we're clearing markup
t = '' ;
t = '' ;
tag = '' ;
tag = '' ;
}
}
@ -611,6 +610,11 @@ function htmlFormatMsg(msg) {
return { html : '' , mentions : [ ] } ;
return { html : '' , mentions : [ ] } ;
}
}
if ( opt && opt . markout )
var markoutOpt = opt . markout ;
else
var markoutOpt = $ . Options . postsMarkout . val ;
var mentionsChars = 'abcdefghijklmnopqrstuvwxyz_0123456789' ;
var mentionsChars = 'abcdefghijklmnopqrstuvwxyz_0123456789' ;
var stopCharsTrailing = '/\\*~_-`.,:;?!%\'"[](){}^|«»…\u201C\u201D\u2026\u2014\u4E00\u3002\uFF0C\uFF1A\uFF1F\uFF01\u3010\u3011\u2047\u2048\u2049' ;
var stopCharsTrailing = '/\\*~_-`.,:;?!%\'"[](){}^|«»…\u201C\u201D\u2026\u2014\u4E00\u3002\uFF0C\uFF1A\uFF1F\uFF01\u3010\u3011\u2047\u2048\u2049' ;
var stopCharsTrailingUrl = stopCharsTrailing . slice ( 1 ) ;
var stopCharsTrailingUrl = stopCharsTrailing . slice ( 1 ) ;
@ -630,7 +634,7 @@ function htmlFormatMsg(msg) {
// 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 ) === '](' && $ . Options . postsMarkout . val !== 'ignore' ) {
if ( msg . str . slice ( i , i + 2 ) === '](' && markoutOpt !== '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 ) {
@ -658,7 +662,7 @@ function htmlFormatMsg(msg) {
} 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' ) {
if ( markoutOpt === '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 ) ) ,
@ -673,7 +677,7 @@ function htmlFormatMsg(msg) {
. replace ( /&(?!lt;|gt;)/g , '&' )
. replace ( /&(?!lt;|gt;)/g , '&' )
)
)
) ;
) ;
} else { // $.Options.postsMarkout.val === 'clear' so we're clearing markup
} else { // markoutOpt === 'clear' so we're clearing markup
str = msg . str . slice ( i , k + 1 ) ;
str = msg . str . slice ( i , k + 1 ) ;
msg = msgAddHtmlEntity ( msg , j - 1 , getSubStrEnd ( msg . str , k + 1 , ')' , true , '' ) + 2 ,
msg = msgAddHtmlEntity ( msg , j - 1 , getSubStrEnd ( msg . str , k + 1 , ')' , true , '' ) + 2 ,
applyHtml ( // we're trying to clear markup inside [] of []()
applyHtml ( // we're trying to clear markup inside [] of []()
@ -778,10 +782,10 @@ function htmlFormatMsg(msg) {
// handling text style markup
// handling text style markup
msg = markout ( markout ( markout ( markout ( msg ,
msg = markout ( markout ( markout ( markout ( msg ,
'*', 'b' ) , // bold
markoutOpt , '*', 'b' ) , // bold
'~', 'i' ) , // italic
markoutOpt , '~', 'i' ) , // italic
'_', 'u' ) , // underlined
markoutOpt , '_', 'u' ) , // underlined
'-', 's' ) // striketrough
markoutOpt , '-', 's' ) // striketrough
;
;
// handling splitted posts numbering and escaping ampersands, qoutes and apostrophes
// handling splitted posts numbering and escaping ampersands, qoutes and apostrophes
@ -794,6 +798,7 @@ function htmlFormatMsg(msg) {
. replace ( /&(?!lt;|gt;)/g , '&' ) // FIXME in many cases there is no need to escape ampersand in HTML 5
. replace ( /&(?!lt;|gt;)/g , '&' ) // FIXME in many cases there is no need to escape ampersand in HTML 5
. replace ( /"/g , '"' )
. replace ( /"/g , '"' )
. replace ( /'/g , ''' )
. replace ( /'/g , ''' )
;
// applying html entities to msg.str and converting msg to string back
// applying html entities to msg.str and converting msg to string back
msg = applyHtml ( msg ) ;
msg = applyHtml ( msg ) ;