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

add a toString : List Block -> String function #112

Open
sebsheep opened this issue Feb 6, 2022 · 1 comment
Open

add a toString : List Block -> String function #112

sebsheep opened this issue Feb 6, 2022 · 1 comment

Comments

@sebsheep
Copy link

sebsheep commented Feb 6, 2022

It would be nice having a toString : List Block -> String function which is a "reverse" of the parser.

Of course some data as indentation could be lost, but I think this manageable.

My use case and wished workflow is the following:

  • an admin writes some article in a form. This content of the textarea is transformed to List Block
  • this List Block is stored as it in the persistence layer (I'm using Lamdera)
  • when a user wants to see the article, we just have to render it with a List Block -> Html renderer.
  • the next time an admin wants to edit the article, we could the string thanks to the toString function and we'd put this in a textarea.

We could just storing the string as it is entered by the admin but:

  • this asks an extra parsing step for the user to view it. It of course seems an inefficient process but what mostly bothers me is that we could have an Err during the process... What do we display to the user in this case?
  • directly storing the List Block value automatically provides a formater, so all the contents are eventually uniformly displayed to the admin.
  • this feature could be a good spot for property testing (the property being: forall blocks : List Block, blocks |> toString |> parse == Ok blocks. And it is always cool writing property tests :)
@dillonkearns
Copy link
Owner

There's a package that has support for something like this:

https://package.elm-lang.org/packages/matheus23/elm-markdown-transforms/latest/Markdown-Scaffolded#reducePretty

I might integrate some of the things in that package there at some point, but in the meantime it would be great if you could try that out and just give feedback and we can use that package to get a better understanding of the ideal way to do have toString and whether it fits in the core package, etc..

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

2 participants