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

Generates invalid code when parsing backtics-separated code #93

Open
malaire opened this issue Apr 16, 2020 · 5 comments
Open

Generates invalid code when parsing backtics-separated code #93

malaire opened this issue Apr 16, 2020 · 5 comments

Comments

@malaire
Copy link

malaire commented Apr 16, 2020

When I run elm-verify-examples with following example:

{-|

  - some
  - list

```
Basics.ceiling 123.45
    |> Basics.toFloat
    --> 124.0
```
-}
someFunction : ...

it generates following invalid code which doesn't even compile:

spec1 : Test.Test
spec1 =
    Test.test "#someFunction: \n\n    |> Basics.toFloat\n    --> 124.0" <|
        \() ->
            Expect.equal
                (
                |> Basics.toFloat
                )
                (
                124.0
                )

If I indent same example with 4 spaces instead of using backticks it works, but since here I have example directly after a list, 4 spaces indentation can't be used as elm-format will mangle that.

@stoeffel
Copy link
Owner

stoeffel commented Apr 20, 2020

Sorry that this isn't working for you as you'd expected. Does it also not work with newlines in between? Do the three backticks format nicely on package.elm-lang.org ?

@malaire
Copy link
Author

malaire commented Apr 20, 2020

Do the three backticks format nicely on package.elm-lang.org ?

It formats normally with elm-doc-preview. I'm not sure what you mean about newlines?

The problem seems to be that the unindented line within backtics-section is not detected by elm-verify-examples.

This doesn't work with elm-verify-examples, and generated code seems to imply that line Basics.ceiling 123.45 is ignored:

```
Basics.ceiling 123.45
    |> Basics.toFloat
    --> 124.0
```

This does work with elm-verify-examples, but adding that unneeded indentation within backtics looks bad in generated documentation:

```
    Basics.ceiling 123.45
        |> Basics.toFloat
        --> 124.0
```

@stoeffel
Copy link
Owner

I meant newlines here.
There is no support for ``` in comments yet. Happy to accept a PR for adding support though.

{-|

  - some
  - list

   -- <-- I meant adding a newline here and no ```
    Basics.ceiling 123.45
        |> Basics.toFloat
        --> 124.0

-}
someFunction : ...

@malaire
Copy link
Author

malaire commented Apr 20, 2020

That syntax is not accepted by elm-format. If there are 2 or more empty lines between list and following indented code-block, elm-format will unindent the code-block and add backticks around it.

If there is only single newline then elm-format will mangle the list and the code-block.

So this example with two empty lines:

...
  - some
  - list


    Basics.ceiling 123.45
        |> Basics.toFloat
        --> 124.0
...

is changed by elm-format to this:

...
  - some
  - list

```
Basics.ceiling 123.45
    |> Basics.toFloat
    --> 124.0
```
...

And this example with single empty line:

...
  - some
  - list

    Basics.ceiling 123.45
        |> Basics.toFloat
        --> 124.0
...

is changed by elm-format to this:

...
  - some

  - list

    Basics.ceiling 123.45
    |> Basics.toFloat
    --> 124.0
...

@stoeffel
Copy link
Owner

Got it. Thanks for clarifying. Don't know when I'll get to this, but I definitelly think that we should start to support ```.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants