Skip to content

Commit ca63d41

Browse files
committed
🐛 Fixing markdown => HTML conversion
1 parent e07c1fa commit ca63d41

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
direnv 2.32.2
2-
ruby 3.4.5
2+
ruby 3.4.7

.yard_gfm_support.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,24 @@ def initialize(source, options = {})
1111
end
1212
end
1313

14+
# Ensure YARD is loaded before modifying its constants
15+
require 'yard' unless defined?(YARD)
16+
1417
# Insert the new provider as the highest priority option for Markdown.
1518
# See:
1619
# - https://github.com/lsegal/yard/issues/1157
1720
# - https://github.com/lsegal/yard/issues/1017
1821
# - https://github.com/lsegal/yard/blob/main/lib/yard/templates/helpers/markup_helper.rb
19-
YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown].insert(
20-
0,
21-
{const: "KramdownGfmDocument"},
22-
)
22+
require 'yard/templates/helpers/markup_helper'
23+
24+
providers = YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown]
25+
providers.unshift({lib: :kramdown, const: :KramdownGfmDocument})
26+
27+
# Normalize provider entries to what YARD expects (const must be a String)
28+
providers.each do |provider|
29+
const = provider[:const]
30+
provider[:const] = const.to_s if const.is_a?(Symbol)
31+
end
32+
33+
# De-duplicate entries by [lib, const]
34+
providers.uniq! { |p| [p[:lib], p[:const].to_s] }

docs/.nojekyll

Whitespace-only changes.

docs/CNAME

Lines changed: 0 additions & 1 deletion
This file was deleted.

test_gfm.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env ruby
2+
require 'bundler/setup'
3+
require 'yard'
4+
require 'yard/templates/helpers/markup_helper'
5+
6+
puts "Before loading .yard_gfm_support.rb:"
7+
YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown].each_with_index do |p, i|
8+
puts " [#{i}] #{p.inspect}"
9+
end
10+
11+
require './.yard_gfm_support.rb'
12+
13+
puts "\nAfter loading .yard_gfm_support.rb:"
14+
YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown].each_with_index do |p, i|
15+
puts " [#{i}] #{p.inspect}"
16+
end
17+
18+
puts "\nTesting KramdownGfmDocument:"
19+
20+
test_md = <<-MD
21+
# Test
22+
23+
```ruby
24+
puts "hello"
25+
```
26+
MD
27+
28+
doc = KramdownGfmDocument.new(test_md)
29+
html = doc.to_html
30+
puts html
31+
puts "\nDoes output contain <pre>? #{html.include?('<pre>')}"
32+
puts "Does output contain <code>? #{html.include?('<code')}"

0 commit comments

Comments
 (0)