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

Require space between hash/content in ATX heading #1140

Merged
merged 1 commit into from
Jul 17, 2024

Conversation

skipkayhil
Copy link
Contributor

@skipkayhil skipkayhil commented Jul 13, 2024

Ref rails/rails#50759
Ref rails/rails#50063

While writing some Markdown documentation for Rails, I came across an interesting case where trying to link to an instance method at the start of a line would instead parse as an H1 heading:

#response_body=

Expected:

<a href=""><code>#response_body=</code></a>

Actual:

<h1>response_body=</h1>

According to the CommonMark spec:

At least one space or tab is required between the # characters and the
heading’s contents, unless the heading is empty. 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 64

So while some implementations do not follow this requirement, I believe RDoc should because it makes it easy to write text similar to Example 64 (which was used in the new test) and it also enables automatically linking to instance methods at the start of a line.

While writing some Markdown documentation for Rails, I came across an
interesting case where trying to link to an instance method at the start
of a line would instead parse as an H1 heading:

```markdown
#response_body=
```

Expected:

```html
<a href=""><code>#response_body=</code></a>
```

Actual:

```html
<h1>response_body=</h1>
```

According to the CommonMark spec:

> At least one space or tab is required between the # characters and the
> heading’s contents, unless the heading is empty. 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 64

So while some implementations do not follow this requirement, I believe
RDoc should because it makes it easy to write text similar to Example 64
(which was used in the new test) and it also enables automatically
linking to instance methods at the start of a line.
Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think the current behaviour is likely surprising and also confusing to most devs (myself included). Thanks for the change 👍

@st0012 st0012 merged commit 1bb3bec into ruby:master Jul 17, 2024
22 checks passed
@skipkayhil skipkayhil deleted the hm-require-heading-space branch July 23, 2024 00:47
@zzak
Copy link
Member

zzak commented Aug 30, 2024

Could you also use rdoc-ref in places where the autolinking is imperfect?
https://ruby.github.io/rdoc/RDoc/MarkupReference.html#class-RDoc::MarkupReference-label-Links

@st0012 st0012 added this to the v6.8.0 milestone Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants