-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to display link reference in paragraph, without footnotes
- Loading branch information
Showing
2 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -443,13 +443,24 @@ protected function flushFootnotes() | |
} else { | ||
$this->out("\n", true); | ||
} | ||
$this->out(' [' . $tag['linkID'] . ']: ' . $tag['href'] . (isset($tag['title']) ? ' "' . $tag['title'] . '"' : ''), true); | ||
$this->out(' [' . $tag['linkID'] . ']: ' . $this->getLinkReference($tag), true); | ||
$tag['unstacked'] = true; | ||
$this->footnotes[$k] = $tag; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* return formated link reference | ||
* | ||
* @param array $tag | ||
* @return string link reference | ||
*/ | ||
protected function getLinkReference($tag) | ||
{ | ||
return $tag['href'] . (isset($tag['title']) ? ' "' . $tag['title'] . '"' : ''); | ||
} | ||
|
||
/** | ||
* flush enqued linebreaks | ||
* | ||
|
@@ -769,6 +780,11 @@ protected function handleTag_a_converter($tag, $buffer) | |
# [1]: mailto:[email protected] Title | ||
$tag['href'] = 'mailto:' . $bufferDecoded; | ||
} | ||
|
||
if ($this->linkPosition == self::LINK_IN_PARAGRAPH) { | ||
return '[' . $buffer . '](' . $this->getLinkReference($tag) . ')'; | ||
} | ||
|
||
# [This link][id] | ||
foreach ($this->footnotes as $tag2) { | ||
if ($tag2['href'] == $tag['href'] && $tag2['title'] === $tag['title']) { | ||
|
@@ -780,7 +796,6 @@ protected function handleTag_a_converter($tag, $buffer) | |
$tag['linkID'] = count($this->footnotes) + 1; | ||
array_push($this->footnotes, $tag); | ||
} | ||
//var_dump($tag); | ||
|
||
return '[' . $buffer . '][' . $tag['linkID'] . ']'; | ||
} | ||
|
@@ -810,7 +825,7 @@ protected function handleTag_img() | |
|
||
if (empty($this->parser->tagAttributes['src'])) { | ||
# support for "empty" images... dunno if this is really needed | ||
# but there are some testcases which do that... | ||
# but there are some test cases which do that... | ||
if (!empty($this->parser->tagAttributes['title'])) { | ||
$this->parser->tagAttributes['title'] = ' ' . $this->parser->tagAttributes['title'] . ' '; | ||
} | ||
|
@@ -821,7 +836,18 @@ protected function handleTag_img() | |
$this->parser->tagAttributes['src'] = $this->decode($this->parser->tagAttributes['src']); | ||
} | ||
|
||
# [This link][id] | ||
$out = '![' . $this->parser->tagAttributes['alt'] . ']'; | ||
if ($this->linkPosition == self::LINK_IN_PARAGRAPH) { | ||
$out .= '(' . $this->parser->tagAttributes['src']; | ||
if ($this->parser->tagAttributes['title']) { | ||
$out .= ' "' . $this->parser->tagAttributes['title'] . '"'; | ||
} | ||
$out .= ')'; | ||
$this->out($out, true); | ||
return ; | ||
} | ||
|
||
# ![This image][id] | ||
$link_id = false; | ||
if (!empty($this->footnotes)) { | ||
foreach ($this->footnotes as $tag) { | ||
|
@@ -842,8 +868,9 @@ protected function handleTag_img() | |
); | ||
array_push($this->footnotes, $tag); | ||
} | ||
|
||
$this->out('![' . $this->parser->tagAttributes['alt'] . '][' . $link_id . ']', true); | ||
$out .= '[' . $link_id . ']'; | ||
|
||
$this->out($out, true); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters