asciidoctor-dot-leader 1.0.0 → 1.1.0

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: d9a25c3ac68e342ade564fce5f6ae421fb3ba5da8ebec4584682cf6b5c2f0202
4
- data.tar.gz: 3883b7986da82e541f1a7dcdf029dc077489906a3ad303e33140ca2f98696d1a
3
+ metadata.gz: cafcd588c3080dba97a8b811c9a230f83623fa27e1d1449f471d6f93428ef6f9
4
+ data.tar.gz: 2b784579fa0453fef3dc0fd1d1d735e31889f9dce3227294225da08064de3300
5
5
  SHA512:
6
- metadata.gz: 671510acec6229d3d54dfb4b9255c307a9141e70d307e3db369ca40773ac4d1f5bc880def7f0d3bc506251a42886956660e5a7535b0743e7e42d98adffaf0e96
7
- data.tar.gz: 4a21802b05620af76b340504cd1d9951430a0502c4e1f77769c04a76cafc7ee86b26b1163e91fc4525082e2cc74e9223dd0f8bb30780a74a41d2084c16d4772b
6
+ metadata.gz: 78bb767ee1ea9560346744da1285c95ba72f26f8787f6843b10e046d9ccc575ef607c29d556bc2c7f53ff4bc0b38ed965aa93ab6164d9a597cc811fe1e6de34f
7
+ data.tar.gz: c7c1e40de2398e37458e1da098fa669b2fb8881a2505ad821a0fbe75d65f0a1591661d9f0333d79ab0e877d09c3a18314a6a590d0e2c9ba3861bf546480c80cc
data/CHANGELOG.adoc ADDED
@@ -0,0 +1,37 @@
1
+ = Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on https://keepachangelog.com/en/1.0.0/[Keep a Changelog],
6
+ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Versioning].
7
+
8
+ == [1.1.0] - 2025-10-31
9
+
10
+ === Fixed
11
+
12
+ This release fixes alignment and width calculation issues for the pdf version:
13
+
14
+ * All positioning uses a universal grid based on absolute page coordinates which ensures all dot leaders align vertically across all block types
15
+ * Fixed width calculation for roles, such as `.small` and `.big`, by using fragment-specific font sizes
16
+
17
+ == [1.0.0] - 2025-07-20
18
+
19
+ === Added
20
+
21
+ Initial release of the asciidoctor-dot-leader extension with these features:
22
+
23
+ * Initial release of the asciidoctor-dot-leader extension
24
+ * Supports the PDF backend via asciidoctor-pdf
25
+ * Supports the HTML5 backend
26
+ * Inline macro syntax: `dot:leader["left", "right"]`
27
+ * Supports formatted text in left and right fragments
28
+ * Handles inline images, superscript, and subscript
29
+
30
+ === Features
31
+
32
+ Key capabilities of the extension:
33
+
34
+ * Dot leader generation between left and right text
35
+ * Configurable dot leader appearance via theme
36
+ * Support for complex inline formatting
37
+ * Compatible with multiple Asciidoctor backends
data/README.adoc CHANGED
@@ -1,14 +1,16 @@
1
- = AsciiDoctor Dot Leader Inline Macro
1
+ = Asciidoctor Dot Leader Inline Macro
2
2
 
3
3
  This project provides an inline macro which `pass:[dot:leader["left", "right"]]` which inserts leaders between the values.
4
4
 
5
5
  Dot . . . . . . . . . . . . . . . . . . . . . . . . Leaders
6
6
 
7
+ **Current Version:** 1.1.0 | link:CHANGELOG.adoc[View Changelog]
8
+
7
9
  It currently supports three backends:
8
10
 
9
- * AsciiDoctor (Ruby) - `backend-html5`
10
- * AsciiDoctor-PDF (Ruby) - `backend-pdf`
11
- * AsciiDoctor.js - `backend-webview-html5` - See <<asciidoctor-js-dot-leader>>
11
+ * Asciidoctor (Ruby) - `backend-html5`
12
+ * Asciidoctor-PDF (Ruby) - `backend-pdf`
13
+ * Asciidoctor.js - `backend-webview-html5` - See <<asciidoctor-js-dot-leader>>
12
14
 
13
15
  .PDF
14
16
  image:resources/images/example-pdf-adoc-formatted.png[]
@@ -16,7 +18,7 @@ image:resources/images/example-pdf-adoc-formatted.png[]
16
18
  .HTML5
17
19
  image:resources/images/example-html5-roles.png[]
18
20
 
19
- .AsciiDoctor.js
21
+ .Asciidoctor.js
20
22
  image:resources/images/example-webview-html5-inline-passthroughs.png[]
21
23
 
22
24
  == Markup And Usage _Manual_
@@ -27,26 +29,52 @@ Markup examples, rendered output examples, and extensive compatibility informati
27
29
  * link:dot_leader_example.html[]
