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

Undesired space for documentation #4

Open
ghivert opened this issue May 12, 2024 · 3 comments
Open

Undesired space for documentation #4

ghivert opened this issue May 12, 2024 · 3 comments

Comments

@ghivert
Copy link

ghivert commented May 12, 2024

Hi!

In the documentation fields, there's an undesired leading space for every line.

Here's an example, from the package interface of the gleam_stdlib right now (append function here):

{
  // That field has undesired spaces
  "documentation": " Creates a new bit array by joining two bit arrays.\n\n ## Examples\n\n ```gleam\n append(to: from_string(\"butter\"), suffix: from_string(\"fly\"))\n // -> from_string(\"butterfly\")\n ```\n",

  // Rest of the definition.
  "deprecation": null,
  "implementations": {
    "gleam": false,
    "uses-erlang-externals": true,
    "uses-javascript-externals": true,
    "can-run-on-erlang": true,
    "can-run-on-javascript": true
  },
  "parameters": [
    {
      "label": "to",
      "type": {
        "kind": "named",
        "name": "BitArray",
        "package": "",
        "module": "gleam",
        "parameters": [
          
        ]
      }
    },
    {
      "label": "suffix",
      "type": {
        "kind": "named",
        "name": "BitArray",
        "package": "",
        "module": "gleam",
        "parameters": [
          
        ]
      }
    }
  ],
  "return": {
    "kind": "named",
    "name": "BitArray",
    "package": "",
    "module": "gleam",
    "parameters": [
      
    ]
  }
}

I suspect it's due to the /// comments removed, but the space between the triple slash and the comments themselves are still there. It's a bug, because the string as-is is not a valid markdown string.

@lpil
Copy link
Member

lpil commented May 13, 2024

Which parser are you having trouble with? All markdown specs I've read while slowly making a parser say that preceding whitespace is permitted and has no impact on the document.

@ghivert
Copy link
Author

ghivert commented May 13, 2024

Oh! Thanks for your answer!

I'm using Showdown JS, because of habits mainly. It does not support leading space as you can see in the live demo.
My bad for that one, I was 100% convinced MD specs forbad leading space, but I cannot find any sources ensuring this behaviour. I think Showdown should be modified.


I'm still wondering about the leading space, for the code part. Let's say the doc is:

" Bla\n\n ```gleam\n\n   io.debug("hello gleam")\n\n ```"

Which translates to

 Bla

 ```gleam
 io.debug("hello gleam")
 ```

Can we be sure parsers will get rid of leading spaces in code blocks? Because I think we'd like to have

io.debug("hello gleam")

And not

 io.debug("hello gleam")

Is it a parser thing? Should it be handled in the code directly?

@lpil
Copy link
Member

lpil commented May 13, 2024

I think that is a problem with that specific markdown parser, but it'd still be good to resolve this. We do have some space trimming code that we use when rendering HTML documentation, let's apply that to the module interface docs too.

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