Skip to content

Add fencedCodeTokenizers extension point for non-Java syntax highligh… - #3315

Open
jjohnstn wants to merge 3 commits into
eclipse-jdt:masterfrom
jjohnstn:tm4eextension
Open

jjohnstn wants to merge 3 commits into
eclipse-jdt:masterfrom
jjohnstn:tm4eextension

Conversation

@jjohnstn

Copy link
Copy Markdown
Contributor

…ting

Add a public IFencedCodeTokenizer interface and fencedCodeTokenizers extension point in org.eclipse.jdt.core.manipulation to allow external plugins to contribute syntax highlighting for non-Java fenced code blocks in Javadoc markdown comments.

CoreMarkdownAccessImpl loads the tokenizer from the extension registry for non-java fenced comments.

What it does

See #3118

How to test

See #3118 or add markdown fenced comments specifying languages such as xml, css, cpp.

Author checklist

…ting

Add a public IFencedCodeTokenizer interface and fencedCodeTokenizers
extension point in org.eclipse.jdt.core.manipulation to allow external
plugins to contribute syntax highlighting for non-Java fenced code
blocks in Javadoc markdown comments.

CoreMarkdownAccessImpl loads the tokenizer from the extension
registry for non-java fenced comments.

- for eclipse-jdt#3118

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jjohnstn jjohnstn self-assigned this Nov 13, 2026
@jjohnstn jjohnstn added the enhancement New feature or request label Nov 13, 2026
@jjohnstn

Copy link
Copy Markdown
Contributor Author

@iloveeclipse @akurtakov This is the extension based solution that just adds the extension and code to look for the extension implemented. I have created a tm4e patch, but it won't be reviewable/buildable until this patch is accepted. If it is possible to review this and get it into RC1 (resolving all comments), that would make it much quicker to add the functionality, otherwise, we have to wait until 2027-03. The patch won't change anything without a user of the extension. I have tried it out and it works well with the tm4e patch. I am attaching the patch here if you want to try it out with actual colorization.
0001-Add-JDT-fenced-code-tokenizer-plugin-and-feature.patch

Extend IFencedCodeTokenizer with CodeTokenType enum, CodeToken record,
and tokenizeCode() default method to support editor-level syntax coloring
of text blocks annotated with // language=xxx comments. The existing
tokenize() method continues to serve Javadoc hover HTML rendering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jjohnstn

jjohnstn commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@iloveeclipse @akurtakov I did some further work on adding the intell-j feature where a line comment before a text block can specify the language to use in adding syntax coloring to the text block contents. For example:

// language=java
String x = """
    public class MyClass extends Object {
        public void foo(String x) {
            System.out.println(x);
        }
    }
    """;

The previous version needed enhancement to add tokenization instead of just providing html. Anyway, I have updated the tm4e code and it works very well. The extension is still called fencedCodeTokenizers and the interface is still IFencedCodeTokenizer.

The updated tm4e patch is:

0001-Add-JDT-fenced-code-tokenizer-plugin-and-feature.patch

A subsequent patch will add the logic to do the text block colorization. This will just cover the markdown fenced comments that are non-java.

Separate text block tokenization from fenced code block tokenization by
introducing a dedicated ITextBlockCodeTokenizer interface and extension
point. The tokenizeCode method and its CodeTokenType/CodeToken types are
moved from IFencedCodeTokenizer to the new interface, keeping each
extension point focused on its specific use case.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jjohnstn

Copy link
Copy Markdown
Contributor Author

I ended up breaking up into 2 extensions. One of them needs tm4e.ui and I want to make the text block tokenizer available to projects such as jdt.ls which can't bring in UI elements.

The new tm4e patch implementing these is:

0001-Add-JDT-fenced-code-and-text-block-tokenizer-plugins.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant