jekyll-ai-visible-content 0.4.7 → 0.4.8

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: 70c2a75f924f17bb54ccd80796dc0da7f6ee26aeed7e7dc8555be88ad95c2497
4
- data.tar.gz: c13846d123a0e9a81e3d4cea3bd31a5e81b9af24885e704cf5a8c586fd4220f9
3
+ metadata.gz: 9afcf72aab91e0280ce7b14771e3b7ddd940e00093bec970feb0a5d4e0242e4d
4
+ data.tar.gz: 1b5229d2111d8e4b70518ea864863e79e7274c1c31d93f3e0658352ff7f78683
5
5
  SHA512:
6
- metadata.gz: 388b85f05e6b0e3ac72f7c09f3e278c6505c0a640c6e307882c57e7de9716eb6671dd9534102f4a77aa32c41cc54a71d9578f52158ce5263a0af00f23a21a11a
7
- data.tar.gz: fc73eef2bf48aa2867e6c146f56644f6962c104f079cbd4bf02c512f8ba047809823bcacab390b9f77b1e278ecad5b9a1aec56040c2bae21c5629be236991f10
6
+ metadata.gz: 0ccc34ccf335efbbd8b9e7151ab3d116ef2163bb02897f267b884aaa69b2a04ebf09ea7ec1d099b18904bd0a379de93a5de616b58b268c58446bf7b73d4b516a
7
+ data.tar.gz: 286af1a67ed7b1e39be4a8abe206f2bad467ef241ac1bc7a0f794578772337741d560c51172efd370f86e78fc31e7dc836e9a519813b7d27fbfc8d8a7832a277
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-ai-visible-content (0.4.7)
4
+ jekyll-ai-visible-content (0.4.8)
5
5
  jekyll (>= 4.0, < 5.0)
6
6
 
7
7
  GEM
@@ -78,7 +78,10 @@ module JekyllAiVisibleContent
78
78
  apply_to_metadata = config.linking['apply_to_metadata'] == true
79
79
 
80
80
  if apply_to_metadata
81
- Jekyll.logger.warn('ai_visible_content', 'linking.apply_to_metadata=true may inject HTML into metadata fields')
81
+ Jekyll.logger.warn(
82
+ 'ai_visible_content',
83
+ 'linking.apply_to_metadata=true may inject HTML into metadata fields'
84
+ )
82
85
  end
83
86
 
84
87
  doc.output = link_entities(
@@ -107,7 +110,7 @@ module JekyllAiVisibleContent
107
110
  def link_entities_in_body(html, definitions, max_per)
108
111
  return html unless html.include?('<body')
109
112
 
110
- html.sub(/<body\b[^>]*>.*<\/body>/im) do |body_fragment|
113
+ html.sub(%r{<body\b[^>]*>.*</body>}im) do |body_fragment|
111
114
  replace_entities_in_fragment(body_fragment, definitions, max_per)
112
115
  end
113
116
  end
@@ -129,19 +132,35 @@ module JekyllAiVisibleContent
129
132
  end
130
133
 
131
134
  def replace_entity_outside_anchor(html, name, max_per, link_html)
132
- pattern = /(?<=\s|>)#{Regexp.escape(name)}(?=[\s,.<])/i
133
- chunks = html.split(%r{(<a\b[^>]*>.*?</a>|<script\b[^>]*>.*?</script>|<style\b[^>]*>.*?</style>|<template\b[^>]*>.*?</template>)}im)
135
+ pattern = /(^|[\s>])(#{Regexp.escape(name)})(?=[\s,.<])/i
136
+ chunks = html.split(/(<[^>]+>)/m)
134
137
  replaced = 0
138
+ skip_text_replacement = false
135
139
 
136
- chunks.map!.with_index do |chunk, idx|
137
- next chunk if idx.odd?
140
+ chunks.map! do |chunk|
141
+ if chunk.start_with?('<')
142
+ opening_name = chunk[/\A<\s*([a-z0-9:-]+)/i, 1]&.downcase
143
+ closing_name = chunk[%r{\A<\s*/\s*([a-z0-9:-]+)}i, 1]&.downcase
138
144
 
139
- chunk.gsub(pattern) do |match|
145
+ if %w[a script style template].include?(opening_name) && chunk !~ %r{/\s*>\z}
146
+ skip_text_replacement = true
147
+ elsif %w[a script style template].include?(closing_name)
148
+ skip_text_replacement = false
149
+ end
150
+
151
+ next chunk
152
+ end
153
+
154
+ next chunk if skip_text_replacement
155
+
156
+ chunk.gsub(pattern) do
157
+ prefix = ::Regexp.last_match(1)
158
+ match = ::Regexp.last_match(2)
140
159
  if replaced < max_per
141
160
  replaced += 1
142
- link_html
161
+ "#{prefix}#{link_html}"
143
162
  else
144
- match
163
+ "#{prefix}#{match}"
145
164
  end
146
165
  end
147
166
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllAiVisibleContent
4
- VERSION = '0.4.7'
4
+ VERSION = '0.4.8'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-ai-visible-content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - madmatvey