@@ -329,8 +329,8 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
329
329
# Remove (faked) XML comments and unescape sequences
330
330
content = script_content
331
331
. inner_html
332
- . sub ( /^\s *< !- -/ , '' )
333
- . sub ( /-- >\s *$/ , '' )
332
+ . sub ( /^\s *< !\s *- \s * -/ , '' )
333
+ . sub ( /-\s * - >\s *$/ , '' )
334
334
. gsub ( /</ , '<' )
335
335
end
336
336
@@ -443,7 +443,10 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
443
443
# Set argument to referenced content to be parsed
444
444
args [ 0 ] = if examples [ ex [ :result_for ] ] [ :ext ] == 'html' && method == :expand
445
445
# 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 *$/ , '' ) )
447
450
448
451
# Get base from document, if present
449
452
html_base = doc . at_xpath ( '/html/head/base/@href' )
@@ -457,12 +460,13 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
457
460
end
458
461
StringIO . new ( script_content
459
462
. inner_html
460
- . sub ( /^\s *< !--/ , '' )
461
- . sub ( /-- >\s *$/ , '' )
462
463
. gsub ( /</ , '<' ) )
463
464
elsif examples [ ex [ :result_for ] ] [ :ext ] == 'html' && ex [ :target ]
464
465
# 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 *$/ , '' ) )
466
470
script_content = doc . at_xpath ( xpath )
467
471
unless script_content
468
472
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:)
471
475
end
472
476
StringIO . new ( script_content
473
477
. to_html
474
- . sub ( /^\s *< !--/ , '' )
475
- . sub ( /-- >\s *$/ , '' )
476
478
. gsub ( /</ , '<' ) )
477
479
else
478
480
StringIO . new ( examples [ ex [ :result_for ] ] [ :content ] )
0 commit comments