Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manpage converter removes spaces in literal block #3583

Closed
ggrossetie opened this issue Feb 24, 2020 · 6 comments
Closed

Manpage converter removes spaces in literal block #3583

ggrossetie opened this issue Feb 24, 2020 · 6 comments
Assignees
Labels
area/manpage Issues related to manual pages and the manpage converter bug compliance v2.0.23 Issues resolved in the 2.0.23 release
Milestone

Comments

@ggrossetie
Copy link
Member

Consider the following manpage that contains a literal block (ASCII art):

= eve(1)
Andrew Stanton
v1.0.0
:doctype: manpage
:manmanual: EVE
:mansource: EVE
:man-linkstyle: pass:[blue R < >]

== Name

eve - analyzes an image to determine if it's a picture of a life form

== Synopsis

....
     ,---.          ,-----.
     |Bob|          |Alice|
     `-+-'          `--+--'
       |    hello      |   
       |-------------->|   
     ,-+-.          ,--+--.
     |Bob|          |Alice|
     `---'          `-----'
....
$ ./bin/asciidoctor eve.adoc -b manpage
$ man ./eve.1
EVE(1)

NAME
       eve - analyzes an image to determine if it's a picture of a life form

SYNOPSIS

                ,---. ,-----.
                |Bob|          |Alice|
                `-+-'          `--+--'
                  |    hello      |
                  |-------------->|
                ,-+-. ,--+--.
                |Bob|          |Alice|
                `---'          `-----'
@graphitefriction graphitefriction added the area/manpage Issues related to manual pages and the manpage converter label Apr 9, 2021
@mojavelinux
Copy link
Member

I'm unaware of how to do this in groff. This post seems to provide some hints https://unix.stackexchange.com/questions/481343/embed-ascii-diagram-in-groff, though it didn't seem to work for me when I tried it.

@mojavelinux mojavelinux added this to the unscheduled milestone Oct 19, 2021
@0-issue
Copy link

0-issue commented Dec 29, 2023

The solution here is simple, asciidoctor should just escape spaces. Just doing that seems to work for all ASCII art.

For RGB hex colors, asciidoctor should consider providing a way for user to specify groff defines, I mean embedding raw groff code, just like you have ways for users to embed html/css content.

@mojavelinux
Copy link
Member

For RGB hex colors, asciidoctor should consider providing a way for user to specify groff defines, I mean embedding raw groff code, just like you have ways for users to embed html/css content.

If this is something you want, you can create a custom inline macro (or some other type of extension). I don't want to introduce raw groff code into AsciiDoc. That's outside the scope of this language.

@g-branden-robinson
Copy link

I'm unaware of how to do this in groff. This post seems to provide some hints https://unix.stackexchange.com/questions/481343/embed-ascii-diagram-in-groff, though it didn't seem to work for me when I tried it.

That didn't work because it was an example for the ms macro package, not the man macro package. If you have groff installed, you can read the man pages for each of these, groff_ms(7) and groff_man(7).

What you want for "ASCII art" in a man page is to turn filling off and select a monospaced font. The EX and EE macros enter and leave this mode.

I will quote their descriptions from groff_man_style(7), including a paragraph of user advice.

     .EX
     .EE    Begin and end example.  After .EX, filling is disabled and a
            constant‐width (monospaced) font is selected.  Calling .EE
            enables filling and restores the previous font.

            Example regions are useful for formatting code, shell
            sessions, and text file contents.  An example region is not
            a “literal mode” of any sort: special character escape
            sequences must still be used to produce correct glyphs for
            ', -, \, ^, `, and ~ (see subsection “Portability” below).
            Sentence endings are still detected and additional inter‐
            sentence space applied.  If the amount of additional inter‐
            sentence spacing is altered, the rendering of, for instance,
            regular expressions using . or ? followed by multiple spaces
            can change.  Use the dummy character escape sequence \&
            before the spaces.

It will be important to keep those rules in mind when generating man output if you want to support fully general ASCII art. Also don't forget that a control character . or ' is still specially recognized by a roff formatter at the start of an input line; the EX macro does not shut that off.

You can find an example of ASCII art in one of groff's own man pages, that for soelim(1).

@mojavelinux
Copy link
Member

mojavelinux commented May 16, 2024

Use the dummy character escape sequence & before the spaces.

It appears that what fixes it is to introduce \& before a run of more than one space in the literal content. This works without any other changes to the generated markup. That seems like a reasonable fix to make.

(What's strange is that it doesn't seem to be needed in every instance, though it doesn't hurt to use it in every instance).

@mojavelinux mojavelinux self-assigned this May 16, 2024
@mojavelinux mojavelinux modified the milestones: unscheduled, v2.0.x May 16, 2024
mojavelinux added a commit to mojavelinux/asciidoctor that referenced this issue May 16, 2024
@g-branden-robinson
Copy link

Use the dummy character escape sequence & before the spaces.

It appears that what fixes it is to introduce \& before a run of more than one space in the literal content. This works without any other changes to the generated markup. That seems like a reasonable fix to make.

(What's strange is that it doesn't seem to be needed in every instance, though it doesn't hurt to use it in every instance).

Looking at the commit, it appears that what you're observing is use of the dummy character escape sequence after a period. Like TeX, *roff programs attempt to detect boundaries between sentences, and the period, question mark, and exclamation mark are all sentence-ending punctuation, so the formatter enters a special interpretation state when encountering them at the end of a word.

https://www.gnu.org/software/groff/manual/groff.html.node/Sentences.html

It is indeed harmless to include \& before a run of more than one space in exhibits like this, so your fix looks good to me.

@mojavelinux mojavelinux added the v2.0.23 Issues resolved in the 2.0.23 release label May 16, 2024
mojavelinux added a commit that referenced this issue May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/manpage Issues related to manual pages and the manpage converter bug compliance v2.0.23 Issues resolved in the 2.0.23 release
Projects
None yet
Development

No branches or pull requests

5 participants