Description
- Gitea version (or commit ref): 1.3.1 and b6d2243 (try.gitea.io)
- Git version: 2.15.1
- Operating system: Arch Linux
- Database (use
[x]
):- PostgreSQL
- MySQL
- MSSQL
- SQLite
- Can you reproduce the bug at https://try.gitea.io:
- Yes: https://try.gitea.io/test/2017-12-14-debug-leading-hash/issues/1#issuecomment-1620
- No
- Not relevant
- Log gist: not relevant
Description
When writing issue or pull request comments, lines that start with a #
character are unconditionally rendered as headings. This takes precedence over interpreting the #
character as the beginning of an issue or pull request reference such as #3189. This was unexpected for me, because I sometimes start sentences with an issue or pull request ID.
Consider the following comment in Markdown:
This is a reference to #1.
#1 addressed this issue first.
#100000 doesn’t exist yet.
# Leading hash used with space = heading
#Leading hash without space = normal text
This is rendered by Gitea as follows:
Note that the same text is treated very differently by GitHub:
The reason for the difference seems to be that GitHub only considers lines starting with #
as headings if the #
is separated from the text by at least one whitespace.
I guess that GitHub shouldn’t serve as the only source of truth in such decisions. However, quoting CommonMark as a more objective source:
4.2 ATX headings
… The opening sequence of # characters must be followed by a space or by the end of line. …
… Note that many implementations currently do not require the space. However, the space was required by the original ATX implementation, and it helps prevent things like the following from being parsed as headings:
Example 34
#5 bolt #hashtag
I think that this specification detail is reasonable, considering the examples mentioned above in the CommonMark document as well as the use of #
for referencing issues and pull requests. For this reason, I suggest adjusting Gitea’s Markdown implementation for consistency with CommonMark.