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

Add css colors ju-comment and ju-judoc #2321

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion assets/css/source-ayu-light.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ body {
color: #787b80;
}

.ju-comment {
color: #ba919966;
}

.ju-comment {
color: #8b2252;
}

.ju-var {
color: #5c6166;
}
Expand Down Expand Up @@ -65,4 +73,4 @@ footer a {
color: gray;
font-size: small;
font-weight: bold;
}
}
12 changes: 10 additions & 2 deletions assets/css/source-nord.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ body {
color: #a4b4d2
}

.ju-comment {
color: #83898d
}

.ju-judoc {
color: #8fbcbb
}

.ju-number {
color: #d8dee9
}

.ju-defined {
.ju-define {
font-weight: bold;
}

Expand All @@ -65,4 +73,4 @@ footer a {
color: gray;
font-size: small;
font-weight: bold;
}
}
66 changes: 49 additions & 17 deletions src/Juvix/Compiler/Backend/Html/Translation/FromTyped/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ import Text.Blaze.Html.Renderer.Text qualified as Html
import Text.Blaze.Html5 as Html hiding (map)
import Text.Blaze.Html5.Attributes qualified as Attr

data CssColor
= JuInductive
| JuConstructor
| JuFunction
| JuAxiom
| JuString
| JuKeyword
| JuDelimiter
| JuVar
| JuFixity
| JuNumber
| JuComment
| JuJudoc

kindSuffix :: HtmlKind -> String
kindSuffix = \case
HtmlDoc -> ""
Expand Down Expand Up @@ -248,16 +262,34 @@ go sdt = case sdt of
textSpaces :: Int -> Text
textSpaces n = Text.replicate n (Text.singleton ' ')

juColor :: CssColor -> Attribute
juColor = Attr.class_ . toStr
where
toStr :: CssColor -> AttributeValue
toStr = \case
JuInductive -> "ju-inductive"
JuConstructor -> "ju-constructor"
JuFunction -> "ju-function"
JuComment -> "ju-comment"
JuJudoc -> "ju-judoc"
JuAxiom -> "ju-axiom"
JuString -> "ju-string"
JuKeyword -> "ju-keyword"
JuDelimiter -> "ju-delimiter"
JuFixity -> "ju-fixity"
JuVar -> "ju-var"
JuNumber -> "ju-number"

putTag :: forall r. (Members '[Reader HtmlOptions] r) => Ann -> Html -> Sem r Html
putTag ann x = case ann of
AnnKind k -> return (tagKind k x)
AnnLiteralInteger -> return (Html.span ! Attr.class_ "ju-number" $ x)
AnnLiteralString -> return (Html.span ! Attr.class_ "ju-string" $ x)
AnnKeyword -> return (Html.span ! Attr.class_ "ju-keyword" $ x)
AnnUnkindedSym -> return (Html.span ! Attr.class_ "ju-var" $ x)
AnnComment -> return (Html.span ! Attr.class_ "ju-var" $ x) -- TODO add comment class
AnnJudoc -> return (Html.span ! Attr.class_ "ju-var" $ x) -- TODO add judoc class
AnnDelimiter -> return (Html.span ! Attr.class_ "ju-delimiter" $ x)
AnnLiteralInteger -> return (Html.span ! juColor JuNumber $ x)
AnnLiteralString -> return (Html.span ! juColor JuString $ x)
AnnKeyword -> return (Html.span ! juColor JuKeyword $ x)
AnnUnkindedSym -> return (Html.span ! juColor JuVar $ x)
AnnComment -> return (Html.span ! juColor JuComment $ x)
AnnJudoc -> return (Html.span ! juColor JuJudoc $ x)
AnnDelimiter -> return (Html.span ! juColor JuDelimiter $ x)
AnnDef tmp ni -> boldDefine <*> tagDef tmp ni
AnnRef tmp ni -> tagRef tmp ni
AnnCode -> return x
Expand Down Expand Up @@ -285,17 +317,17 @@ putTag ann x = case ann of

tagKind k =
Html.span
! Attr.class_
! juColor
( case k of
S.KNameConstructor -> "ju-constructor"
S.KNameInductive -> "ju-inductive"
S.KNameFunction -> "ju-function"
S.KNameLocal -> "ju-var"
S.KNameAxiom -> "ju-axiom"
S.KNameLocalModule -> "ju-var"
S.KNameAlias -> "ju-var"
S.KNameTopModule -> "ju-var"
S.KNameFixity -> "ju-fixity"
S.KNameConstructor -> JuConstructor
S.KNameInductive -> JuInductive
S.KNameFunction -> JuFunction
S.KNameLocal -> JuVar
S.KNameAxiom -> JuAxiom
S.KNameLocalModule -> JuVar
S.KNameAlias -> JuVar
S.KNameTopModule -> JuVar
S.KNameFixity -> JuFixity
)

nameIdAttr :: S.NameId -> AttributeValue
Expand Down