Skip to content

Commit 7262050

Browse files
committed
More work at undoing comments that should be viewable in the HTML when extracting examples.
1 parent 93a83a8 commit 7262050

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

common/extract-examples.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
329329
# Remove (faked) XML comments and unescape sequences
330330
content = script_content
331331
.inner_html
332-
.sub(/^\s*< !--/, '')
333-
.sub(/-- >\s*$/, '')
332+
.sub(/^\s*< !\s*-\s*-/, '')
333+
.sub(/-\s*- >\s*$/, '')
334334
.gsub(/&lt;/, '<')
335335
end
336336

@@ -443,7 +443,10 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
443443
# Set argument to referenced content to be parsed
444444
args[0] = if examples[ex[:result_for]][:ext] == 'html' && method == :expand
445445
# If we are expanding, and the reference is HTML, find the first script element.
446-
doc = Nokogiri::HTML.parse(examples[ex[:result_for]][:content])
446+
doc = Nokogiri::HTML.parse(
447+
examples[ex[:result_for]][:content]
448+
.sub(/^\s*< !\s*-\s*-/, '')
449+
.sub(/-\s*- >\s*$/, ''))
447450

448451
# Get base from document, if present
449452
html_base = doc.at_xpath('/html/head/base/@href')
@@ -457,12 +460,13 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
457460
end
458461
StringIO.new(script_content
459462
.inner_html
460-
.sub(/^\s*< !--/, '')
461-
.sub(/-- >\s*$/, '')
462463
.gsub(/&lt;/, '<'))
463464
elsif examples[ex[:result_for]][:ext] == 'html' && ex[:target]
464465
# Only use the targeted script
465-
doc = Nokogiri::HTML.parse(examples[ex[:result_for]][:content])
466+
doc = Nokogiri::HTML.parse(
467+
examples[ex[:result_for]][:content]
468+
.sub(/^\s*< !\s*-\s*-/, '')
469+
.sub(/-\s*- >\s*$/, ''))
466470
script_content = doc.at_xpath(xpath)
467471
unless script_content
468472
errors << "Example #{ex[:number]} at line #{ex[:line]} references example #{ex[:result_for].inspect} with no JSON-LD script element"
@@ -471,8 +475,6 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
471475
end
472476
StringIO.new(script_content
473477
.to_html
474-
.sub(/^\s*< !--/, '')
475-
.sub(/-- >\s*$/, '')
476478
.gsub(/&lt;/, '<'))
477479
else
478480
StringIO.new(examples[ex[:result_for]][:content])

0 commit comments

Comments
 (0)