Skip to content

Newlines on Windows #36

@lukewilliamboswell

Description

@lukewilliamboswell

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"

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