jekyll-l10n 1.3.16 → 1.4.1

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: e9b11bbd19ea0a06c6282c11b22319d49ec9a25060d7324d667e14c78f397881
4
- data.tar.gz: 0b7c89696c593e771c2694090d0fcebb4c9414a07fc2474f568c5d298953667b
3
+ metadata.gz: 1c8edcdac30ed6d89b587d914f1b8038ffd3b10a95a0e15cc43965dd915e39f2
4
+ data.tar.gz: 513218e1e01c3814a2f7130f60a6b35463d0836659ee13d85ae3d7c9a0aaf6c5
5
5
  SHA512:
6
- metadata.gz: fee23453215a6576799f774d9de4f94e870554b0c9fe9044ec7b0fd20477f20cb99d4d56d026005224774cdb4d332f0e493eb0bf8e8cf0750289a0028850fd8b
7
- data.tar.gz: 0ac080acebbd08f462ee480f771804890111603e94f9c17aae24a12ec7e7d984659096c64e513e7c34c535fc5c2f0d127dad9a6038704ca9f4107b0c6d110115
6
+ metadata.gz: 24586cc374d7ad819cbda298c98d9dc70438b60bc7afafcc6d695190bb62dc6294ddfd4bb02fb4f04c57c3231cea3fe12047dc9bdf3eb0de5390c6e4fb7a0970
7
+ data.tar.gz: f5f5bb5755c8354794fd81090c74c0519f06fb15c216cc1b9ba748e5837dcef7b7a05c324d5f67feef8c544884e17a936d492c76132ac26cb7f0d6f0bafa22e6
@@ -39,6 +39,7 @@ module Jekyll
39
39
  return nil unless extractable?(node)
40
40
 
41
41
  clone = node.dup
42
+ HtmlTextUtils.remove_code_blocks(clone)
42
43
  HtmlTextUtils.remove_block_elements(clone)
43
44
  HtmlTextUtils.remove_empty_icon_tags(clone)
44
45
 
@@ -147,9 +147,15 @@ module Jekyll
147
147
  "[HtmlTranslator] Translation: #{translation[0..truncate_length]}..."
148
148
  end
149
149
 
150
+ inject_translation_preserving_structure(parent, translation)
151
+ end
152
+
153
+ def inject_translation_preserving_structure(parent, translation)
154
+ preserved_blocks = parent.css('pre').map(&:dup)
150
155
  preserved_anchors = parent.css('.heading-anchor').map(&:dup)
151
156
  parent.children.each(&:remove)
152
157
  parent.inner_html = translation
158
+ preserved_blocks.each { |b| parent.add_child(b) }
153
159
  preserved_anchors.each { |a| parent.add_child(a) } if parent.css('.heading-anchor').empty?
154
160
  end
155
161
 
@@ -253,7 +259,8 @@ module Jekyll
253
259
 
254
260
  private :log_text_node_debug, :should_skip_translation?, :should_log_text_debug?,
255
261
  :apply_block_level_translation?, :select_block_translation,
256
- :find_content_element_ancestor, :log_translation_debug_info
262
+ :find_content_element_ancestor, :log_translation_debug_info,
263
+ :inject_translation_preserving_structure
257
264
  end
258
265
  end
259
266
  end
@@ -48,6 +48,22 @@ module Jekyll
48
48
  .gsub(''', "'")
49
49
  end
50
50
 
51
+ # Remove preformatted code blocks from a node.
52
+ #
53
+ # Removes all <pre> elements entirely. With highlighter: none in Jekyll config,
54
+ # fenced code blocks produce plain <pre><code> as direct children of content
55
+ # elements — no Rouge wrappers. Removing <pre> before extraction ensures raw
56
+ # code never appears in PO msgids.
57
+ #
58
+ # Must run before remove_block_elements_from_node so that <code> inside <pre>
59
+ # is gone before the general flattening pass.
60
+ #
61
+ # @param node [Nokogiri::XML::Node] Node to process (modified in place)
62
+ # @return [void]
63
+ def self.remove_code_blocks(node)
64
+ node.css('pre').each(&:remove)
65
+ end
66
+
51
67
  # Remove block-level elements from a cloned node.
52
68
  #
53
69
  # Replaces block-level element nodes with their children (flattening structure).
@@ -98,6 +114,7 @@ module Jekyll
98
114
  # @return [String] Extracted and normalized text
99
115
  def self.extract_with_inline_tags(node)
100
116
  clone = node.dup
117
+ remove_code_blocks(clone)
101
118
  remove_block_elements_from_node(clone)
102
119
  remove_empty_icon_tags(clone)
103
120
 
@@ -47,7 +47,7 @@ module Jekyll
47
47
  # node alone doesn't have a direct translation but the entire block does.
48
48
  #
49
49
  # Security consideration: Returns nil if the block contains protected elements
50
- # (script, style, pre tags) to prevent unsafe translation application.
50
+ # (script, style) to prevent unsafe translation application.
51
51
  #
52
52
  # @param node [Nokogiri::XML::Node] Text node being translated
53
53
  # @param text [String] Normalized text of the node
@@ -90,13 +90,11 @@ module Jekyll
90
90
 
91
91
  # Check if an element contains protected child elements that block translations.
92
92
  #
93
- # Protected elements (script, style, pre) cannot have their surrounding text
94
- # translated at the block level because:
95
- # * script/style: Security and functionality reasons (executable content)
96
- # * pre: Multi-line code blocks where translations break formatting
97
- #
98
- # This is a shared utility used by both HtmlTranslator and TranslationResolver
99
- # to ensure consistent protection of sensitive content across the codebase.
93
+ # Protected elements (script, style) cannot have their surrounding text
94
+ # translated at the block level for security and functionality reasons.
95
+ # <pre> is not protected here HtmlTextUtils.remove_code_blocks strips it
96
+ # before extraction so code content never reaches PO msgids, and
97
+ # HtmlTranslator preserves <pre> verbatim across translation injection.
100
98
  #
101
99
  # @param node [Nokogiri::XML::Node] Element to check
102
100
  # @return [Boolean] true if node contains protected elements, false otherwise
@@ -111,13 +109,12 @@ module Jekyll
111
109
  # doc = Nokogiri::HTML('<p><code>inline</code> text</p>')
112
110
  # para = doc.xpath('//p').first
113
111
  # TranslationResolver.contains_protected_elements?(para)
114
- # # => false (code is allowed, only script/style/pre are protected)
112
+ # # => false (code is allowed, only script/style are protected)
115
113
  def self.contains_protected_elements?(node)
116
114
  return false unless node.element?
117
115
 
118
- # Block block-level translation for script, style (security/functionality),
119
- # and pre (multi-line code blocks). These cannot be safely applied at block level.
120
- protected_elements = %w[script style pre]
116
+ # Block block-level translation for script and style (security/functionality).
117
+ protected_elements = %w[script style]
121
118
  node.children.any? { |child| child.element? && protected_elements.include?(child.name) }
122
119
  end
123
120
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-l10n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.16
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ReleaseBot