Skip to content

Conversation

@sascha-wolf
Copy link
Contributor

Issue

This PR introduces markdown quote block handling in IO.ANSI.Docs, for blocks such as this:

> first line of quote
> second line of __quote__
> third line of `quote`

Before this a quote was simply rendered as text which lead to the above quote looking like this:

> first line of quote > second line of quote > third line of quote

An example of this in the Elixir codebase can be seen in Access (link to code). Which got rendered like this in iex:

image

Solution

Instead of defining a specific quote style (such as doc_quote) - which clashes with inline styling of text - this solution instead renders the quote's content in an ASCII-art box. As such the quote from above would be rendered like this:

+----------------------+
| first line of quote  |
| second line of quote |
| third line of quote  |
+----------------------+

With this change the quote from Access now gets rendered like this:

image

@josevalim
Copy link
Member

Thank you @sascha-wolf!

Generally speaking, we try to render IO.ANSI as close to the original markup as possible, so I think we can render it as:

> first line of quote
> second line of quote
> third line of quote

Can you please adjust the code accordingly? Thank you.

@sascha-wolf
Copy link
Contributor Author

Sure thing!

Now the formatting uses leading `>` instead of boxing the quote:

    > first line
    > second line
To differentiate it from "regular" text the leading `> ` character is
formatted according to the `doc_quote` setting which is set to
light_black for the time being.
@sascha-wolf
Copy link
Contributor Author

sascha-wolf commented Jan 3, 2020

I've updated the code to render quotes with a leading > ; to differentiate them from regular text the > is being styled according to the doc_quote setting which - for now - is set to light_black.

The end result looks like this:

image

@josevalim the quote retains the lines as originally written in markdown. It would also be possible to wrap the lines using the same logic as write_text - when I look at various markdown there seems to be no "standard" (e.g. GitHub retains line breaks, StackOverflow removes them).

According to Babelmark 2 most renderers just pop the content into a p tag but retain line breaks which renders without line breaks.

What do you think?

@josevalim
Copy link
Member

Let’s use write_text because the lines originally written may be too short or too long!

@sascha-wolf
Copy link
Contributor Author

@josevalim I've updated the code to wrap the lines for quotes. The result now looks like this for Access:

image

@sascha-wolf
Copy link
Contributor Author

I'll also extend the rendering to respect empty lines for quotes.

@sascha-wolf
Copy link
Contributor Author

@josevalim from my perspective everything is ready to go. 🙂

@ericmj ericmj merged commit f0fbf02 into elixir-lang:master Jan 5, 2020
@ericmj
Copy link
Member

ericmj commented Jan 5, 2020

Thank you @sascha-wolf!

@sascha-wolf sascha-wolf deleted the fix/docs/ansi/render-quotes-properly branch October 18, 2021 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants