lib/kramdown/converter/kramdown.rb in kramdown-1.5.0 vs lib/kramdown/converter/kramdown.rb in kramdown-1.6.0
- old
+ new
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
#
#--
-# Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at>
+# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
#
# This file is part of kramdown which is licensed under the MIT.
#++
#
-require 'rexml/parsers/baseparser'
+require 'kramdown/converter'
+require 'kramdown/utils'
module Kramdown
module Converter
@@ -278,21 +279,21 @@
@linkrefs << el
@linkrefs.size
end
"[#{inner(el, opts)}][#{index}]"
else
- title = el.attr['title'].to_s.empty? ? '' : ' "' + el.attr['title'].gsub(/"/, """) + '"'
+ title = parse_title(el.attr['title'])
"[#{inner(el, opts)}](#{el.attr['href']}#{title})"
end
end
def convert_img(el, opts)
- alt_text = el.attr['alt'].gsub(ESCAPED_CHAR_RE) { $1 ? "\\#{$1}" : $2 }
+ alt_text = el.attr['alt'].to_s.gsub(ESCAPED_CHAR_RE) { $1 ? "\\#{$1}" : $2 }
if el.attr['src'].empty?
"![#{alt_text}]()"
else
- title = (el.attr['title'] ? ' "' + el.attr['title'].gsub(/"/, """) + '"' : '')
+ title = parse_title(el.attr['title'])
link = if el.attr['src'].count("()") > 0
"<#{el.attr['src']}>"
else
el.attr['src']
end
@@ -367,12 +368,12 @@
def create_link_defs
res = ''
res << "\n\n" if @linkrefs.size > 0
@linkrefs.each_with_index do |el, i|
- title = el.attr['title']
- res << "[#{i+1}]: #{el.attr['href']}#{title ? ' "' + title.gsub(/"/, """) + '"' : ''}\n"
+ title = parse_title(el.attr['title'])
+ res << "[#{i+1}]: #{el.attr['href']}#{title}\n"
end
res
end
def create_footnote_defs
@@ -387,10 +388,11 @@
def create_abbrev_defs
return '' unless @root.options[:abbrev_defs]
res = ''
@root.options[:abbrev_defs].each do |name, text|
res << "*[#{name}]: #{text}\n"
+ res << ial_for_element(Element.new(:unused, nil, @root.options[:abbrev_attr][name])).to_s << "\n\n"
end
res
end
# Return the IAL containing the attributes of the element +el+.
@@ -411,9 +413,13 @@
res = "toc" << (res.strip.empty? ? '' : " #{res}") if (el.type == :ul || el.type == :ol) &&
(el.options[:ial][:refs].include?('toc') rescue nil)
res = "footnotes" << (res.strip.empty? ? '' : " #{res}") if (el.type == :ul || el.type == :ol) &&
(el.options[:ial][:refs].include?('footnotes') rescue nil)
res.strip.empty? ? nil : "{:#{res}}"
+ end
+
+ def parse_title(attr)
+ attr.to_s.empty? ? '' : ' "' + attr.gsub(/"/, '"') + '"'
end
# :startdoc:
end