Skip to content

(bug): Markdown's like breaks are not properly rendered

Markdown supports a line break which is achievable by using two spaces at the end of the line followed by a return.

Example

This is the first line
This is the following line

These types of line breaks are ignored and the content is rendered as a single line.

Example issue

https://gitlab.com/ck3g/playground/-/issues/7

Web view CLI view
Screenshot_2023-01-10_at_12.08.04 Screenshot_2023-01-10_at_12.08.16

Checklist

  • I'm using the latest version of the extension (Run glab --version)
    • Extension version: glab version 1.23.1-58-ga0d0ed7c (2023-01-10)
  • Operating System and version: macOS Ventura 13.1

Summary

Steps to reproduce

  • Create an issue with line breaks (two spaces followed by a return)
  • View the issue using CLI app

What is the current bug behavior?

Renders different lines as a single line

What is the expected correct behavior?

Every line should be a separate line

Possible fixes

The bug comes from the glamour package used to render Markdown in CLI applications.

It's a known issue https://github.com/charmbracelet/glamour/issues/84, but since it's almost 3 years old, the fix is probably not a priority.

One of the ways is to fix the bug in the glamour package (or goldmark which glamour uses to parse the markdown).

As an alternative quick fix, we can try to fix the GitLab CLI, by turning line breaks into paragraphs by replacing \n with \n\n. That's not entirely the same because there would be extra spacing, but at least it separates the lines.

Example
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index 3c0e568f..840a941b 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -43,6 +43,7 @@ func renderMarkdown(text string, opts MarkdownRenderOpts) (string, error) {
        // Glamour rendering preserves carriage return characters in code blocks, but
        // we need to ensure that no such characters are present in the output.
        text = strings.ReplaceAll(text, "\r\n", "\n")
+       text = strings.ReplaceAll(text, "  \n", "\n\n")
 
        tr, err := glamour.NewTermRenderer(opts...)
        if err != nil {

Screenshot_2023-01-10_at_12.24.23

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information