jekyll-webawesome 0.5.1 → 0.5.3

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: 5f88821b94fa1042ddd81efc46e15e35eb4b0c53f1159ccba1f92f171bf3b498
4
- data.tar.gz: a10ad10f3477bbbe7da32eab5b9faaab0ef202e94aa6369ee28936ae52017d19
3
+ metadata.gz: 229fd8aa9734c6c6c21684d05420d80db94b6b5a271f1dc2d8b901773bc61d3a
4
+ data.tar.gz: 373f57b7afbcfe0cccc2857f20987d91c1433768f3d0257773da9d7b3018f7f6
5
5
  SHA512:
6
- metadata.gz: 78af1fefc803ab19f6da488775df860d49c0f7855afdec3ed9e2a8794b5e4261914bbd169ad275be7094a8aa10656c36c0ce6a3db88021544ffd6e7b81b2c47f
7
- data.tar.gz: 9bb145b074f07b779f0fec449d3b24c2c7727a7fd55e9cdeb1697460a8d0214bf6052d84ce0a2686a0b4e2c83264c1a0137cfdb71e20eef204d4d6febfe7cf5d
6
+ metadata.gz: 4f76a3acdd6417715ed2a928a94705f99b402a843f2cfa74b30ab4b0f9b632fe90182fac3d50aa18780d98ce260e6c7de460a5b3dd565cc45ea534e89aaaaa4d
7
+ data.tar.gz: d68c37818e5ae0a20f9ff236914110f163bc775374dde1c886baa210231c1a50596aaabd1ae6357c4bdbe3667385678a669a22b9ef04c72a1273135566187797
data/CHANGELOG.md CHANGED
@@ -8,6 +8,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
8
8
 
9
9
  - Placeholder
10
10
 
11
+ ## [0.5.3] - 2025-10-20
12
+
13
+ - Always have a header with X button on the dialogs
14
+
15
+ ## [0.5.2] - 2025-10-20
16
+
17
+ - Fix the image dialog auto-transformation feature protection again
18
+
11
19
  ## [0.5.1] - 2025-10-20
12
20
 
13
21
  - Image dialog auto-transformation feature fix: protect comparison components
data/README.md CHANGED
@@ -387,16 +387,6 @@ Click outside to close this dialog.
387
387
  ???
388
388
  ```
389
389
 
390
- **Without Header** - Remove the dialog header entirely:
391
-
392
- ```markdown
393
- ???without-header
394
- Open Dialog
395
- >>>
396
- This dialog has no header.
397
- ???
398
- ```
399
-
400
390
  **Custom Width** - Set a specific width using CSS units (px, em, rem, vw, vh, %):
401
391
 
402
392
  ```markdown
@@ -428,15 +418,9 @@ Open Dialog
428
418
  # Custom Dialog
429
419
  This dialog has light dismiss enabled and is 700px wide.
430
420
  ???
431
-
432
- ???without-header light-dismiss 45em
433
- Open Simple Dialog
434
- >>>
435
- This dialog has no header, light dismiss, and is 45em wide.
436
- ???
437
421
  ```
438
422
 
439
- > **Note**: The dialog uses Web Awesome's declarative `data-dialog` API, so no custom JavaScript is needed. Each dialog gets a unique ID automatically generated from its content, and a close button is automatically added to the footer.
423
+ > **Note**: The dialog uses Web Awesome's declarative `data-dialog` API, so no custom JavaScript is needed. Each dialog gets a unique ID automatically generated from its content. The header with X close button is always shown for accessibility, and a "Close" button is automatically added to the footer.
440
424
 
441
425
  ### Details/Summary (Collapsible Content)
442
426
 
@@ -621,12 +605,12 @@ Cards automatically parse content into these slots:
621
605
  | Option | Description |
622
606
  |--------|-------------|
623
607
  | `light-dismiss` | Dialog closes when clicking outside/on overlay |
624
- | `without-header` | Removes the dialog header entirely |
625
608
  | Width (e.g., `500px`, `50vw`, `40em`) | Sets custom width using CSS units (px, em, rem, vw, vh, %) |
626
609
 
627
610
  ### Dialog Features
628
611
 
629
612
  - **Automatic ID Generation**: Each dialog gets a unique ID based on MD5 hash of its content
613
+ - **Header with X Button**: The header with X close button is always shown for accessibility
630
614
  - **Auto-close Button**: A "Close" button is automatically added to the footer
631
615
  - **Declarative API**: Uses Web Awesome's `data-dialog` attributes - no custom JavaScript needed
632
616
  - **Label Extraction**: First `#` heading becomes the dialog label, or button text is used as fallback
@@ -8,7 +8,8 @@ module Jekyll
8
8
  # Transforms dialog syntax into wa-dialog elements with trigger buttons
9
9
  # Primary syntax: ???params\nbutton text\n>>>\ncontent\n???
10
10
  # Alternative syntax: :::wa-dialog params\nbutton text\n>>>\ncontent\n:::
