Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Netcarver/Textile/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4217,7 +4217,18 @@ protected function markStartOfLinks($text)
protected function replaceLinks($text)
{
$stopchars = "\s|^'\"*";

$text = 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
);
return (string)preg_replace_callback(
'/
(?P<pre>\[)? # Optionally open with a square bracket eg. Look ["here":url]
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/issue-202.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Link with square brackets directly followed by words or link will be broken at the second link:
input: |
["Wikipedia":https://en.wikipedia.org/]["Github":https://www.github.com/]

我爱["Textile":https://textile-lang.com/]和["TextPattern":https://textpattern.com/]

expect: |
<p><a href="https://en.wikipedia.org/">Wikipedia</a><a href="https://www.github.com/">Github</a></p>

<p>我爱<a href="https://textile-lang.com/">Textile</a>和<a href="https://textpattern.com/">TextPattern</a></p>