Skip to content

Remove text wrapping #3

@Thenlie

Description

@Thenlie

In certain documents, there is text wrapping used in the markdown document that is not displayed on the website. For example: https://github.com/Thenlie/mdnman/blob/main/lib/javascript/web_api/window/status/index.md?plain=1#L13

Create a function to remove these text wraps without breaking any other line breaks.

A naïve attempt to do this was already made.

const removeTextWrapping = (document: string) => {
    return document.replace(/([^\n])\n(?=\S)/g, '$1 ');
};

This approach does not account for codeblocks or block quotes, and likely some other edge cases. Ensure the function properly handles the following cases:

→ Input
However, the HTML standard now requires
setting `window.status` to have no effect on the text displayed in the
status bar.

← Output
However, the HTML standard now requires setting `window.status` to have no effect on the text displayed in the status bar.
→ Input
```js
let foo = 42; // foo is now a number
foo = "bar"; // foo is now a string
foo = true; // foo is now a boolean
`` `

← Output
```js
let foo = 42; // foo is now a number
foo = "bar"; // foo is now a string
foo = true; // foo is now a boolean
`` `
→ Input
> This is a 
> Block quote that
> Should not be split up

← Output
> This is a 
> Block quote that
> Should not be split up

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions