Skip to content

Commit

Permalink
added support for simple references
Browse files Browse the repository at this point in the history
fixes #33
  • Loading branch information
cebe committed Apr 26, 2014
1 parent 47b7d7f commit d97c44a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,12 +703,12 @@ private function parseLinkOrImage($markdown)
empty($refMatches[5]) ? null: $refMatches[5], // title
$offset + strlen($refMatches[0]), // offset
];
} elseif (preg_match('/^[ \n]?\[(.*?)\]/', $markdown, $refMatches)) {
} elseif (preg_match('/^[ \n]?(\[(.*?)\])?/', $markdown, $refMatches)) {
// reference style link
if (empty($refMatches[1])) {
if (empty($refMatches[2])) {
$key = strtolower($text);
} else {
$key = strtolower($refMatches[1]);
$key = strtolower($refMatches[2]);
}
if (isset($this->references[$key])) {
return [
Expand Down
5 changes: 5 additions & 0 deletions tests/github-data/issue-33.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<pre><code>hey, check [this].

[this]: https://github.com/cebe/markdown
</code></pre>
<p>is a vaild reference.</p>
6 changes: 6 additions & 0 deletions tests/github-data/issue-33.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```
hey, check [this].
[this]: https://github.com/cebe/markdown
```
is a vaild reference.
3 changes: 2 additions & 1 deletion tests/markdown-data/references.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<p>In the following example we will implement support for <a href="https://help.github.com/articles/github-flavored-markdown#fenced-code-blocks" title="Fenced code block feature of github flavored markdown">fenced code blocks</a> which are part
<p>In the following example we will im[ple]ment support for <a href="https://help.github.com/articles/github-flavored-markdown#fenced-code-blocks" title="Fenced code block feature of github flavored markdown">fenced code blocks</a> which are part
of the <a href="https://github.com">github flavored markdown</a>.</p>
<p>hey, check <a href="https://github.com/cebe/markdown">this</a>.</p>
7 changes: 6 additions & 1 deletion tests/markdown-data/references.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
In the following example we will implement support for [fenced code blocks][] which are part
In the following example we will im[ple]ment support for [fenced code blocks][] which are part
of the [github flavored markdown][gfm].

[fenced code blocks]: https://help.github.com/articles/github-flavored-markdown#fenced-code-blocks
"Fenced code block feature of github flavored markdown"
[gfm]: https://github.com
[unused]: https://github.com/unused

hey, check [this].

[this]: https://github.com/cebe/markdown

0 comments on commit d97c44a

Please sign in to comment.