28
30
  * Or clone the project and open the link:dot_leader_example.adoc[] file with Visual Studio Code's Asciidoc's preview window.
29
31
 
30
- == Todo
32
+ == Asciidoctor and Asciidoctor-PDF (Ruby) Installation and Usage
31
33
 
32
- There are a few items which need fixing:
34
+ The asciidoctor-dot-leader is available as a Ruby Gem.
33
35
 
34
- * PDF
35
- ** [ ] Upload gem to rubygems.org
36
- * HTML5
37
- ** [ ] Include .css automatically?
38
- * webview-html5 (Asciidoctor.js) for Microsoft Visual Studio Code and possibly others
39
- ** [ ] Release on npm
36
+ https://rubygems.org/gems/asciidoctor-dot-leader[^]
37
+
38
+ Complete these steps to use:
39
+
40
+ . Install the required Gems:
41
+ +
42
+ [source]
43
+ ----
44
+ gem install asciidoctor
45
+ gem install asciidoctor-dot-leader
46
+ ----
47
+ +
48
+ . Render the document:
49
+ +
50
+ [source]
51
+ ----
52
+ asciidoctor -r asciidoctor-dot-leader dot_leader_example.adoc
53
+ ----
54
+ +
55
+ . [For PDF] Install Asciidoctor-PDF:
56
+ +
57
+ [source]
58
+ ----
59
+ gem install asciidoctor-pdf
60
+ ----
61
+ +
62
+ . [For PDF] Render the PDF:
63
+ +
64
+ [source]
65
+ ----
66
+ asciidoctor-pdf -r asciidoctor-dot-leader dot_leader_example.adoc
67
+ ----
40
68
 
41
- == Ruby GEM Build Instructions (for 白一百 baiyibai)
69
+ === Ruby GEM Build Instructions (for 白一百 baiyibai)
42
70
 
43
71
  ```
44
72
  gem build asciidoctor-dot-leader.gemspec
45
- gem install ./asciidoctor-dot-leader-1.0.0.gem
73
+ gem install ./asciidoctor-dot-leader-1.1.0.gem
46
74
  ```
47
75
 
