Class: Yard::Fence::KramdownGfmDocument
- Inherits:
-
Kramdown::Document
- Object
- Kramdown::Document
- Yard::Fence::KramdownGfmDocument
- Defined in:
- lib/yard/fence/kramdown_gfm_document.rb,
sig/yard/fence.rbs
Constant Summary collapse
- UNRENDERED_FENCE_PARAGRAPH =
From implementation: stores original source and forces GFM input by default
/<p>```/- DETAILS_MARKDOWN_1 =
/<details[^>]*markdown=["']1["'][^>]*>/i
Instance Method Summary collapse
- #fallback_improved?(fb_html) ⇒ Boolean
-
#initialize(source, options = {}) ⇒ KramdownGfmDocument
constructor
A new instance of KramdownGfmDocument.
- #needs_fallback?(html) ⇒ Boolean
-
#to_html ⇒ String
Public API.
Constructor Details
#initialize(source, options = {}) ⇒ KramdownGfmDocument
Returns a new instance of KramdownGfmDocument.
26 27 28 29 30 |
# File 'lib/yard/fence/kramdown_gfm_document.rb', line 26 def initialize(source, = {}) [:input] = "GFM" unless .key?(:input) @__yard_fence_source = source # Keep original for potential fallback. super end |
Instance Method Details
#fallback_improved?(fb_html) ⇒ Boolean
62 63 64 65 |
# File 'lib/yard/fence/kramdown_gfm_document.rb', line 62 def fallback_improved?(fb_html) fb_html.match?(UNRENDERED_FENCE_PARAGRAPH) == false && fb_html.include?("<pre") && fb_html.include?("<code") end |
#needs_fallback?(html) ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/yard/fence/kramdown_gfm_document.rb', line 51 def needs_fallback?(html) # Obvious failure: raw fenced code rendered as a paragraph return true if html.match?(UNRENDERED_FENCE_PARAGRAPH) # Edge case: details wrapper present in source but output lacks any code block if @__yard_fence_source.match?(DETAILS_MARKDOWN_1) has_code_block = html.include?("<pre") && html.include?("<code") return !has_code_block end false end |
#to_html ⇒ String
Public API
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/yard/fence/kramdown_gfm_document.rb', line 36 def to_html html = super return html if ENV["YARD_FENCE_DISABLE_FALLBACK"] == "1" return html unless @__yard_fence_source.include?("```") if needs_fallback?(html) = @options.merge(input: "kramdown") fb_html = Kramdown::Document.new(@__yard_fence_source, ).to_html return fb_html if fallback_improved?(fb_html) end html end |