11
- # Params: light-dismiss, without-header, and optional width (e.g., 500px, 50vw, 40em)
11
+ # Params: light-dismiss and optional width (e.g., 500px, 50vw, 40em)
12
+ # Note: Header with close X button is always enabled for accessibility
12
13
  class DialogTransformer < BaseTransformer
13
14
  def self.transform(content)
14
15
  # Define both regex patterns - capture parameter string, button text, and content
@@ -24,7 +25,7 @@ module Jekyll
24
25
  dialog_content = dialog_content.strip
25
26
 
26
27
  # Parse parameters
27
- light_dismiss, without_header, width = parse_parameters(params_string)
28
+ light_dismiss, width = parse_parameters(params_string)
28
29
 
29
30
  # Extract label from first heading or use button text
30
31
  label, content_without_label = extract_label(dialog_content, button_text)
@@ -37,7 +38,7 @@ module Jekyll
37
38
 
38
39
  # Build the dialog HTML
39
40
  build_dialog_html(dialog_id, button_text, label, content_html,
40
- light_dismiss, without_header, width)
41
+ light_dismiss, width)
41
42
  end
42
43
 
43
44
  # Apply both patterns
@@ -50,12 +51,11 @@ module Jekyll
50
51
 
51
52
  # Parse parameters from the params string
52
53
  def parse_parameters(params_string)
53
- return [false, false, nil] if params_string.nil? || params_string.strip.empty?
54
+ return [false, nil] if params_string.nil? || params_string.strip.empty?
54
55
 
55
56
  tokens = params_string.strip.split(/\s+/)
56
57
 
57
58
  light_dismiss = tokens.include?('light-dismiss')
58
- without_header = tokens.include?('without-header')
59
59
 
60
60
  # Look for width parameter (last token with CSS units)
61
61
  width = nil
@@ -66,10 +66,11 @@ module Jekyll
66
66
  end
67
67
  end
68
68
 
69
- [light_dismiss, without_header, width]
69
+ [light_dismiss, width]
70
70
  end
71
71
 
72
72
  # Extract label from first heading in content
73
+ # Always returns a label - uses heading if available, otherwise default_label
73
74
  def extract_label(content, default_label)
74
75
  # Check if content starts with a heading
