Skip to content

Add support for hard and soft line breaks #40

@NReilingh

Description

@NReilingh

Is your feature request related to a problem? Please describe.

It is extremely rare for console markdown renderers to handle hard and soft line breaks correctly. This appears to be because it is easy to overlook the detail of collapsible whitespace rendering that occurs in the browser. As Markdown is always specified as a transformation to HTML, the challenge of the console markdown renderer is thus to emulate the browser's text rendering behavior.

When contiguous spaces (non-&nbsp;) or linefeeds appear in raw HTML, they are always rendered as collapsed to a single space. This makes HTML compatible with the Semantic Line Break. Markdown (in the majority of its implementations, including CommonMark and GFM) is designed to be compatible with the semantic line break, offering two explicit syntax options for rendering hard line breaks (<br /> in HTML), with the collapsing-rendered soft line break being the implicit treatment.

Describe the solution you'd like

Markshell should emulate the browser's rendering of hard and soft line breaks as defined by the CommonMark spec.

Describe alternatives you've considered

The best workaround I've managed to come up (besides implementing my own console markdown renderer) with would involve rendering markdown to HTML and then using a terminal browser like Lynx to render the HTML to the console.

Additional context

Current behavior

Image

Expected behavior

commonmark.js demo

Image

Additional notes

I have known certain markdown documentation repositories, including Microsoft's GitHub-hosted PowerShell documentation, to enforce a per-line character limit, which necessitates the use of the semantic line break.

The CommonMark Spec indicates that the default behavior of a renderer will always output whitespace-collapsing HTML, but permits the renderer to offer an option to output soft breaks as hard breaks (<br />).

The GFM spec concurs with CommonMark exactly in this regard, however it is interesting to note that only as of a few years ago, when rendering Issues/PRs and comments, they appear to avail themselves of the option to use hard breaks. (Discussion can be found here.) Rendering a README.md on GitHub.com still conforms to the specified default behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions