Skip to content

Commit

Permalink
Update prism.js to match new webhelp highlight colors (#2670)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev committed Sep 20, 2022
1 parent e88a21e commit c63ec45
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 44 deletions.
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() }
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

0 comments on commit c63ec45

Please sign in to comment.