clickable urls in task title and v1 note supports IDN (fixes GH-12)

This commit is contained in:
Max Pozdeev 2021-07-15 21:43:50 +03:00
parent c4873ff3d3
commit 9fcafb7f8a
3 changed files with 36 additions and 5 deletions

View file

@ -532,7 +532,8 @@ function prepareTaskRow($r)
return array(
'id' => $r['id'],
'title' => htmlspecialchars( $r['title'] ),
'title' => titleMarkup( $r['title'] ),
'titleText' => (string)$r['title'],
'listId' => $r['list_id'],
'date' => htmlarray($dCreated),
'dateInt' => (int)$r['d_created'],

View file

@ -31,17 +31,47 @@ function mttMarkup_v1($s)
$s = preg_replace("~<i>([\s\S]*?)</i>~i", "${c1}i${c2}\$1${c1}/i${c2}", $s);
$s = preg_replace("~<u>([\s\S]*?)</u>~i", "${c1}u${c2}\$1${c1}/u${c2}", $s);
$s = preg_replace("~<s>([\s\S]*?)</s>~i", "${c1}s${c2}\$1${c1}/s${c2}", $s);
$s = htmlspecialchars($s); //escape all elements, except above
$s = htmlspecialchars($s, ENT_QUOTES); //escape all elements, except above
$s = str_replace( [$c1, $c2], ['<','>'], $s ); //unhide
$s = nl2br($s);
// make links from text starting with 'www.'
$s = preg_replace( "/(^|\s|>)(www\.([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|&quot;|&lt;|&gt;|\"|<|>|$)/i" , '$1<a href="http://$2" target="_blank">$2</a>$4' , $s );
$s = preg_replace(
"/(^|\s|>)(www\.([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|&quot;|&lt;|&gt;|\"|<|>|$)/iu" ,
'$1<a href="http://$2" target="_blank">$2</a>$4' ,
$s
);
// make link from text starting with protocol like 'http://'
$s = preg_replace( "/(^|\s|>)([a-z]+:\/\/([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|&quot;|&lt;|&gt;|\"|<|>|$)/i" , '$1<a href="$2" target="_blank">$2</a>$4' , $s);
$s = preg_replace(
"/(^|\s|>)([a-z]+:\/\/([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|&quot;|&lt;|&gt;|\"|<|>|$)/iu" ,
'$1<a href="$2" target="_blank">$2</a>$4' ,
$s
);
return $s;
}
// Convert raw title to html with allowed urls
function titleMarkup($title)
{
//escape all unsafe
$title = htmlspecialchars($title, ENT_QUOTES);
// make links from text starting with 'www.'
$title = preg_replace(
"/(^|\s|>)(www\.([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|&quot;|&lt;|&gt;|\"|<|>|$)/iu" ,
'$1<a href="http://$2" target="_blank">$2</a>$4' ,
$title
);
// make link from text starting with protocol like 'http://'
$title = preg_replace(
"/(^|\s|>)([a-z]+:\/\/([\w\#$%&~\/.\-\+;:=,\?\[\]@]+?))(,|\.|:|)?(?=\s|&quot;|&lt;|&gt;|\"|<|>|$)/iu" ,
'$1<a href="$2" target="_blank">$2</a>$4' ,
$title
);
return $title;
}
?>

View file

@ -1496,7 +1496,7 @@ function editTask(id)
if(!item) return false;
// no need to clear form
var form = document.getElementById('taskedit_form');
form.task.value = dehtml(item.title);
form.task.value = item.titleText;
form.note.value = item.noteText;
form.id.value = item.id;
form.tags.value = item.tags.split(',').join(', ');