$lineCount = 0;
foreach ($descriptionLines as $descriptionLine) {
- // Detect line of code
- $codeLineOn = preg_match('/^ /', $descriptionLine) > 0;
+ // Detect line of code: starting with 4 spaces,
+ // except lists which can start with +/*/- or `2.` after spaces.
+ $codeLineOn = preg_match('/^ +(?=[^\+\*\-])(?=(?!\d\.).)/', $descriptionLine) > 0;
// Detect and toggle block of code
if (!$codeBlockOn) {
$codeBlockOn = preg_match('/^```/', $descriptionLine) > 0;
$descriptionLine
);
- // Reverse hashtag links if we're in a code block.
- $hashtagFilter = ($codeBlockOn || $codeLineOn) ? $hashtagTitle : '';
+ // Reverse all links in code blocks, only non hashtag elsewhere.
+ $hashtagFilter = (!$codeBlockOn && !$codeLineOn) ? '(?!'. $hashtagTitle .')': '(?:'. $hashtagTitle .')?';
$descriptionLine = preg_replace(
- '!<a href="[^ ]*"'. $hashtagFilter .'>([^<]+)</a>!m',
+ '#<a href="[^ ]*"'. $hashtagFilter .'>([^<]+)</a>#m',
'$1',
$descriptionLine
);