class Translatomatic::ResourceFile::Markdown
Markdown
resource file
Public Class Methods
extensions()
click to toggle source
(see Base.extensions
)
# File lib/translatomatic/resource_file/markdown.rb, line 9 def self.extensions %w[md] end
Public Instance Methods
save(target = path, options = {})
click to toggle source
(see Base#save
)
# File lib/translatomatic/resource_file/markdown.rb, line 14 def save(target = path, options = {}) if @doc add_created_by unless options[:no_created_by] html = @doc.to_html # convert html back to markdown markdown = ReverseMarkdown.convert(html, unknown_tags: :bypass) target.write(markdown.chomp) end end
Private Instance Methods
add_created_by()
click to toggle source
# File lib/translatomatic/resource_file/markdown.rb, line 26 def add_created_by @created_by ||= begin body = @doc.at('body') body.add_child("<p><i>#{created_by}</i></p>") end end
read_doc()
click to toggle source
# File lib/translatomatic/resource_file/markdown.rb, line 33 def read_doc # read markdown and convert to html markdown = read_contents(@path) if markdown.blank? empty_doc else html = Kramdown::Document.new(markdown).to_html # parse html with nokogiri doc = Nokogiri::HTML(html, &:noblanks) parse_error(doc.errors[0]) if doc.errors.present? doc end end