aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-10-21 12:38:38 +0200
committerArthurHoaro <arthur@hoa.ro>2016-11-05 14:30:56 +0100
commit95a12c7c0f3d074c3e61507b3fc33879b042f683 (patch)
tree59cacc4ebf6453efe8eb9d3392a7680a612eff96 /plugins
parentdf90715655347c53aa9743de156b163de8fbd784 (diff)
downloadShaarli-95a12c7c0f3d074c3e61507b3fc33879b042f683.tar.gz
Shaarli-95a12c7c0f3d074c3e61507b3fc33879b042f683.tar.zst
Shaarli-95a12c7c0f3d074c3e61507b3fc33879b042f683.zip
Fix an issue with links not being reversed in code blocks
Fixes #672 + Markdown to HTML unit test
Diffstat (limited to 'plugins')
-rw-r--r--plugins/markdown/markdown.php11
1 files changed, 6 insertions, 5 deletions
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php
index eb7bf23d..a764b6fa 100644
--- a/plugins/markdown/markdown.php
+++ b/plugins/markdown/markdown.php
@@ -155,8 +155,9 @@ function reverse_text2clickable($description)
155 $lineCount = 0; 155 $lineCount = 0;
156 156
157 foreach ($descriptionLines as $descriptionLine) { 157 foreach ($descriptionLines as $descriptionLine) {
158 // Detect line of code 158 // Detect line of code: starting with 4 spaces,
159 $codeLineOn = preg_match('/^ /', $descriptionLine) > 0; 159 // except lists which can start with +/*/- or `2.` after spaces.
160 $codeLineOn = preg_match('/^ +(?=[^\+\*\-])(?=(?!\d\.).)/', $descriptionLine) > 0;
160 // Detect and toggle block of code 161 // Detect and toggle block of code
161 if (!$codeBlockOn) { 162 if (!$codeBlockOn) {
162 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0; 163 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0;
@@ -173,10 +174,10 @@ function reverse_text2clickable($description)
173 $descriptionLine 174 $descriptionLine
174 ); 175 );
175 176
176 // Reverse hashtag links if we're in a code block. 177 // Reverse all links in code blocks, only non hashtag elsewhere.
177 $hashtagFilter = ($codeBlockOn || $codeLineOn) ? $hashtagTitle : ''; 178 $hashtagFilter = (!$codeBlockOn && !$codeLineOn) ? '(?!'. $hashtagTitle .')': '(?:'. $hashtagTitle .')?';
178 $descriptionLine = preg_replace( 179 $descriptionLine = preg_replace(
179 '!<a href="[^ ]*"'. $hashtagFilter .'>([^<]+)</a>!m', 180 '#<a href="[^ ]*"'. $hashtagFilter .'>([^<]+)</a>#m',
180 '$1', 181 '$1',
181 $descriptionLine 182 $descriptionLine
182 ); 183 );