yard-fence 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0909353a8e193134a57cf571979c154be5c08adb0ce6c53855282996ea8d96de'
4
- data.tar.gz: 69400f31490fb97d56aa19a79519c7f15c160b689b48ca6d0228df640410655b
3
+ metadata.gz: dedaaa231c20409b1d4aedb72ac7b12c0716076eedea5375ed2a232999b2ea7b
4
+ data.tar.gz: f6b65e208d3fc7c9a0b19939949309e6020ad1808cb5378372ac0a6ef2511715
5
5
  SHA512:
6
- metadata.gz: e7e3af604e115d051dac3bb1763df43aeacdd693c947504ace79f8864f12e343ea54e065be3b3b13e55b4b29bc8d193fcb939c44fbcad3a6f0307df5c55dd06e
7
- data.tar.gz: 28c385b149403931cf456ad76223a33b12df2272fa47bcde51cfff31344e43b699227a7a10902f27e910beced70db24fd674b0831e2652ef7dc487669139ca78
6
+ metadata.gz: a5f0e3c15d75462209e1a717b762b137256aab58dfc44527008cf159458ed50fa47450ddb8355f0f2b006db3cff4f18ba9258ffc6f5542177c5921a2a2d42292
7
+ data.tar.gz: 81f406fdc8c3e399fa730ec7ab3790fa62981a96a02852abaaa8c0edca52cc8070cef89933407e142bc1e741a3f1e46cd933c369ade528cbf2f593c188d02b52
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -30,6 +30,17 @@ Please file a bug if you notice a violation of semantic versioning.
30
30
 
31
31
  ### Security
32
32
 
33
+ ## [0.6.0] - 2025-11-07
34
+
35
+ - TAG: [v0.6.0][0.6.0t]
36
+ - COVERAGE: 100.00% -- 119/119 lines in 4 files
37
+ - BRANCH COVERAGE: 100.00% -- 34/34 branches in 4 files
38
+ - 37.93% documented
39
+
40
+ ### Added
41
+
42
+ - Catch unrendered code blocks and attempt to convert to HTML
43
+
33
44
  ## [0.5.0] - 2025-11-07
34
45
 
35
46
  - TAG: [v0.5.0][0.5.0t]
@@ -94,7 +105,9 @@ Please file a bug if you notice a violation of semantic versioning.
94
105
 
95
106
  - Initial release
96
107
 
97
- [Unreleased]: https://github.com/galtzo-floss/yard-fence/compare/v0.5.0...HEAD
108
+ [Unreleased]: https://github.com/galtzo-floss/yard-fence/compare/v0.6.0...HEAD
109
+ [0.6.0]: https://github.com/galtzo-floss/yard-fence/compare/v0.5.0...v0.6.0
110
+ [0.6.0t]: https://github.com/galtzo-floss/yard-fence/releases/tag/v0.6.0
98
111
  [0.5.0]: https://github.com/galtzo-floss/yard-fence/compare/v0.4.0...v0.5.0
99
112
  [0.5.0t]: https://github.com/galtzo-floss/yard-fence/releases/tag/v0.5.0
100
113
  [0.4.0]: https://github.com/galtzo-floss/yard-fence/compare/v0.3.0...v0.4.0
data/README.md CHANGED
@@ -586,7 +586,7 @@ Thanks for RTFM. ☺️
586
586
  [📌gitmoji]: https://gitmoji.dev
587
587
  [📌gitmoji-img]: https://img.shields.io/badge/gitmoji_commits-%20%F0%9F%98%9C%20%F0%9F%98%8D-34495e.svg?style=flat-square
