Skip to content

Conversation

@ksss
Copy link
Contributor

@ksss ksss commented Dec 3, 2025

In the documentation for methods like test, backtick are used within table cells.
While each parser handles backquotes within table cells, the generator does not.
As a result, the tags are displayed literally without being processed.

To resolve this, I propose that tag expressions should be properly handled within table cells as well.

Before

ri --format=bs test

 Character  |Test
------------|---------------------------------------------------------------
<tt>'<'</tt>|Whether the `mtime` at `path0` is less than that at `path1`.
<tt>'='</tt>|Whether the `mtime` at `path0` is equal to that at `path1`.
<tt>'>'</tt>|Whether the `mtime` at `path0` is greater than that at `path1`.

ri --format=markdown test

 Character  |Test
------------|---------------------------------------------------------------
<tt>'<'</tt>|Whether the `mtime` at `path0` is less than that at `path1`.
<tt>'='</tt>|Whether the `mtime` at `path0` is equal to that at `path1`.
<tt>'>'</tt>|Whether the `mtime` at `path0` is greater than that at `path1`.

ri --format=ansi

image

After

ri --format=bs test

Character|Test
---------|---------------------------------------------------------------
   '<'   |Whether the `mtime` at `path0` is less than that at `path1`.
   '='   |Whether the `mtime` at `path0` is equal to that at `path1`.
   '>'   |Whether the `mtime` at `path0` is greater than that at `path1`.

ri --format=markdown test

Character|Test
---------|---------------------------------------------------------------
  `'<'`  |Whether the `mtime` at `path0` is less than that at `path1`.
  `'='`  |Whether the `mtime` at `path0` is equal to that at `path1`.
  `'>'`  |Whether the `mtime` at `path0` is greater than that at `path1`.

ri --format=ansi

image

@ksss ksss requested a deployment to fork-preview-protection December 3, 2025 07:39 — with GitHub Actions Waiting
Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Can we improve alignment in ri --format=ansi? It seems that we should not count invisible ANSI escape characters for width.

@ksss ksss mentioned this pull request Dec 3, 2025
@ksss
Copy link
Contributor Author

ksss commented Dec 3, 2025

@kou
You are absolutely right.
How can I implement ToAnsi#accept_table?

@tompng
Copy link
Member

tompng commented Dec 3, 2025

I think RDoc::Markup::ToRdoc can have a method like calculate_text_width(text) and use it in accept_table.

widths = header.zip(*body).map do |cols|
  cols.map(&:size).max # Use `calculate_text_width instead of size
end
...
# a is :rjust | :ljust | :center, w is width
t.__send__(a, w)

t.__send__(a, w + calculate_text_width(t) - t.size)

And each formatter can override it if it needs special width calculation logic.

ToRDoc#calculate_text_width

Simply return text.size for now. Maybe there's a room for improvement in the future such as treating some multibyte character as 2-width.

ToAnsi#calculate_text_width

Remove escape sequences before calculating width

ToBs#calculate_text_width

I think ToBS also need another custom width calculation logic.
"<b>dd</b>" becomes "d\bdd\bd" and its width should be 2.
"d" backspace "d" will print "d" twice in the same position. (Printing a character to a paper by ink twice makes the text darker/bold)

@ksss
Copy link
Contributor Author

ksss commented Dec 5, 2025

@tompng
Thank you for your wonderful suggestion!
I also learned about the BS format, which I was unaware of.
I have reimplemented it using the proposed method and updated the description.

@ksss ksss deployed to fork-preview-protection December 5, 2025 01:59 — with GitHub Actions Active
@matzbot
Copy link
Collaborator

matzbot commented Dec 5, 2025

🚀 Preview deployment available at: https://4ba19a13.rdoc-6cd.pages.dev (commit: 45a8180)

Copy link
Member

@tompng tompng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

@tompng tompng merged commit d51bfc0 into ruby:master Dec 5, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants