-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: go/doc: Support for bulleted lists #7873
Comments
The way to discuss a proposal like this is to raise it on the public lists. Especially if you have a patch. See http://golang.org/doc/contribute.html . Thanks. Labels changed: added repo-main, release-none. |
Are you kidding me? You guys have an issue with markdown? |
@frankandrobot, that is not a constructive comment. We happily use Markdown on Github and elsewhere. We just don't want it to be Go's documentation format. |
@bradfitz i'm surprised that you guys decided to go with plain text. In practice in a large, complex app, you'll end up approximating a markup language for readability anyway (ex: caps for sections), and well you might as well pick a markup language for comments. Alternatively, since you guys hate markdown, is there the ability to pick whatever markup you want (like a plugin for markdown)? |
While I sympathise with not supporting Markdown in godoc, I also think that bulleted lists are important enough to have them properly displayed in godoc. A PR is still welcome? Or has this been rejected somewhere else already? |
And @griesemer. |
I understand and support the strive for simplicity. In this case, it seems, simplicity could be improved going either direction. Either have it be plain text or support a preexisting parser. To do it the way it is currently seems unnecessarily complex. As it stands, a simple parser is implemented (to heading sections and for preformatted text; documented here). It seems that just supporting an already existing parser, or at least parser specification like Markdown, would be duck soup. Maybe it would hurt the elegance of the output, but a list is a key ingredient of documentation. |
Moving to 1.9Maybe to raise visibility. No guarantee we're getting to it for 1.9, though. |
This is an example of the slippery-slope fallacy and is not a valid argument. |
@libeclipse, thanks. |
In case anybody is interested, I made a modified version of Godoc that adds ordered and unordered lists with a fast and simple custom parser I wrote called slippery-slope-markdown. Here's a link to my modified version: godoc-custom-fork Admittedly, the way I threw it in there is kinda hacky, but it could be a starting point. The parser follows this convention:
A similar convention is applied to ordered lists. As an aside, it also allows bold text. |
Change https://golang.org/cl/167403 mentions this issue: |
The len godoc uses a blockquote to list the rules for its semantics. The item that describes channels is a bit long, so it's split in two lines. However, the first line ends with a semicolon, and the second line can be read as a sentence of its own, so it's easy to misinterpret that the two lines are separate. Making that easy mistake would lead to an incorrect understanding of len: if v is nil, len(v) is zero. This could lead us to think that len(nil) is valid and should return zero. When in fact, that statement only applies to nil channels. To make this less ambiguous, add a bit of indentation to the follow-up line, to align with the channel body. If lists are added to godoc in the future via #7873, perhaps this text can be simplified. Fixes #30349. Change-Id: I84226edc812d429493137bcc65c332e92d4e6c87 Reviewed-on: https://go-review.googlesource.com/c/go/+/167403 Run-TryBot: Daniel Martí <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
I find it extremely disturbing that this discussion has not once referenced the amazing efforts of the Pandoc Markdown project (which is the standard documentation method use by the R language as well as many text books). It is objectively the most widely adopted knowledge source standard. |
Can this move forward at all? It seems like many people are looking for it, and miss this docstring feature that is present in many other languages. |
/cc @julieqiu This is a longstanding proposal (with lots of discussion above) to modify how Go packages can be documented. Perhaps it should be considered as part of other future work that's being done to improve documentation rendering on pkg.go.dev. |
Just stumbled across this.
Sounds great! Would be neat to address this in pkg.go.dev. |
Here's a concrete proposal for adding support for lists. It's more detailed than my original proposal #7873 (comment), has a prototype implementation, and in-depth analysis based on all public modules. GoalsLet's put forth some goals:
ProposalThe proposal here is based on Markdown, but modified to comply with the goals mentioned above. GrammarA list is started by a line:
The start of the list must be preceded by either a blank line or be indented relative to the previous text span. The amount of leading whitespace in the first list item determines the baseline indentation for all subsequent items in the same list. For example, this snippet:
and this:
and this:
will all render as:
However, this snippet:
will render as:
because the start of the list is not preceded by a blank line nor indented relative to the previous text span. See the analysis below for why we don't handle this case. The text for a list item may span multiple lines. Each additional line must have the same baseline indentation as the starting list indentation. However, relative to the baseline indentation subsequent lines may have additional indentation, but it must be consistent for each subsequent line (i.e., have same indentation as the second line). For example:
and
and
will all render as:
The span continues until the next empty line or a line with less indentation than the baseline indentation and the optional indentation of the second line. For example,
and
will render as:
Strangely formatted lists such as the following:
has undefined behavior, but will probably still render as expected:
Bulleted listsA bulleted list item is denoted by a single character marker that is one of the following:
Numbered listsA numbered list item is denoted by a non-negative integer followed by one of the following:
Numbered lists do not support automatic numbering. For example:
would be rendered as a list with every item number still being 1. Similarly, out-of-order numbering or sparse numbering will be preserved as is. We don't use Markdown's "lazy list numbering" feature since it violates goal 2 as the rendered documentation would look different from natural source code. Multi-span list itemsA list item may have multiple spans. A subsequent span within the same list item must be separated from the previous span by one or more blank lines. Such spans must start with the same indentation as the previous span. The list item ends when encountering a text span with an indentation less than the current indentation. For example:
and
would both render as:
Subsequent spans can include pre-formatted text or other lists according to the expected grammar for such constructs (but with the leading common indent stripped). For example:
would render as:
Multi-span list items and nested lists are a more complex addition, but not supporting it would interestingly violate goal 2. In the Go source code, it would already look naturally like a list item with multiple spans and nested lists, but would be rendered by Go documentation tools in a mangled manner. I don't expect nested lists to be used often and this assertion seems to hold empirically. Analysis of existing source code(The following analysis uses the latest version (as of 2021-03-21) of all public modules.) Bullet marker charactersBullet markers using:
The number of
since each of the The Number marker charactersNumber markers ending with:
Lists in pre-formatted textDue to the lack of support for lists, one convention is to pre-format the entire list to ensure that Go documentation doesn't render the lists as a regular paragraph. For example:
Fortunately, the rules proposed above will allow these currently pre-formatted lists to be treated as a real list. For all pre-formatted blocks, we detected ~241k cases where the first line starts with the list marker. Visual inspection of many of them seem to show that they genuinely are lists with no notable false positives: Sample of findings from top 1000 modules. Lists at the start of a paragraphDue to the lack of support for lists, another convention treat each item in the list as an entirely new paragraph. For example:
The rules defined above will allow this situation to be treated as real list. Our analysis detected ~123k paragraphs that start with a list marker. Visual inspection of many of them seem to show that they genuinely are lists with no notable false positives:
Sample of findings from top 1000 modules In some cases, users don't realize that Go documentation doesn't support native lists and still write documentation that looks like:
Unfortunately, this currently renders as:
Fortunately, the rules proposed above will allow this to be treated as a real list item. To detect this situation, we search for all paragraphs that start with a list marker and are followed by pre-formatted block and found ~24k cases. Visual inspection of many of them seem to show that they genuinely are lists: Sample of findings from top 1000 modules Lists in the middle of a paragraphSometimes Go documentation contains lists in the middle of a paragraph:
Unfortunately, this currently renders as:
We detected ~77k cases of paragraphs with list markers in the middle. While most the cases do look like legitimate lists: There were a few notable false positives:
Sample of findings from top 1000 modules The rules above do not handle lists in the middle of a paragraph for several reasons:
ImplementationI have working parser built. I don't think it would much work to integrate it into the pkgsite and I'm willing to do the work. The existing I believe there is benefit to a |
See #48305. |
Closing as done. |
The text was updated successfully, but these errors were encountered: