Skip to content

Commit

Permalink
Allow empty link text also for normal links, not just images
Browse files Browse the repository at this point in the history
Fixes #305, inconsistent behavior in kramdown itself and makes kramdown
more compatible with other implementations.
  • Loading branch information
gettalong committed Feb 17, 2016
1 parent f9c408e commit 6aefeff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions doc/syntax.page
Original file line number Diff line number Diff line change
Expand Up @@ -1136,9 +1136,9 @@ As the wording suggests, inline links provide all information inline in the text
style links only provide the link text in the text flow and everything else is defined
elsewhere. This also allows you to reuse link definitions.

An inline style link can be created by surrounding the link text which must contain at least one
character with square brackets, followed immediately by the link URL (and an optional title in
single or double quotes preceded by at least one space) in normal parentheses. For example:
An inline style link can be created by surrounding the link text with square brackets, followed
immediately by the link URL (and an optional title in single or double quotes preceded by at least
one space) in normal parentheses. For example:

This is [a link](http://rubyforge.org) to a page.
A [link](../test "local URI") can also have a title.
Expand All @@ -1150,6 +1150,8 @@ Notes:
However, if you use square brackets within the link text, you have to either properly nest them or
to escape them. It is not possible to create nested links!

The link text may also be omitted, e.g. for creating link anchors.

* The link URL has to contain properly nested parentheses if no title is specified, or the link URL
must be contained in angle brackets (incorrectly nested parentheses are allowed).

Expand Down Expand Up @@ -1222,9 +1224,8 @@ used on them to specify additional attributes for the links:

Images can be specified via a syntax that is similar to the one used by links. The difference is
that you have to use an exclamation mark before the first square bracket and that the link text of a
normal link, which may also be the empty string in case of image links, becomes the alternative text
of the image link. As with normal links, image links can be written inline or reference style. For
example:
normal link becomes the alternative text of the image link. As with normal links, image links can be
written inline or reference style. For example:

Here comes a ![smiley](../images/smiley.png)! And here
![too](../images/other.png 'Title text'). Or ![here].
Expand Down
2 changes: 1 addition & 1 deletion lib/kramdown/parser/kramdown/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def parse_link
count = count + (@src[1] ? -1 : 1)
count - el.children.select {|c| c.type == :img}.size == 0
end
if !found || (link_type == :a && el.children.empty?)
unless found
@src.revert_pos(saved_pos)
add_text(result)
return
Expand Down
2 changes: 1 addition & 1 deletion test/testcases/span/01_link/empty.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

<p>This is [][] empty.</p>

<p>This is [](test.html) empty.</p>
<p>This is <a href="test.html"></a> empty.</p>

0 comments on commit 6aefeff

Please sign in to comment.