22
33module Jekyll
44 module SideBySideFilter
5+ def split_list_for_notes ( list_node )
6+ items = list_node . css ( '> li' )
7+ list_type = list_node . name
8+
9+ # Check if next sibling is a NOTE paragraph
10+ next_sibling = list_node . next_element
11+ has_note_following = next_sibling && next_sibling . text . strip . start_with? ( '[NOTE]' )
12+
13+ if has_note_following && items . length > 1
14+ # Split: all items except last go in one list, last item in its own list
15+ first_items = items [ 0 ..-2 ]
16+ last_item = items [ -1 ]
17+
18+ # Push the first group as one list
19+ first_list = "<#{ list_type } >#{ first_items . map ( &:to_s ) . join } </#{ list_type } >"
20+ @elements . push ( first_list )
21+
22+ # Push the last item as its own list (will pair with the NOTE)
23+ last_list = "<#{ list_type } >#{ last_item . to_s } </#{ list_type } >"
24+ @elements . push ( last_list )
25+ else
26+ # No NOTE following, push the entire list as-is
27+ @elements . push ( list_node . to_s )
28+ end
29+ end
30+
531 def side_by_side_with_subtitle ( input , mode , subtitle )
632 @doc = Nokogiri ::HTML ::DocumentFragment . parse ( input )
733 @elements = [ ]
834 @doc . children . each do |node |
9- @elements . push ( node . to_s )
35+ # For lists with footnotes, split before the item with [NOTE] reference
36+ if ( node . name == 'ul' || node . name == 'ol' ) && mode == 'comment'
37+ split_list_for_notes ( node )
38+ else
39+ @elements . push ( node . to_s )
40+ end
1041 end
1142 @result = '<table class="side-by-side"><tbody>'
1243 if mode == 'translation'
@@ -17,16 +48,24 @@ def side_by_side_with_subtitle(input, mode, subtitle)
1748 end
1849 end
1950 elsif mode == 'comment'
20- @comments = ''
2151 @opened = false
2252 @elements . select { |e | !e . strip . empty? } . each do |e |
2353 if e . slice! '[NOTE] '
24- @comments << e
54+ # Convert footnote references [^1] to styled markers
55+ e = e . gsub ( /\[ \^ (\d +)\] / , '<sup class="note-ref">\1</sup>' )
56+ # Output note immediately with the currently open row
57+ if @opened
58+ @result << %(<td>#{ e } </td></tr>)
59+ @opened = false
60+ end
2561 else
62+ # Convert footnote references [^1] to styled markers in content
63+ e = e . gsub ( /\[ \^ (\d +)\] / , '<sup class="note-ref">\1</sup>' )
64+ # Close any previously opened row with empty comment
2665 if @opened
27- @result << %(<td>#{ @comments } </td></tr>)
28- @comments = ''
66+ @result << %(<td></td></tr>)
2967 end
68+ # Open new row with this element
3069 if e . include? '<h1'
3170 @result << %(<tr><td>#{ e } #{ subtitle } </td>)
3271 else
@@ -35,6 +74,10 @@ def side_by_side_with_subtitle(input, mode, subtitle)
3574 @opened = true
3675 end
3776 end
77+ # Close any remaining open row
78+ if @opened
79+ @result << %(<td></td></tr>)
80+ end
3881 end
3982 @result << '</table></tbody>'
4083 return @result
0 commit comments