Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Last active November 26, 2020 04:11
Show Gist options
  • Save sogaiu/569daccc3dbab7b8e27efa1529d5c778 to your computer and use it in GitHub Desktop.
Save sogaiu/569daccc3dbab7b8e27efa1529d5c778 to your computer and use it in GitHub Desktop.
janet docstring formatting rules

The current docstrings formatting rules are very simple:

  • any number of spaces or a single newline is considered a word break [1]
  • tabs are preserved for indentation
  • multiple newlines in a row are also preserved [2]

I think tweaking these rules to work with markdown might help.

We could probably just do something like textwrap.dedent from python on the docstring, and then only drop spaces as long as they are not the first characters on a line (in which case they would be for indentation).

Some care also needs to be taken for defn vs def, as defn prepends, so stuff the docstring that may mess with the dedent process.


[1] So we can wrap on them (any number of spaces or a single newline)

[2] This is how we can do formatting without any complicated syntax - this lets you do list and such, albeit a bit cumbersomely.

adapted from: janet-lang/janet#507 (comment)

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