75
76
  if content.match(/^#\s+(.+?)$/)
@@ -78,6 +79,7 @@ module Jekyll
78
79
  content_without_label = content.sub(/^#\s+.+?\n/, '').strip
79
80
  [label, content_without_label]
80
81
  else
82
+ # Use default label (button text) to ensure header is always shown
81
83
  [default_label, content]
82
84
  end
83
85
  end
@@ -90,13 +92,14 @@ module Jekyll
90
92
  end
91
93
 
92
94
  # Build the complete dialog HTML with trigger button
95
+ # Header with X close button is always enabled for accessibility
93
96
  def build_dialog_html(dialog_id, button_text, label, content_html,
94
- light_dismiss, without_header, width)
97
+ light_dismiss, width)
95
98
  # Build dialog attributes
96
99
  dialog_attrs = ["id='#{dialog_id}'"]
97
100
  # Escape both HTML and attribute characters for label
98
- dialog_attrs << "label='#{escape_attribute(escape_html(label))}'" unless without_header
99
- dialog_attrs << 'without-header' if without_header
101
+ # Header is always shown to provide the X close button
102
+ dialog_attrs << "label='#{escape_attribute(escape_html(label))}'"
100
103
  dialog_attrs << 'light-dismiss' if light_dismiss
101
104
 
102
105
  # Build style attribute for width if specified
@@ -10,8 +10,9 @@ module Jekyll
10
10
  # Example: ![Alt text](image.png "nodialog")
11
11
  class ImageDialogTransformer < BaseTransformer
12
12
  def self.transform(content)
13
- # First, protect inline code blocks and comparison blocks from transformation
14
- protected_content, code_blocks = protect_inline_code(content)
13
+ # First, protect code blocks, inline code, and comparison blocks from transformation
14
+ protected_content, fenced_code_blocks = protect_fenced_code_blocks(content)
15
+ protected_content, inline_code_blocks = protect_inline_code(protected_content)
15
16
  protected_content, comparison_blocks = protect_comparisons(protected_content)
16
17
 
17
18
  # Match markdown images: ![alt](url) or ![alt](url "title")
@@ -34,19 +35,40 @@ module Jekyll
34
35
  end
35
36
  end
36
37
 
37
- # Restore protected comparison blocks first, then inline code
38
+ # Restore protected blocks in reverse order
38
39
  result = restore_comparisons(result, comparison_blocks)
39
- restore_inline_code(result, code_blocks)
40
+ result = restore_inline_code(result, inline_code_blocks)
41
+ restore_fenced_code_blocks(result, fenced_code_blocks)
40
42
  end
41
43
 
42
44
  class << self
43
45
  private
44
46
 
47
+ # Protect fenced code blocks from transformation
48
+ def protect_fenced_code_blocks(content)
49
+ code_blocks = []
50
+ # Match both ``` and ~~~ style code blocks with optional language
51
+ protected = content.gsub(/^```.*?^```$|^~~~.*?^~~~$/m) do |match|
52
+ placeholder = "<!--IMAGE_DIALOG_FENCED_CODE_#{code_blocks.length}-->"
53
+ code_blocks << match
54
+ placeholder
55
+ end
56
+ [protected, code_blocks]
57
+ end
58
+
59
+ # Restore protected fenced code blocks
60
+ def restore_fenced_code_blocks(content, code_blocks)
61
+ code_blocks.each_with_index do |code, index|
62
+ content = content.gsub("<!--IMAGE_DIALOG_FENCED_CODE_#{index}-->", code)
63
+ end
64
+ content
65
+ end
66
+
45
67
  # Protect inline code from transformation
46
68
  def protect_inline_code(content)
47
69
  code_blocks = []
48
70
  protected = content.gsub(/`[^`]+`/) do |match|
49
- placeholder = "INLINE_CODE_#{code_blocks.length}"
71
+ placeholder = "<!--IMAGE_DIALOG_INLINE_CODE_#{code_blocks.length}-->"
50
72
  code_blocks << match
51
73
  placeholder
52
74
  end
@@ -56,27 +78,37 @@ module Jekyll
56
78
  # Restore protected inline code
57
79
  def restore_inline_code(content, code_blocks)
58
80
  code_blocks.each_with_index do |code, index|
59
- content = content.gsub("INLINE_CODE_#{index}", code)
81
+ content = content.gsub("<!--IMAGE_DIALOG_INLINE_CODE_#{index}-->", code)
60
82
  end
61
83
  content
62
84
  end
63
85
 
64
86
  # Protect comparison blocks from image transformation
87
+ # Must protect both markdown syntax (|||...|||) and already-transformed HTML
65
88
  def protect_comparisons(content)
66
89
  comparison_blocks = []
67
- # Match comparison blocks: <wa-comparison ...>...</wa-comparison>
68
- protected = content.gsub(/<wa-comparison[^>]*>.*?<\/wa-comparison>/m) do |match|
69
- placeholder = "COMPARISON_BLOCK_#{comparison_blocks.length}"
90
+
91
+ # First protect markdown comparison syntax: |||...|||
92
+ protected = content.gsub(/\|\|\|(\d+)?\n.*?\n\|\|\|/m) do |match|
93
+ placeholder = "<!--IMAGE_DIALOG_COMPARISON_#{comparison_blocks.length}-->"
94
+ comparison_blocks << match
95
+ placeholder
96
+ end
97
+
98
+ # Also protect already-transformed HTML comparison blocks: <wa-comparison ...>...</wa-comparison>
99
+ protected = protected.gsub(/<wa-comparison[^>]*>.*?<\/wa-comparison>/m) do |match|
100
+ placeholder = "<!--IMAGE_DIALOG_COMPARISON_#{comparison_blocks.length}-->"
70
101
  comparison_blocks << match
71
102
  placeholder
72
103
  end
104
+
73
105
  [protected, comparison_blocks]
74
106
  end
75
107
 
76
108
  # Restore protected comparison blocks
77
109
  def restore_comparisons(content, comparison_blocks)
78
110
  comparison_blocks.each_with_index do |block, index|
79
- content = content.gsub("COMPARISON_BLOCK_#{index}", block)
111
+ content = content.gsub("<!--IMAGE_DIALOG_COMPARISON_#{index}-->", block)
80
112
  end
81
113
  content
82
114
  end
@@ -88,7 +120,8 @@ module Jekyll
88
120
  width = extract_width_from_title(title)
89
121
 
90
122
  # Build dialog parameters
91
- params = %w[light-dismiss without-header]
123
+ # Always include header with X close button for accessibility
124
+ params = ['light-dismiss']
92
125
  params << width if width
93
126
  params_string = params.join(' ')
94
127
 
@@ -97,8 +130,10 @@ module Jekyll
97
130
  title_attr = title && !title.include?('nodialog') && !contains_width?(title) ? " title=\"#{title}\"" : ''
98
131
  button_content = "<img src=\"#{image_url}\" alt=\"#{alt_text}\" style=\"cursor: zoom-in; display: block; width: 100%; height: auto;\"#{title_attr} />"
99
132
 
100
- # Build the dialog content - full-size image
101
- dialog_content = "<img src=\"#{image_url}\" alt=\"#{alt_text}\" style=\"max-width: 100%; height: auto; display: block; margin: 0 auto;\" />"
133
+ # Build the dialog content with alt text as heading for the label
134
+ # Use alt text for the label, or "Image" as fallback if alt is empty
135
+ label_text = alt_text.empty? ? 'Image' : alt_text
136
+ dialog_content = "# #{label_text}\n\n<img src=\"#{image_url}\" alt=\"#{alt_text}\" style=\"max-width: 100%; height: auto; display: block; margin: 0 auto;\" />"
102
137
 
103
138
  # Use our custom dialog syntax that will be processed by DialogTransformer
104
139
  # Format: ???params\nbutton_content\n>>>\ndialog_content\n???
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module WebAwesome
5
- VERSION = '0.5.1'
5
+ VERSION = '0.5.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-webawesome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janne Waren