mirror of
https://framagit.org/hubzilla/core.git
synced 2026-06-21 00:52:33 -04:00
Merge branch 'fix-markdown-mentions' into 'dev'
Prevent mentions from mangling by markdown parser See merge request hubzilla/core!2211
This commit is contained in:
@@ -64,6 +64,12 @@ function markdown_to_bb($s, $use_zrl = false, $options = []) {
|
|||||||
// Escaping the hash tags
|
// Escaping the hash tags
|
||||||
$s = preg_replace('/\#([^\s\#])/','#$1',$s);
|
$s = preg_replace('/\#([^\s\#])/','#$1',$s);
|
||||||
|
|
||||||
|
// Protect mentions from being mangled by the markdown parser
|
||||||
|
$s = preg_replace_callback(
|
||||||
|
'|@\{([^}]+)\}|',
|
||||||
|
fn ($matches) => '@{' . base64_encode($matches[1]) . '}',
|
||||||
|
$s);
|
||||||
|
|
||||||
$s = MarkdownExtra::defaultTransform($s);
|
$s = MarkdownExtra::defaultTransform($s);
|
||||||
|
|
||||||
|
|
||||||
@@ -76,6 +82,12 @@ function markdown_to_bb($s, $use_zrl = false, $options = []) {
|
|||||||
$s = str_replace("\r","",$s);
|
$s = str_replace("\r","",$s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore mentions after markdown conversion
|
||||||
|
$s = preg_replace_callback(
|
||||||
|
'|@\{([^}]+)\}|',
|
||||||
|
fn ($matches) => '@{' . base64_decode($matches[1]) . '}',
|
||||||
|
$s);
|
||||||
|
|
||||||
$s = str_replace('#','#',$s);
|
$s = str_replace('#','#',$s);
|
||||||
|
|
||||||
$s = html2bbcode($s);
|
$s = html2bbcode($s);
|
||||||
|
|||||||
@@ -114,6 +114,10 @@ class MarkdownTest extends UnitTestCase {
|
|||||||
'This is a link https://example.com/some/path more info.',
|
'This is a link https://example.com/some/path more info.',
|
||||||
'This is a link https://example.com/some/path more info.',
|
'This is a link https://example.com/some/path more info.',
|
||||||
],
|
],
|
||||||
|
'mention with underscores is untouched' => [
|
||||||
|
'@{_test_@somesite.example} @{test_2_@othersite.example}',
|
||||||
|
'@{_test_@somesite.example} @{test_2_@othersite.example}',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user