48
76
  [#asciidoctor-js-dot-leader]
49
- == AsciiDoctor.js Dot Leader Inline Macro
77
+ == Asciidoctor.js Dot Leader Inline Macro
50
78
 
51
79
  This project provides an inline macro, `pass:[dot:leader["left", "right"]]`, which inserts dot leaders between the provided values.
52
80
 
@@ -83,6 +111,14 @@ module.exports = require('../../asciidoctorjs-extension/dot_leader.js')
83
111
  .. Enable the Asciidoc > Extensions: *Register Workspace Extensions* option.
84
112
  . Open a document containing `pass:[dot:leader[]]` inline macros, and press the _Preview_ button.
85
113
 
114
+ == Todo
115
+
116
+ There are a few items which need fixing:
117
+
118
+ * HTML5
119
+ ** [ ] Include .css automatically?
120
+ * webview-html5 (Asciidoctor.js) for Microsoft Visual Studio Code and possibly others
121
+ ** [ ] Release on npm
86
122
 
87
123
  == Copyright
88
124
 
@@ -1,6 +1,6 @@
1
1
  # dot_leader_pdf.rb 2025-07-20 白一百 baiyibai
2
2
  # https://gitlab.com/baiyibai/asciidoctor-pdf-dot-leader
3
- # This inline macro uses AsciiDoctor-PDF's ToC generation code as a jumping off point, but departs from it.
3
+ # This inline macro uses Asciidoctor-PDF's ToC generation code as a jumping off point, but departs from it.
4
4
  # Use '':dot-leader-scale: 0.6' to set the document-wide factor
5
5
  require 'asciidoctor-pdf' unless defined? ::Asciidoctor::Converter::PdfConverter
6
6
  class DotLeader < (Asciidoctor::Converter.for 'pdf')
@@ -9,7 +9,8 @@ class DotLeader < (Asciidoctor::Converter.for 'pdf')
9
9
  def rendered_width_of_fragments(fragments, scale, roles = [])
10
10
  fragments.sum do |fragment|
11
11
  styles = fragment[:styles] || Set.new
12
- size = font_size
12
+ # Use fragment's size if specified (for roles like .small, .big), otherwise use current font size
13
+ size = fragment[:size] || font_size
13
14
  size *= scale if styles.include?(:subscript) || styles.include?(:superscript)
14
15
  font_style = if styles.include?(:bold) && styles.include?(:italic)
15
16
  :bold_italic
@@ -152,19 +153,76 @@ class DotLeader < (Asciidoctor::Converter.for 'pdf')
152
153
  # NOTE: the same font is used for dot leaders throughout toc
153
154
  set_font toc_font_info[:font], dot_leader[:font_size]
154
155
  font_style dot_leader[:font_style]
155
- # 2025-07-17 BYB: Add support for Multiple Columns https://asciidoctor.zulipchat.com/#narrow/channel/288690-users.2Fasciidoctor-pdf/topic/Implicit.20page.20break.20after.20column_box
156
- if node.parent.parent.attributes['columns']
157
- start_dots = start_dots - bounds.left
158
- end
159
- num_dots = [((bounds.width - start_dots - dot_leader[:spacer_width] - right_side_width) / dot_leader[:width]).floor, 0].max
160
- # FIXME: dots don't line up in columns if width of page numbers differ # BYB: Original
156
+ # For true vertical alignment, dots must be at consistent absolute positions across all lines
157
+ # Calculate the absolute position from page margin for universal grid alignment
158
+ # This ensures dots align across tables, lists, and other indented contexts
159
+
160
+ # Get the absolute position where dots will start
161
+ # start_dots is in local bounds coordinates, convert to absolute page coordinates
162
+ start_dots_absolute = start_dots + bounds.absolute_left
163
+
164
+ # Use the page's left margin as the grid origin for universal alignment
165
+ # In a normal flow at the top level, bounds.absolute_left equals the page margin
166
+ # Use a reference from the document's margin settings
167
+ page_margin_left = page.margins[:left]
168
+
169
+ # Calculate the position relative to the page margin for grid alignment
170
+ start_dots_from_page_margin = start_dots_absolute - page_margin_left
171
+
172
+ # Find the first grid position after the left text ends
173
+ # Grid positions are at multiples of dot_leader[:width] from the page margin
174
+ first_dot_grid_index = (start_dots_from_page_margin / dot_leader[:width]).ceil
175
+ first_dot_position_absolute = page_margin_left + (first_dot_grid_index * dot_leader[:width])
176
+
177
+ # Convert back to the local bounds coordinate system for rendering
178
+ first_dot_position = first_dot_position_absolute - bounds.absolute_left
179
+
180
+ # Check if the first dot is too close to the left text
181
+ # Calculate the actual left text width for precise spacing check
182
+ left_text_width = rendered_width_of_fragments left_side_fragments, scale, node.roles.to_a
183
+ space_after_left_text = first_dot_position - left_text_width
184
+
185
+ dot_stripped = dot_leader[:text].rstrip
186
+ dot_stripped_width = rendered_width_of_string dot_stripped
187
+
188
+ # Calculate where the right text will start (in absolute coordinates)
189
+ right_text_start_local = bounds.width - right_side_width - dot_leader[:spacer_width]
190
+ right_text_start_absolute = right_text_start_local + bounds.absolute_left
191
+
192
+ # Find the last grid position before the right text starts (using global grid)
193
+ # Ensure the COMPLETE dot (start + width) fits before right text
194
+ right_text_from_page_margin = right_text_start_absolute - page_margin_left
195
+
196
+ # Calculate the last grid index where a complete dot would fit
197
+ # A dot at position N has its right edge at N + dot_leader[:width]
198
+ # The target: (last_dot_grid_index * dot_leader[:width]) + dot_leader[:width] <= right_text_from_page_margin
199
+ # Simplified: last_dot_grid_index <= (right_text_from_page_margin / dot_leader[:width]) - 1
200
+ # Add some buffer space to ensure the dot does not touch the right text
201
+ last_possible_dot_end = right_text_from_page_margin - (1.0 * dot_stripped_width)
202
+ last_dot_grid_index = (last_possible_dot_end / dot_leader[:width]).floor
203
+
204
+ # Calculate the number of dots that fit on the grid between left and right text
205
+ num_dots = [last_dot_grid_index - first_dot_grid_index + 1, 0].max
206
+
207
+ # Calculate the indent to position the first dot at the correct grid position
208
+ dot_indent = first_dot_position
209
+
161
210
  fragment_positions = []
162
211
  right_side_fragments.each do |fragment|
163
212
  fragment_positions << (fragment_position = ::Asciidoctor::PDF::FormattedText::FragmentPositionRenderer.new)
164
213
  (fragment[:callback] ||= []) << fragment_position
165
214
  end
215
+
216
+ # Render the dots with a proper indent to align to the grid
217
+ indent dot_indent, 0 do
218
+ typeset_formatted_text [
219
+ { text: dot_leader[:text] * num_dots, color: dot_leader[:font_color] }
220
+ ], line_metrics, align: :left
221
+ end
222
+
223
+ # Move cursor back to render right text
224
+ move_cursor_to start_cursor
166
225
  typeset_formatted_text [
167
- { text: dot_leader[:text] * num_dots, color: dot_leader[:font_color] },
168
226
  dot_leader[:spacer],
169
227
  *right_side_fragments.map { |fragment|
170
228
  fragment.dup.tap do |f|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-dot-leader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 白一百 baiyibai
@@ -30,6 +30,7 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
+ - CHANGELOG.adoc
33
34
  - LICENSE
34
35
  - README.adoc
35
36
  - lib/asciidoctor-dot-leader.rb