Skip to content

feat: syntax highlight in Example block #889

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

Merged
merged 1 commit into from
Jun 10, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/elm-srcs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
version = "1.0.1";
};

"pablohirafuji/elm-syntax-highlight" = {
sha256 = "0yadpqbq9nbmhzaasvcdcn4c1yak1v0xalx4126akvffic531gq9";
version = "3.6.0";
};

"truqu/elm-base64" = {
sha256 = "12w68b4idbs2vn0gm0lj354pm745jb7n0fj69408mpvh5r1z4m1b";
version = "2.0.4";
Expand Down
1 change: 1 addition & 0 deletions frontend/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"hecrj/html-parser": "2.3.4",
"krisajenkins/remotedata": "6.0.1",
"leojpod/elm-keyboard-shortcut": "1.0.1",
"pablohirafuji/elm-syntax-highlight": "3.6.0",
"truqu/elm-base64": "2.0.4"
},
"indirect": {
Expand Down
Binary file modified frontend/registry.dat
Binary file not shown.
12 changes: 11 additions & 1 deletion frontend/src/Page/Options.elm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import Search
, decodeResolvedFlake
)
import Utils
import SyntaxHighlight exposing (useTheme, oneDark, elm, toBlockHtml)



Expand Down Expand Up @@ -189,6 +190,15 @@ viewResultItem nixosChannels channel _ show item =

asPreCode value =
div [] [ pre [] [ code [ class "code-block" ] [ text value ] ] ]

asHighlightPreCode value =
div []
[ useTheme oneDark
, elm value
|> Result.map (toBlockHtml (Just 1))
|> Result.withDefault
(pre [] [ code [ class "code-block" ] [ text value ]])
]

showDetails =
if Just item.source.name == show then
Expand Down Expand Up @@ -229,7 +239,7 @@ viewResultItem nixosChannels channel _ show item =
|> Maybe.map
(\example ->
[ div [] [ text "Example" ]
, div [] <| Maybe.withDefault [ asPreCode example ] (Utils.showHtml example)
, div [] <| Maybe.withDefault [ asHighlightPreCode example ] (Utils.showHtml example)
]
)
|> Maybe.withDefault []
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ body {
}
}

.code-block,.sourceCode {
.code-block,.sourceCode,.elmsh > code {
display: block;
cursor: text;
}
Expand Down