Class: Canon::PrettyPrinter::Html
- Inherits:
-
Object
- Object
- Canon::PrettyPrinter::Html
- Defined in:
- lib/canon/pretty_printer/html.rb
Overview
Pretty printer for HTML with consistent indentation.
Two modes:
-
Default mode (+fixture_ready: false+): retains the existing behaviour for callers that use the pretty-printer as a structural normaliser (the canon round-trip tests, the diff-pipeline
apply_pretty_printstage, etc). These callers do not require actual indentation; they require structural equivalence to the input. -
Fixture-ready mode (+fixture_ready: true+): emits actually-indented XHTML-shaped output via libxml’s
FORMATsave flag. Used by DiffFormatter#prettyprint_for_display (the CANON_<FORMAT>_DIFF_SHOW_PRETTYPRINT_RECEIVED surface) so the user can read or paste the formatted output directly into a fixture heredoc. Output is XHTML-shaped (void elements self-closed, non-void paired) via theAS_XHTMLsave flag; theNO_DECLARATIONflag suppresses the <?xml …?> prefix.
See lutaml/canon#133, lutaml/canon#135.
Instance Method Summary collapse
- #format(html_string) ⇒ Object
-
#initialize(indent: 2, indent_type: "space", fixture_ready: false) ⇒ Html
constructor
A new instance of Html.
Constructor Details
#initialize(indent: 2, indent_type: "space", fixture_ready: false) ⇒ Html
Returns a new instance of Html.
32 33 34 35 36 |
# File 'lib/canon/pretty_printer/html.rb', line 32 def initialize(indent: 2, indent_type: "space", fixture_ready: false) @indent = indent.to_i @indent_type = indent_type @fixture_ready = fixture_ready end |
Instance Method Details
#format(html_string) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/canon/pretty_printer/html.rb', line 38 def format(html_string) return format_fixture_ready(html_string) if @fixture_ready if xhtml?(html_string) format_as_xhtml(html_string) else format_as_html(html_string) end end |