Class: Ace::Lint::Atoms::KramdownParser
- Inherits:
-
Object
- Object
- Ace::Lint::Atoms::KramdownParser
- Defined in:
- lib/ace/lint/atoms/kramdown_parser.rb
Overview
Pure function to parse markdown with kramdown
Class Method Summary collapse
-
.format(content, options: {}) ⇒ Hash
Format markdown content with kramdown.
-
.format_kramdown_message(warning) ⇒ Object
Kramdown warnings are already formatted strings.
-
.parse(content, options: {}) ⇒ Hash
Parse markdown content with kramdown.
Class Method Details
.format(content, options: {}) ⇒ Hash
Format markdown content with kramdown
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ace/lint/atoms/kramdown_parser.rb', line 51 def self.format(content, options: {}) parse_result = parse(content, options: ) return {success: false, formatted_content: nil, errors: parse_result[:errors]} unless parse_result[:success] begin # Convert back to markdown formatted = parse_result[:document].to_kramdown { success: true, formatted_content: formatted, errors: [] } rescue => e { success: false, formatted_content: nil, errors: ["Kramdown formatting error: #{e.}"] } end end |
.format_kramdown_message(warning) ⇒ Object
Kramdown warnings are already formatted strings
75 76 77 |
# File 'lib/ace/lint/atoms/kramdown_parser.rb', line 75 def self.(warning) warning.to_s end |
.parse(content, options: {}) ⇒ Hash
Parse markdown content with kramdown
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ace/lint/atoms/kramdown_parser.rb', line 15 def self.parse(content, options: {}) # Minimal defaults - let kramdown use its defaults # Users can override via .ace/lint/config.yml = { input: "GFM" # Use GitHub Flavored Markdown } = .merge() begin document = Kramdown::Document.new(content, ) # Kramdown collects warnings during parsing (as strings) # All warnings are informational, not errors warnings = document.warnings || [] { success: true, # Kramdown warnings don't indicate parsing failure document: document, errors: [], warnings: warnings } rescue => e { success: false, document: nil, errors: ["Kramdown parsing error: #{e.}"], warnings: [] } end end |