From 08585bc7e9696a9afbb91ec41aff9acda6b29085 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 6 Oct 2020 11:31:08 -0400 Subject: [PATCH] LibGemini: Improve rendering of
 blocks

For

    ```foo
    asdf
    jkl;
    ```bar

we would previously generate

    
foo
    f
    ;
    
```bar Now we generate
    asdf
    jkl;
    
* no longer cut off the first 3 characters on most lines. * don't include the closing ``` line in the output. in addition to omitting the '```', this also honors "Any text following the leading "```" of a preformat toggle line which toggles preformatted mode off MUST be ignored by clients." from the spec * ignore the alt text after the toggle-on text. the spec leaves it to the client what to do with that alt text, but it tends to be metadata, and omitting it is simplest for the implementation, so do that. Improves ascii art on many gemini pages, e.g. gemini://carcosa.net/ --- Libraries/LibGemini/Document.cpp | 1 + Libraries/LibGemini/Line.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGemini/Document.cpp b/Libraries/LibGemini/Document.cpp index 028b538c4b..fcf57d4d10 100644 --- a/Libraries/LibGemini/Document.cpp +++ b/Libraries/LibGemini/Document.cpp @@ -74,6 +74,7 @@ void Document::read_lines(const StringView& source) } else { m_lines.append(make(Control::PreformattedEnd)); } + continue; } if (m_inside_preformatted_block) { diff --git a/Libraries/LibGemini/Line.cpp b/Libraries/LibGemini/Line.cpp index 9ce48fba14..d663184b2c 100644 --- a/Libraries/LibGemini/Line.cpp +++ b/Libraries/LibGemini/Line.cpp @@ -127,7 +127,7 @@ String Link::render_to_html() const String Preformatted::render_to_html() const { StringBuilder builder; - builder.append(escape_html_entities(m_text.substring_view(3, m_text.length() - 3))); + builder.append(escape_html_entities(m_text)); builder.append("\n"); return builder.build();