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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9afcf72aab91e0280ce7b14771e3b7ddd940e00093bec970feb0a5d4e0242e4d
|
|
4
|
+
data.tar.gz: 1b5229d2111d8e4b70518ea864863e79e7274c1c31d93f3e0658352ff7f78683
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ccc34ccf335efbbd8b9e7151ab3d116ef2163bb02897f267b884aaa69b2a04ebf09ea7ec1d099b18904bd0a379de93a5de616b58b268c58446bf7b73d4b516a
|
|
7
|
+
data.tar.gz: 286af1a67ed7b1e39be4a8abe206f2bad467ef241ac1bc7a0f794578772337741d560c51172efd370f86e78fc31e7dc836e9a519813b7d27fbfc8d8a7832a277
|
data/Gemfile.lock
CHANGED
|
@@ -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(
|
|
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(
|
|
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 = /(
|
|
133
|
-
chunks = html.split(
|
|
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
|
|
137
|
-
|
|
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
|
-
|
|
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
|