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

Code in Tables Not Highlighted #2990

Closed
tajmone opened this issue Dec 23, 2018 · 5 comments
Closed

Code in Tables Not Highlighted #2990

tajmone opened this issue Dec 23, 2018 · 5 comments
Assignees
Milestone

Comments

@tajmone
Copy link

tajmone commented Dec 23, 2018

I'm working on an AsciiDoc document which uses Highlight as an external syntax highlighter (via the Highlight Treeprocessor Extension). Code block in the main document are being highlighted fine, but blocks inside tables not.

I have some tables with a column set as ADoc ([cols="<1m,<6a"]) and some cells in that column contain code blocks. Although in the final HTML document the block is correctly shown as a code block, with the proper language, nevertheless the code is not highlighted.

For some reason, it seems that code blocks inside tables are being ignored by the Treeprocessor extension.

Is it an Asciidoctor bug? or is it just a problem with the Highlight Treeprocessor Extension?

@mojavelinux
Copy link
Member

Tree processors do not get called separately for AsciiDoc table cells. It's up to the extension to descend into the table, find the AsciiDoc table cells, and descend into those.

You can use the mathematical extension as a reference. See https://github.com/asciidoctor/asciidoctor-mathematical/blob/master/lib/asciidoctor-mathematical/extension.rb#L45-L59

This is something we need to make easier in Asciidoctor, but that's a separate issue.

@mojavelinux mojavelinux added this to the support milestone Dec 23, 2018
@mojavelinux mojavelinux self-assigned this Dec 23, 2018
@tajmone
Copy link
Author

tajmone commented Dec 23, 2018

Thanks for the clarification.

Would this also affect code blocks inside admonitions?

This is something we need to make easier in Asciidoctor...

Indeed, it would make sense that source code is treated the same in respect to syntax highlighting, regardless of whether it appears in the main body of text or inside tables, admonitions, etc.

@mojavelinux
Copy link
Member

Asciidoctor 2.0 introduces a new API for registering a syntax highlighter adapter. I recommend that you use this for your highlight extension. Here's an example:

https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/syntax_highlighter/coderay.rb

Instead of having to find nodes in a tree processor extension, the adapter gets called by the processor to highlight the relevant nodes, contribution markup to the output, and write a custom stylesheet.

You can find the API docs here: https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/syntax_highlighter.rb

I look forward to your feedback.

@mojavelinux
Copy link
Member

Would this also affect code blocks inside admonitions?

To answer your question, no. Although admonition blocks are laid out using tables, they are not themselves table nodes.

@mojavelinux
Copy link
Member

Please open a new issue if you have follow-up questions or feedback.

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

No branches or pull requests

2 participants