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

Style unstyled code ref links #255

Merged

Conversation

jonathanhefner
Copy link
Member

@jonathanhefner jonathanhefner commented Jul 31, 2023

RDoc does not provide syntax to style manual code ref links with <code></code>. Wrapping code ref links in <tt></tt> or ++ does not give the desired result. For example,

# {<tt>Rails</tt>}[rdoc-ref:Rails]

is rendered as

{<code>Rails</code><a href="..."><code>}</code></a>

and

# <tt>{Rails}[rdoc-ref:Rails]</tt>

is rendered as

<code>{Rails}[rdoc-ref:Rails]</code>

This commit uses postprocessing to style unstyled code ref links that look like code. If the link text does not contain a space or if it matches /\S\(/ (e.g. foo(bar, &block)), it is assumed to be code, and the text is then wrapped with <code></code>.

This complements 4837fea in that it allows manual code ref links to single-word modules to be styled as if they were autolinks.

Before After
before after

RDoc does not provide syntax to style manual code ref links with
`<code></code>`.  Wrapping code ref links in `<tt></tt>` or `++` does
not give the desired result.  For example,

  ```ruby
  # {<tt>Rails</tt>}[rdoc-ref:Rails]
  ```

is rendered as

  ```html
  {<code>Rails</code><a href="..."><code>}</code></a>
  ```

and

  ```ruby
  # <tt>{Rails}[rdoc-ref:Rails]</tt>
  ```

is rendered as

  ```html
  <code>{Rails}[rdoc-ref:Rails]</code>
  ```

This commit uses postprocessing to style unstyled code ref links that
look like code.  If the link text does not contain a space or if it
matches `/\S\(/` (e.g. `foo(bar, &block)`), it is assumed to be code,
and the text is then wrapped with `<code></code>`.

This complements 4837fea in that it
allows manual code ref links to single-word modules to be styled as if
they were autolinks.
@jonathanhefner jonathanhefner merged commit e3e6016 into rails:main Aug 5, 2023
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

Successfully merging this pull request may close these issues.

1 participant