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

Fix Asciidoc syntax highlight #1276

merged 3 commits into from Nov 26, 2019


Copy link

skalee commented Aug 30, 2019


This pull request improves the way in which code listing blocks in extra file objects are matched.
In the result, listings in extra file objects written in AsciiDoc are now properly enriched with YARD: the syntax is highlighted, and the identifiers are linked with their respective documentation.

Fixes #1239 (went with option 2).


The regular expression used for code blocks detection has been significantly relaxed. The updated one makes no assumptions on what HTML attributes can be set on <pre> or <code> element, allowing everything. It still requires that the listing's outermost element is <pre>, but this seems to be a reasonable limitation.

The programming language detection still considers the values of class and lang HTML attributes. Moreover, data-lang attribute, which is produced by AsciiDoctor markup processor, is also supported now.

Finally, this pull request properly ensures that code blocks produced from Ruby source files are not highlighted twice. It wasn't a problem before only because of a very lucky situation that code blocks produced by html_markup_ruby have a slightly different attributes, and that was preventing them from being erroneously double-highlighted.

Completed Tasks

  • I have read the Contributing Guide.
  • The pull request is complete (implemented / written).
  • Git commits have been cleaned up (squash WIP / revert commits).
  • I wrote tests and ran bundle exec rake locally (if code is attached to PR).
skalee added 3 commits Aug 29, 2019
This commit replaces the regular expression, which detects code blocks
in the HTML document produced by a markup renderer, with a more general
one.  The new regular expression makes no assumptions on what HTML
attributes can be set on <pre> or <code> element.

As a consequence, code block's programming language detection is now
slightly more complicated, because it must deal with parsing HTML
attribute lists.  A new private method has been defined to handle that.
Recognize "data-lang" HTML attribute, which is set on code blocks
in HTML documents produced by AsciiDoctor.
The #html_markup_ruby method, which is responsible for creating HTML from
Ruby snippets, produces output with syntax highlighting already applied.
Doing it for the second time messes things up.

It wasn't a big deal before the regular expression in #parse_codeblocks
has been relaxed.  Only a slightly different set of HTML attributes was
preventing the rendered Ruby listings from being matched.  But now,
a proper fix is needed, and it is introduced in this very commit.

This comment has been minimized.

Copy link

coveralls commented Aug 30, 2019

Coverage Status

Coverage increased (+0.04%) to 93.808% when pulling c7975eb on skalee:asciidoc-syntax-highlight into 890d4ad on lsegal:master.

lsegal approved these changes Nov 26, 2019

This comment has been minimized.

Copy link

lsegal commented Nov 26, 2019

Sorry for the delay here. Thanks for this!

@lsegal lsegal merged commit ebd6269 into lsegal:master Nov 26, 2019
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
coverage/coveralls Coverage increased (+0.04%) to 93.808%
@skalee skalee deleted the skalee:asciidoc-syntax-highlight branch Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.