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

Implement custom code block renderers support #3320

Merged
merged 4 commits into from
Nov 16, 2023
Merged

Implement custom code block renderers support #3320

merged 4 commits into from
Nov 16, 2023

Conversation

whyoleg
Copy link
Contributor

@whyoleg whyoleg commented Nov 6, 2023

Fixes #3244

Notes:

  • multiple custom renderers can be installed to support different languages independently
  • if no custom renderers is applicable for rendering code blocks, default (original) code will be used
  • as was discussed internally, in extension, only language and code properties are provided instead of full ContentCodeBlock type

Example of usage in mermaid plugin: whyoleg/dokka-mermaid@0c0cd23

@whyoleg whyoleg self-assigned this Nov 6, 2023
@@ -48,6 +48,7 @@ public class DokkaBase : DokkaPlugin() {
public val externalLocationProviderFactory: ExtensionPoint<ExternalLocationProviderFactory> by extensionPoint()
public val outputWriter: ExtensionPoint<OutputWriter> by extensionPoint()
public val htmlPreprocessors: ExtensionPoint<PageTransformer> by extensionPoint()
public val htmlCodeBlockRenderers: ExtensionPoint<HtmlCodeBlockRenderer> by extensionPoint()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put KDoc here as this is an extension point for plugins?

Copy link
Member

@IgnatBeresnev IgnatBeresnev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I only have a minor comment above about code and a documentation/api nitpick, but it's up to you

* remove `code` from HtmlCodeBlockRenderer.isApplicable
* add documentation for extension
* add test for multiline code with linebreaks
* revert default rendering to original implementation
* split applicability for defined and undefined languages
* make language nullable
* improve documentation for applicability and building of content
* add a lot of tests for multiple renderers combinations
@whyoleg
Copy link
Contributor Author

whyoleg commented Nov 14, 2023

Added documentation and divided workflows for cases with explicit language and undefined.

BTW, IDEA doesn't really like nested code blocks: parameters references in KDoc after the first code block are not resolved (and so not clickable):

image

But it works just fine in Reader mode:

image

And also works on GitHub:

image

P.S. writing examples for Markdown code blocks via Markdown code blocks is funny and looks really strange :)

Copy link
Member

@IgnatBeresnev IgnatBeresnev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done with the comments!

@whyoleg whyoleg merged commit f333e42 into master Nov 16, 2023
10 of 11 checks passed
@whyoleg whyoleg deleted the code-blocks branch November 16, 2023 14:58
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.

Provide a way to override/extend rendering of a specific language's code blocks in HTML format
3 participants