Class: Apex::Document
- Inherits:
-
Object
- Object
- Apex::Document
- Defined in:
- lib/apex/document.rb
Overview
High-level document API for Apex Markdown.
The primary entry point is Document.markdown_to_html, which mirrors the style of Kramdown::Document.new(text, options).to_html but uses a single convenient class method:
html = Apex::Document.markdown_to_html(text, mode: :unified)
You can also use the instance-level API if you prefer object instances that you can reuse:
doc = Apex::Document.new(text, mode: :gfm, enable_tables: true)
html = doc.to_html
Instance Attribute Summary collapse
-
#mode ⇒ Symbol, String
readonly
The selected Apex mode.
-
#options ⇒ Hash
readonly
Options passed on to the native Apex renderer.
-
#source ⇒ String
readonly
The original Markdown source.
Class Method Summary collapse
-
.markdown_to_html(source, mode: :unified, **options) ⇒ String
Render Markdown to HTML using Apex.
Instance Method Summary collapse
-
#initialize(source, mode: :unified, **options) ⇒ Document
constructor
Create a new document instance.
-
#to_html ⇒ String
Render this document to HTML.
Constructor Details
Instance Attribute Details
#mode ⇒ Symbol, String (readonly)
Returns the selected Apex mode.
42 43 44 |
# File 'lib/apex/document.rb', line 42 def mode @mode end |
#options ⇒ Hash (readonly)
Returns options passed on to the native Apex renderer.
45 46 47 |
# File 'lib/apex/document.rb', line 45 def @options end |
#source ⇒ String (readonly)
Returns the original Markdown source.
39 40 41 |
# File 'lib/apex/document.rb', line 39 def source @source end |
Class Method Details
.markdown_to_html(source, mode: :unified, **options) ⇒ String
Render Markdown to HTML using Apex.
33 34 35 36 |
# File 'lib/apex/document.rb', line 33 def self.markdown_to_html(source, mode: :unified, **) opts = { mode: mode }.merge() Apex::Native.markdown_to_html(String(source), opts) end |
Instance Method Details
#to_html ⇒ String
Render this document to HTML.
61 62 63 |
# File 'lib/apex/document.rb', line 61 def to_html self.class.markdown_to_html(@source, mode: @mode, **@options) end |