lib/kramdown/parser/kramdown/link.rb in kramdown-1.2.0 vs lib/kramdown/parser/kramdown/link.rb in kramdown-1.3.0
- old
+ new
@@ -20,11 +20,11 @@
# Parse the link definition at the current location.
def parse_link_definition
@src.pos += @src.matched_size
link_id, link_url, link_title = normalize_link_id(@src[1]), @src[2] || @src[3], @src[5]
- warning("Duplicate link ID '#{link_id}' - overwriting") if @link_defs[link_id]
+ warning("Duplicate link ID '#{link_id}' on line #{@src.current_line_number} - overwriting") if @link_defs[link_id]
@link_defs[link_id] = [link_url, link_title]
@tree.children << Element.new(:eob, :link_def)
true
end
define_parser(:link_definition, LINK_DEFINITION_START)
@@ -51,20 +51,21 @@
LINK_START = /!?\[(?=[^^])/
# Parse the link at the current scanner position. This method is used to parse normal links as
# well as image links.
def parse_link
+ start_line_number = @src.current_line_number
result = @src.scan(LINK_START)
reset_pos = @src.pos
link_type = (result =~ /^!/ ? :img : :a)
# no nested links allowed
if link_type == :a && (@tree.type == :img || @tree.type == :a || @stack.any? {|t,s| t && (t.type == :img || t.type == :a)})
add_text(result)
return
end
- el = Element.new(link_type)
+ el = Element.new(link_type, nil, nil, :location => start_line_number)
count = 1
found = parse_spans(el, LINK_BRACKET_STOP_RE) do
count = count + (@src[1] ? -1 : 1)
count - el.children.select {|c| c.type == :img}.size == 0