Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing spaces in string blocks are ignored even in Mark.New.string #40

Open
tad-lispy opened this issue Jul 15, 2020 · 1 comment
Open

Comments

@tad-lispy
Copy link

tad-lispy commented Jul 15, 2020

When parsing a string block like this:

|> Title
    There are spaces here ->  

the trailing spaces will be ignored. In most cases it makes sense - probably the whitespace is there by mistake. The problem is that when creating a new block programmatically with Mark.New the trimming is also applied. This makes incremental updates to string block difficult.

Say I have a text input that on change replaces the text block:

setTitle : Mark.Edit.Id -> String -> Mark.Parsed -> Result (List Error) Mark.Parsed
setTitle id value ast =
    let
        block =
            Mark.New.string value

        edit =
            Mark.Edit.replace id block
    in
    Mark.update document edit ast

This works great except when a user tries to insert a space at the end of the field with intention of adding another word after it. Then the space simply does not get added.

It seems to me that trimming should be applied when parsing, but not when blocks are created with Mark.New.string.

@tad-lispy
Copy link
Author

tad-lispy commented Jul 15, 2020

After some investigation I see that actually the whitespace is preserved in AST (Mark.Parsed) and trimmed when it's rendered. It seems to me that trimming should be a responsibility of the parser, not the render function. I'll prepare a PR. Please let me know if you disagree.

As usual, thanks for your awesome work 😁

tad-lispy added a commit to tad-lispy/elm-markup that referenced this issue Jul 15, 2020
Trailing spaces from string blocks were not rendered, even when the
block was created using Mark.New.string. This commit removes trimming
when string is rendered and instead adds trimming to string block
parser. That way documents parsed from string behave the same as before,
but programmatically inserted whitespace is preserved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant