Class: Rubino::Documents::Converters::Json
- Inherits:
-
Object
- Object
- Rubino::Documents::Converters::Json
- Defined in:
- lib/rubino/documents/converters/json.rb
Overview
JSON -> Markdown: pretty-printed inside a “‘json fence (same as markitdown). On a parse error we fence the raw bytes verbatim rather than failing – the model still gets the content, just unprettified.
Instance Method Summary collapse
Instance Method Details
#accepts?(mime, path) ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/rubino/documents/converters/json.rb', line 16 def accepts?(mime, path) m = mime.to_s return true if m == "application/json" || m.end_with?("+json") File.extname(path.to_s).downcase == ".json" end |
#available? ⇒ Boolean
12 13 14 |
# File 'lib/rubino/documents/converters/json.rb', line 12 def available? true end |
#convert(path) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/rubino/documents/converters/json.rb', line 23 def convert(path) raw = File.read(path, encoding: "bom|utf-8") pretty = begin ::JSON.pretty_generate(::JSON.parse(raw)) rescue ::JSON::ParserError raw.strip end "```json\n#{pretty}\n```\n" end |