How to Perform Post-Processing on HTML Generated by the `Documentation Target API`?

Answered

Hi!

I’m the developer of the Translation plugin, which helps non-native English developers by translating code documentation from English to other languages:

This feature relies on post-processing the code documentation HTML generated by the IDE to translate its contents. Currently, I am using the Documentation Provider API to achieve this.

However, I’ve encountered an issue where this approach doesn’t work for documents generated using the new Documentation Target API, such as in Kotlin’s K2 mode.

I’ve tried implementing a solution using the Documentation Target API, but I’ve found that many useful APIs are either internal or non-public. Even when I attempted to proxy the original DocumentationTarget using my own DocumentationTarget, I couldn’t access the actual content of the documentation:

class MyDocumentationTarget(private val delegate: DocumentationTarget) : DocumentationTarget by delegate {

    // ...

    override fun computeDocumentation(): DocumentationResult {
        val original = delegate.computeDocumentation()
        // Cannot get the HTML content from the original documentation result.
        return DocumentationResult.documentation("<html><body>Translated documentation.</body></html>")
    }

}

Could you please advise on how I can achieve my goal with the Documentation Target API?

Thank you!

0
1 comment

com.intellij.codeInsight.documentation.DocumentationComponent etc. are not used by Documentation Target API.

Use com.intellij.lang.documentation.ide.ui.DocumentationUI and related classes.

Please note, using reflection in plugin code is a bad practice and may stop working in the future.

0

Please sign in to leave a comment.