diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-10-21 12:38:38 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-10-22 11:13:48 +0200 |
commit | c5941f316a49c94eff354b63e75b3add98ac4aea (patch) | |
tree | 3a98fc6dee7edd3a13f335f97fb9bc4faf95f064 /plugins | |
parent | e680cfea08051150827dae26ae5e59374880c46c (diff) | |
download | Shaarli-c5941f316a49c94eff354b63e75b3add98ac4aea.tar.gz Shaarli-c5941f316a49c94eff354b63e75b3add98ac4aea.tar.zst Shaarli-c5941f316a49c94eff354b63e75b3add98ac4aea.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.php | 11 |
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 | ); |