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

Update prism.js to match new webhelp highlight colors #2670

Merged
merged 5 commits into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion core/api/core.api
Expand Up @@ -4303,7 +4303,6 @@ public final class org/jetbrains/dokka/pages/TextStyle : java/lang/Enum, org/jet
public final class org/jetbrains/dokka/pages/TokenStyle : java/lang/Enum, org/jetbrains/dokka/pages/Style {
public static final field Annotation Lorg/jetbrains/dokka/pages/TokenStyle;
public static final field Boolean Lorg/jetbrains/dokka/pages/TokenStyle;
public static final field Builtin Lorg/jetbrains/dokka/pages/TokenStyle;
public static final field Constant Lorg/jetbrains/dokka/pages/TokenStyle;
public static final field Function Lorg/jetbrains/dokka/pages/TokenStyle;
public static final field Keyword Lorg/jetbrains/dokka/pages/TokenStyle;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/pages/ContentNodes.kt
Expand Up @@ -382,7 +382,7 @@ enum class SymbolContentKind : Kind {
}

enum class TokenStyle : Style {
Keyword, Punctuation, Function, Operator, Annotation, Number, String, Boolean, Constant, Builtin
Keyword, Punctuation, Function, Operator, Annotation, Number, String, Boolean, Constant
}

enum class TextStyle : Style {
Expand Down
9 changes: 8 additions & 1 deletion plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
Expand Up @@ -792,11 +792,18 @@ open class HtmlRenderer(
TextStyle.Strong -> strong { body() }
TextStyle.Var -> htmlVar { body() }
TextStyle.Underlined -> underline { body() }
is TokenStyle -> span("token " + styleToApply.toString().toLowerCase()) { body() }
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously, if a text element had >2 TokenStyle styles, it was rendered as

span("token first") {
    span("token second") {
        text
    }
}

is TokenStyle -> span("token ${styleToApply.prismJsClass()}") { body() }
else -> body()
}
}

private fun TokenStyle.prismJsClass(): String = when(this) {
// Prism.js parser adds Builtin token instead of Annotation
// for some reason, so we also add it for consistency and correct coloring
TokenStyle.Annotation -> "annotation builtin"
else -> this.toString().toLowerCase()
}

override fun render(root: RootPageNode) {
shouldRenderSourceSetBubbles = shouldRenderSourceSetBubbles(root)
super.render(root)
Expand Down