Class: Rubino::Documents::Converters::Xml

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/documents/converters/xml.rb

Overview

XML -> Markdown: pretty-printed inside a “‘xml fence (markitdown does the same for generic XML). Uses stdlib REXML, which ships with Ruby; if pretty-printing fails we fence the raw bytes. SVG is deliberately NOT handled here – Classify routes SVG to :text, never :document.

Instance Method Summary collapse

Instance Method Details

#accepts?(mime, path) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/rubino/documents/converters/xml.rb', line 15

def accepts?(mime, path)
  m = mime.to_s
  return false if m == "image/svg+xml"
  return true if m == "application/xml" || m == "text/xml" || m.end_with?("+xml")

  File.extname(path.to_s).downcase == ".xml"
end

#available?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/rubino/documents/converters/xml.rb', line 11

def available?
  true
end

#convert(path) ⇒ Object



23
24
25
26
27
# File 'lib/rubino/documents/converters/xml.rb', line 23

def convert(path)
  raw = File.read(path, encoding: "bom|utf-8")
  pretty = pretty_print(raw) || raw.strip
  "```xml\n#{pretty}\n```\n"
end