jekyll-webawesome 0.4.0 → 0.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 +4 -4
- data/CHANGELOG.md +4 -1
- data/lib/jekyll/webawesome/code_block_transformer.rb +49 -30
- data/lib/jekyll/webawesome/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b925e93ad2a43e360c982ac4fbc9c25ee0a0c4573039ecf2c182fa566377d60b
|
4
|
+
data.tar.gz: 32e0685f36e0c5a3532900ffb964aa15809ba2fb5fbc9d71240dba39d5612427
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53d88906164176d32ad025c073d410c8d585f782643e0e3372ae5da51daf1fd5c65519dc77a9dd952aff2870c2c3a6453d454cd858cacefa4f0b19b993466258
|
7
|
+
data.tar.gz: 9cc2f919be3f5513ca7269f5d9f9c722ab9cd386a78be5f9e1dd968ffd699e7edab43546c4b099d9ebb8fa55f41e5dfa79b30bc39fa9b446f8d0c00806fb18c2
|
data/CHANGELOG.md
CHANGED
@@ -6,7 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
-
|
9
|
+
## [0.4.1] - 2025-10-02
|
10
|
+
|
11
|
+
- Code blocks inside custom elements (wa-details, wa-callout, etc.) are now properly protected from markdown processing
|
12
|
+
- Previously, code blocks would be corrupted with HTML entities and extra `<p>` tags when nested inside custom elements
|
10
13
|
|
11
14
|
## [0.4.0] - 2025-09-29
|
12
15
|
|
@@ -48,38 +48,38 @@ module Jekyll
|
|
48
48
|
content.match?(callout_pattern) || content.match?(details_pattern) || content.match?(tabs_pattern)
|
49
49
|
end
|
50
50
|
|
51
|
-
#
|
52
|
-
|
51
|
+
# Protect all code blocks by converting them to placeholders
|
52
|
+
# This prevents markdown processing from corrupting code blocks inside custom elements
|
53
|
+
def protect_all_code_blocks(content)
|
53
54
|
counter = @@protected_blocks.size
|
54
55
|
|
55
|
-
# First pass: protect markdown code blocks that contain WebAwesome syntax
|
56
|
-
content = content.gsub(CODE_BLOCK_PATTERN) do |match|
|
57
|
-
language = Regexp.last_match(1)
|
58
|
-
code_content = Regexp.last_match(2).strip
|
59
|
-
|
60
|
-
# If this is a markdown code block containing WebAwesome syntax, protect it
|
61
|
-
if language && language.downcase == 'markdown' && contains_webawesome_syntax?(code_content)
|
62
|
-
placeholder = "<!--PROTECTED_WEBAWESOME_EXAMPLE_#{counter}-->"
|
63
|
-
@@protected_blocks[placeholder] = match
|
64
|
-
counter += 1
|
65
|
-
placeholder
|
66
|
-
else
|
67
|
-
match # Leave other code blocks for normal processing
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# Second pass: transform remaining code blocks normally
|
72
56
|
content.gsub(CODE_BLOCK_PATTERN) do |match|
|
73
|
-
|
74
|
-
|
57
|
+
placeholder = "<!--PROTECTED_CODE_BLOCK_#{counter}-->"
|
58
|
+
@@protected_blocks[placeholder] = match
|
59
|
+
counter += 1
|
60
|
+
placeholder
|
61
|
+
end
|
62
|
+
end
|
75
63
|
|
76
|
-
|
77
|
-
|
78
|
-
|
64
|
+
# Transform code blocks from markdown syntax to Jekyll highlight tags
|
65
|
+
# This should be called AFTER WebAwesome transformers have processed the content
|
66
|
+
def transform_code_blocks(content)
|
67
|
+
# Transform code blocks that were previously protected
|
68
|
+
@@protected_blocks.transform_values! do |match|
|
69
|
+
if match =~ CODE_BLOCK_PATTERN
|
70
|
+
language = Regexp.last_match(1)
|
71
|
+
code_content = Regexp.last_match(2).strip
|
72
|
+
|
73
|
+
if language && language.downcase != 'plain'
|
74
|
+
"{% highlight #{language} %}\n#{code_content}\n{% endhighlight %}"
|
75
|
+
else
|
76
|
+
match # Return original block if no language or 'plain'
|
77
|
+
end
|
79
78
|
else
|
80
|
-
match
|
79
|
+
match
|
81
80
|
end
|
82
81
|
end
|
82
|
+
content
|
83
83
|
end
|
84
84
|
|
85
85
|
# Restore protected WebAwesome example blocks after WaElementTransformer processing
|
@@ -101,23 +101,42 @@ module Jekyll
|
|
101
101
|
CodeBlockTransformer.clear_protected_blocks
|
102
102
|
end
|
103
103
|
|
104
|
-
|
104
|
+
# STEP 1: Protect all code blocks BEFORE any transformations (highest priority)
|
105
|
+
Jekyll::Hooks.register :documents, :pre_render, priority: 50 do |document|
|
106
|
+
next unless document.relative_path =~ /.*\.md$/i
|
107
|
+
next unless CodeBlockTransformer.transform_documents_enabled?(document.site)
|
108
|
+
|
109
|
+
puts "Jekyll::WebAwesome::CodeBlockTransformer protecting code blocks in document: #{document.relative_path}\n"
|
110
|
+
document.content = CodeBlockTransformer.protect_all_code_blocks(document.content)
|
111
|
+
end
|
112
|
+
|
113
|
+
Jekyll::Hooks.register :pages, :pre_render, priority: 50 do |page|
|
114
|
+
next unless page.relative_path =~ /.*\.md$/i
|
115
|
+
next unless CodeBlockTransformer.transform_pages_enabled?(page.site)
|
116
|
+
|
117
|
+
puts "Jekyll::WebAwesome::CodeBlockTransformer protecting code blocks in page: #{page.relative_path}\n"
|
118
|
+
page.content = CodeBlockTransformer.protect_all_code_blocks(page.content)
|
119
|
+
end
|
120
|
+
|
121
|
+
# STEP 2: Transform protected code blocks to Jekyll highlight syntax
|
122
|
+
# This happens AFTER WebAwesome transformers (priority 20) but BEFORE restoration
|
123
|
+
Jekyll::Hooks.register :documents, :pre_render, priority: 15 do |document|
|
105
124
|
next unless document.relative_path =~ /.*\.md$/i
|
106
125
|
next unless CodeBlockTransformer.transform_documents_enabled?(document.site)
|
107
126
|
|
108
|
-
puts "Jekyll::WebAwesome::CodeBlockTransformer
|
127
|
+
puts "Jekyll::WebAwesome::CodeBlockTransformer transforming code blocks in document: #{document.relative_path}\n"
|
109
128
|
document.content = CodeBlockTransformer.transform_code_blocks(document.content)
|
110
129
|
end
|
111
130
|
|
112
|
-
Jekyll::Hooks.register :pages, :pre_render, priority:
|
131
|
+
Jekyll::Hooks.register :pages, :pre_render, priority: 15 do |page|
|
113
132
|
next unless page.relative_path =~ /.*\.md$/i
|
114
133
|
next unless CodeBlockTransformer.transform_pages_enabled?(page.site)
|
115
134
|
|
116
|
-
puts "Jekyll::WebAwesome::CodeBlockTransformer
|
135
|
+
puts "Jekyll::WebAwesome::CodeBlockTransformer transforming code blocks in page: #{page.relative_path}\n"
|
117
136
|
page.content = CodeBlockTransformer.transform_code_blocks(page.content)
|
118
137
|
end
|
119
138
|
|
120
|
-
#
|
139
|
+
# STEP 3: Restore protected blocks after transformation (lowest priority)
|
121
140
|
Jekyll::Hooks.register :documents, :pre_render, priority: 10 do |document|
|
122
141
|
next unless document.relative_path =~ /.*\.md$/i
|
123
142
|
next unless CodeBlockTransformer.transform_documents_enabled?(document.site)
|