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

Newlines on Windows #36

Open
lukewilliamboswell opened this issue Oct 27, 2019 · 3 comments
Open

Newlines on Windows #36

lukewilliamboswell opened this issue Oct 27, 2019 · 3 comments

Comments

@lukewilliamboswell
Copy link

Not sure if this is an issue but I thought I would mention in case there is a way to prevent someone else having a similar issue?

I wanted to get a minimal example of Elm Markup working using reactor using Visual Studio Code ... but had an issue with the windows new-line characters being rejected as an error by Mark.compile.

The workaround was to use String.replace "\u{000D}\n" "\n"

I have included an copy of the error and the code example below.

image

module Main exposing (main)

import Browser exposing (sandbox)
import Html exposing (Html)
import Html.Attributes as Attr
import Mark
import Mark.Error


main : Program () Model Msg
main =
    sandbox
        { init = init
        , view = view
        , update = update
        }


type alias Model =
    {}


init : Model
init =
    {}


type Msg
    = NoOP


update : Msg -> Model -> Model
update msg model =
    model


view : Model -> Html.Html msg
view model =
    case Mark.compile document source of
        Mark.Success html ->
            Html.div [] [ html ]

        Mark.Almost { result, errors } ->
            Html.div []
                [ Html.div [] (viewErrors errors)
                , Html.div [] [ result ]
                ]

        Mark.Failure errors ->
            Html.div []
                (viewErrors errors)


viewErrors errors =
    errors
        |> List.map
            (\error ->
                let
                    { title, message, region } =
                        Mark.Error.toDetails error
                in
                Html.p []
                    [ Html.text (Debug.toString <| Mark.Error.toDetails error)
                    ]
            )


document =
    Mark.document
        (\meta ->
            Html.node "blah"
                []
                [ Html.h1 [] [ Html.text meta.title ]
                , Html.h1 [] [ Html.text meta.description ]
                , Html.h1 [] [ Html.text meta.author ]
                ]
        )
        metadata


metadata =
    Mark.record "Article"
        (\author description title ->
            { author = author
            , description = description
            , title = title
            }
        )
        |> Mark.field "author" Mark.string
        |> Mark.field "description" Mark.string
        |> Mark.field "title" Mark.string
        |> Mark.toBlock


source =
    """
|> Article
    author = Matthew Griffith
    description = How I learned to use elm-markup.
    title = How I Learned /elm-markup/
"""
        |> String.trim
        -- Without the following line it will error on Windows
        -- |> String.replace "\u{000D}\n" "\n"
@j-maas
Copy link

j-maas commented May 14, 2020

I am running into more subtle errors with newlines. The sympoms are paragraphs and even blocks not being detected correctly, leading to errors that are hard to trace back to the newlines.

The most devious one I had was a block that took a Mark.string, but that got interpreted as Mark.text (presumably because the block was not detected as a block due to the newlines) and the content containing [FILE]. The error message told me that [FILE] was not a known annotation.

After I switched the newline format in VSCode from CRLF to LF (you can do that by clicking on "CRLF" in the bottom right corner and choosing the other one), everything works as expected.

This leads me to think that it might be possible and worth it to handle these different newline codes in elm-markup itself.

@Evelios
Copy link

Evelios commented Aug 18, 2020

I am having the same issue. I am having trouble compiling even basic markup syntaxes such as basic string parsing

@dzuk-mutant
Copy link

Yeah, I've just encountered the same issue when working with this.

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

4 participants