588
588
  [🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ
589
- [🧮kloc-img]: https://img.shields.io/badge/KLOC-0.098-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
589
+ [🧮kloc-img]: https://img.shields.io/badge/KLOC-0.119-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
590
590
  [🔐security]: SECURITY.md
591
591
  [🔐security-img]: https://img.shields.io/badge/security-policy-259D6C.svg?style=flat
592
592
  [📄copyright-notice-explainer]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year
@@ -12,14 +12,57 @@ require "kramdown-parser-gfm"
12
12
  module Yard
13
13
  module Fence
14
14
  class KramdownGfmDocument < Kramdown::Document
15
+ # Detects an unrendered fenced code block that slipped through HTML generation.
16
+ # Note on <details markdown="1">:
17
+ # - The classic kramdown parser honors the markdown="1" attribute on block HTML like <details>,
18
+ # and will parse contained markdown as block-level content.
19
+ # - The GFM parser generally handles many cases well, and markdown="1" may appear to work in
20
+ # most sections; however, we've observed edge cases where fenced code blocks inside a
21
+ # <details markdown="1"> are left as literal backticks (rendered as <p>``` …</p>).
22
+ # This fallback detects that situation and re-renders with the classic parser.
23
+ UNRENDERED_FENCE_PARAGRAPH = /<p>```/
24
+ DETAILS_MARKDOWN_1 = /<details[^>]*markdown=["']1["'][^>]*>/i
25
+
15
26
  def initialize(source, options = {})
16
27
  options[:input] = "GFM" unless options.key?(:input)
28
+ @__yard_fence_source = source # Keep original for potential fallback.
17
29
  super(source, options)
18
30
  end
31
+
32
+ # Override to_html to provide a smart fallback: if the GFM parse leaves literal
33
+ # fenced code markers (```), re-run the render with the classic 'kramdown' input which
34
+ # correctly evaluates markdown inside <details markdown="1"> blocks.
35
+ # Opt-out via ENV["YARD_FENCE_DISABLE_FALLBACK"] == "1".
36
+ def to_html
37
+ html = super
38
+ return html if ENV["YARD_FENCE_DISABLE_FALLBACK"] == "1"
39
+ return html unless @__yard_fence_source.include?("```")
40
+
41
+ if needs_fallback?(html)
42
+ fallback_options = @options.merge(input: "kramdown")
43
+ fb_html = Kramdown::Document.new(@__yard_fence_source, fallback_options).to_html
44
+ return fb_html if fallback_improved?(fb_html)
45
+ end
46
+ html
47
+ end
48
+
49
+ private
50
+
51
+ def needs_fallback?(html)
52
+ # Obvious failure: raw fenced code rendered as a paragraph
53
+ return true if html.match?(UNRENDERED_FENCE_PARAGRAPH)
54
+ # Edge case: details wrapper present in source but output lacks any code block
55
+ if @__yard_fence_source.match?(DETAILS_MARKDOWN_1)
56
+ has_code_block = html.include?("<pre") && html.include?("<code")
57
+ return !has_code_block
58
+ end
59
+ false
60
+ end
61
+
62
+ def fallback_improved?(fb_html)
63
+ fb_html.match?(UNRENDERED_FENCE_PARAGRAPH) == false &&
64
+ fb_html.include?("<pre") && fb_html.include?("<code")
65
+ end
19
66
  end
20
67
  end
21
68
  end
22
-
23
- # Note:
24
- # We intentionally do NOT auto-register here to avoid circular require warnings when
25
- # YARD is loading. Prefer calling Yard::Fence.use_kramdown_gfm! from your .yardopts.
@@ -3,7 +3,7 @@
3
3
  module Yard
4
4
  module Fence
5
5
  module Version
6
- VERSION = "0.5.0"
6
+ VERSION = "0.6.0"
7
7
  end
8
8
  VERSION = Version::VERSION
9
9
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-fence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter H. Boling
@@ -316,10 +316,10 @@ licenses:
316
316
  - MIT
317
317
  metadata:
318
318
  homepage_uri: https://yard-fence.galtzo.com/
319
- source_code_uri: https://github.com/galtzo-floss/yard-fence/tree/v0.5.0
320
- changelog_uri: https://github.com/galtzo-floss/yard-fence/blob/v0.5.0/CHANGELOG.md
319
+ source_code_uri: https://github.com/galtzo-floss/yard-fence/tree/v0.6.0
320
+ changelog_uri: https://github.com/galtzo-floss/yard-fence/blob/v0.6.0/CHANGELOG.md
321
321
  bug_tracker_uri: https://github.com/galtzo-floss/yard-fence/issues
322
- documentation_uri: https://www.rubydoc.info/gems/yard-fence/0.5.0
322
+ documentation_uri: https://www.rubydoc.info/gems/yard-fence/0.6.0
323
323
  funding_uri: https://github.com/sponsors/pboling
324
324
  wiki_uri: https://github.com/galtzo-floss/yard-fence/wiki
325
325
  news_uri: https://www.railsbling.com/tags/yard-fence
metadata.gz.sig CHANGED
Binary file