Skip to content

Commit

Permalink
Merge 51d957b into 99d0a66
Browse files Browse the repository at this point in the history
  • Loading branch information
gocom committed Jan 8, 2020
2 parents 99d0a66 + 51d957b commit 92c0705
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/Netcarver/Textile/Parser.php
Expand Up @@ -4217,19 +4217,29 @@ protected function markStartOfLinks($text)
protected function replaceLinks($text)
{
$stopchars = "\s|^'\"*";
$needle = $this->uid . 'linkStartMarker:';
$prev = null;

while (\strpos($text, $needle) !== false) {
$text = (string)preg_replace_callback(
'/
(?P<pre>\[)?
' . $needle . '"
(?P<inner>(?:.|\n)*?)
":(?P<urlx>[^' . $stopchars . ']*)
/x' . $this->regex_snippets['mod'],
array($this, "fLink"),
$text
);

return (string)preg_replace_callback(
'/
(?P<pre>\[)? # Optionally open with a square bracket eg. Look ["here":url]
'.$this->uid.'linkStartMarker:" # marks start of the link
(?P<inner>(?:.|\n)*?) # grab the content of the inner "..." part of the link, can be anything but
# do not worry about matching class, id, lang or title yet
": # literal ": marks end of atts + text + title block
(?P<urlx>[^'.$stopchars.']*) # url upto a stopchar
/x'.$this->regex_snippets['mod'],
array($this, "fLink"),
$text
);
if ($prev === $text) {
break;
}

$prev = $text;
}

return $text;
}

/**
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/issue-202.yaml
@@ -0,0 +1,20 @@
Links placed one after other should be parsed:
input: |
["1":https://example.tld]["2":https://example.tld]["3":https://example.tld]
expect: |
<p><a href="https://example.tld">1</a><a href="https://example.tld">2</a><a href="https://example.tld">3</a></p>
Continous non-breaking content between links should be allowed:
input: |
["1":https://example.tld]|["2":https://example.tld]|["3":https://example.tld]
expect: |
<p><a href="https://example.tld">1</a>|<a href="https://example.tld">2</a>|<a href="https://example.tld">3</a></p>
Same applies for continuous multi-byte characters between links:
input: |
我["1":https://example.tld/]和["2":https://example.tld/]和["3":https://example.tld/]
expect: |
<p>我<a href="https://example.tld/">1</a>和<a href="https://example.tld/">2</a>和<a href="https://example.tld/">3</a></p>

0 comments on commit 92c0705

Please sign in to comment.