-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement custom code block renderers support (#3320)
* multiple custom renderers can be installed to support different languages independently * only language and code properties are provided for extension
- Loading branch information
Showing
5 changed files
with
426 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...gin-base/src/main/kotlin/org/jetbrains/dokka/base/renderers/html/HtmlCodeBlockRenderer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package org.jetbrains.dokka.base.renderers.html | ||
|
||
import kotlinx.html.FlowContent | ||
|
||
/** | ||
* Provides an ability to override code blocks rendering differently dependent on the code language. | ||
* | ||
* Multiple renderers can be installed to support different languages in an independent way. | ||
*/ | ||
public interface HtmlCodeBlockRenderer { | ||
|
||
/** | ||
* Whether this renderer supports rendering Markdown code blocks | ||
* for the given [language] explicitly specified in the fenced code block definition, | ||
*/ | ||
public fun isApplicableForDefinedLanguage(language: String): Boolean | ||
|
||
/** | ||
* Whether this renderer supports rendering Markdown code blocks | ||
* for the given [code] when language is not specified in fenced code blocks | ||
* or indented code blocks are used. | ||
*/ | ||
public fun isApplicableForUndefinedLanguage(code: String): Boolean | ||
|
||
/** | ||
* Defines how to render [code] for specified [language] via HTML tags. | ||
* | ||
* The value of the [language] will be the same as in the input Markdown fenced code block definition. | ||
* In the following example [language] = `kotlin` and [code] = `val a`: | ||
* ~~~markdown | ||
* ```kotlin | ||
* val a | ||
* ``` | ||
* ~~~ | ||
* The value of the [language] will be `null` if language is not specified in the fenced code block definition | ||
* or indented code blocks are used. | ||
* In the following example [language] = `null` and [code] = `val a`: | ||
* ~~~markdown | ||
* ``` | ||
* val a | ||
* ``` | ||
* ~~~ | ||
*/ | ||
public fun FlowContent.buildCodeBlock(language: String?, code: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.