From c0e1b7b1379ae92f721e1c5b026294432d1f0695 Mon Sep 17 00:00:00 2001
From: tauomicronmu
Date: Mon, 12 Jun 2023 11:50:37 +0200
Subject: [PATCH 1/3] Remove Haskell tags from error message code blocks
---
message-index/messages/GHC-00158/example1/index.md | 2 +-
message-index/messages/GHC-00158/example2/index.md | 2 +-
message-index/messages/GHC-00482/example1/index.md | 2 +-
message-index/messages/GHC-00482/example2/index.md | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/message-index/messages/GHC-00158/example1/index.md b/message-index/messages/GHC-00158/example1/index.md
index d832a060..44bc206e 100644
--- a/message-index/messages/GHC-00158/example1/index.md
+++ b/message-index/messages/GHC-00158/example1/index.md
@@ -6,7 +6,7 @@ GHC cannot derive an instance for `MyClass`, as it is not stock deriveable. Enab
## Error Message
-```haskell
+```
NotStockDeriveable.hs:6:12: error: [GHC-00158]
• Can't make a derived instance of ‘MyClass MyType’:
‘MyClass’ is not a stock derivable class (Eq, Show, etc.)
diff --git a/message-index/messages/GHC-00158/example2/index.md b/message-index/messages/GHC-00158/example2/index.md
index d0a801aa..fd71ea0e 100644
--- a/message-index/messages/GHC-00158/example2/index.md
+++ b/message-index/messages/GHC-00158/example2/index.md
@@ -6,7 +6,7 @@ In this example, the `stock` strategy is incorrectly specified when deriving the
## Error Message
-```haskell
+```
IncorrectDerivingStrategy.hs:6:18: error: [GHC-00158]
• Can't make a derived instance of
‘Num IntWrapper’ with the stock strategy:
diff --git a/message-index/messages/GHC-00482/example1/index.md b/message-index/messages/GHC-00482/example1/index.md
index b552a19a..b8aa0e73 100644
--- a/message-index/messages/GHC-00482/example1/index.md
+++ b/message-index/messages/GHC-00482/example1/index.md
@@ -6,7 +6,7 @@ When pattern matching with a `case` expression, backslash (`\`) is not required
## Error Message
-```haskell
+```
LambdaInCase.hs:6:5: error: [GHC-00482]
Lambda-syntax in pattern.
Pattern matching on functions is not possible.
diff --git a/message-index/messages/GHC-00482/example2/index.md b/message-index/messages/GHC-00482/example2/index.md
index 444c43a1..37550f7a 100644
--- a/message-index/messages/GHC-00482/example2/index.md
+++ b/message-index/messages/GHC-00482/example2/index.md
@@ -6,7 +6,7 @@ Pattern matching on functions is not possible.
## Error Message
-```haskell
+```
LambdaInPattern.hs:4:4: error: [GHC-00482]
Lambda-syntax in pattern.
Pattern matching on functions is not possible.
From 3eab4ff770c9444bce4840ecdef4bc1a19a2a30d Mon Sep 17 00:00:00 2001
From: Daan Rijks
Date: Tue, 21 Jun 2022 22:17:27 +0200
Subject: [PATCH 2/3] Replace highlight.js with static highlighting using
Pandoc
Co-authored-by: tauomicronmu
---
message-index/css/highlight.css | 100 ++++++++++-----------------
message-index/message-index.cabal | 1 +
message-index/site.hs | 23 +++---
message-index/templates/default.html | 5 --
message-index/templates/example.html | 6 +-
5 files changed, 55 insertions(+), 80 deletions(-)
diff --git a/message-index/css/highlight.css b/message-index/css/highlight.css
index e927eee8..ee2ea9c4 100644
--- a/message-index/css/highlight.css
+++ b/message-index/css/highlight.css
@@ -1,67 +1,41 @@
-pre code.hljs {
- display: block;
- overflow-x: auto;
- padding: 1em
-}
-
-code.hljs {
- padding: 3px 5px
-}
-
-.hljs {
+/* This is based on the output of running Pandoc with the `--standalone` flag and
+ * `--highlight-style pygments`, with hardcoded colors replaced with CSS
+ * variables.
+ *
+ * The names referred to in the comments are from: https://docs.kde.org/trunk5/en/kate/katepart/highlight.html
+ * (See header "Available Default Styles".)
+ */
+div.sourceCode {
color: var(--code-color);
background: var(--code-bg-color);
}
-.hljs-comment, .hljs-quote {
- color: var(--code-comment-color);
- font-style: italic
-}
-
-.hljs-doctag, .hljs-formula, .hljs-keyword {
- color: var(--code-kw-color);
-}
-
-.hljs-deletion, .hljs-name, .hljs-section, .hljs-selector-tag, .hljs-subst {
- color: var(--code-name-color);
-}
-
-.hljs-literal, .hljs-number {
- color: var(--code-literal-color);
-}
-
-.hljs-addition, .hljs-attribute, .hljs-meta .hljs-string, .hljs-regexp, .hljs-string {
- color: var(--code-string-color);
-}
-
-.hljs-type {
- color: var(--code-constructor-color);
-}
-
-.hljs-attr, .hljs-selector-attr, .hljs-selector-class, .hljs-selector-pseudo, .hljs-template-variable, .hljs-variable {
- color: var(--code-attr-color);
-}
-
-.hljs-meta {
- color: var(--code-pragma-color);
-}
-
-.hljs-bullet, .hljs-link, .hljs-selector-id, .hljs-symbol, .hljs-title {
- color: var(--code-symbol-color);
-}
-
-.hljs-built_in, .hljs-class .hljs-title, .hljs-title.class_ {
- color: var(--record-field-color);
-}
-
-.hljs-emphasis {
- font-style: italic
-}
-
-.hljs-strong {
- font-weight: 700
-}
-
-.hljs-link {
- text-decoration: underline
-}
+code span.al { color: var(); font-weight: bold; } /* Alert */
+code span.an { color: var(--code-comment-color); font-weight: bold; font-style: italic; } /* Annotation */
+code span.at { color: var(--code-pragma-color); } /* Attribute */
+code span.bn { color: var(--code-literal-color); } /* BaseN */
+code span.bu { color: var(--code-name-color); } /* BuiltIn */
+code span.cf { color: var(--code-kw-color); font-weight: bold; } /* ControlFlow */
+code span.ch { color: var(--code-literal-color); } /* Char */
+code span.cn { color: var(--code-symbol-color); } /* Constant */
+code span.co { color: var(--code-comment-color); font-style: italic; } /* Comment */
+code span.cv { color: var(--code-comment-color); font-weight: bold; font-style: italic; } /* CommentVar */
+code span.do { color: var(--code-comment-color); font-style: italic; } /* Documentation */
+code span.dt { color: var(--code-constructor-color); } /* DataType */
+code span.dv { color: var(--code-literal-color); } /* DecVal */
+code span.er { color: var(); font-weight: bold; } /* Error */
+code span.ex { } /* Extension */
+code span.fl { color: var(--code-literal-color); } /* Float */
+code span.fu { color: var(--code-color); } /* Function */
+code span.im { color: var(--code-kw-color); font-weight: bold; } /* Import */
+code span.in { color: var(); font-weight: bold; font-style: italic; } /* Information */
+code span.kw { color: var(--code-kw-color); font-weight: bold; } /* Keyword */
+code span.op { color: var(--code-symbol-color); } /* Operator */
+code span.ot { color: var(--code-color); } /* Other */
+code span.pp { color: var(--code-comment-color); } /* Preprocessor */
+code span.sc { color: var(--code-literal-color); } /* SpecialChar */
+code span.ss { color: var(--code-string-color); } /* SpecialString */
+code span.st { color: var(--code-string-color); } /* String */
+code span.va { color: var(--code-attr-color); } /* Variable */
+code span.vs { color: var(--code-string-color); } /* VerbatimString */
+code span.wa { color: var(); font-weight: bold; font-style: italic; } /* Warning */
diff --git a/message-index/message-index.cabal b/message-index/message-index.cabal
index 2270da6f..1f7fa7fd 100644
--- a/message-index/message-index.cabal
+++ b/message-index/message-index.cabal
@@ -12,6 +12,7 @@ executable site
, microlens ^>= 0.4.12
, binary ^>= 0.8.8
, aeson ^>= 2.0.3 || ^>= 2.1
+ , pandoc ^>= 3.1.3
, pandoc-types ^>= 1.22 || ^>= 1.23
, containers ^>= 0.6
, text ^>= 1.2 || ^>= 2.0
diff --git a/message-index/site.hs b/message-index/site.hs
index 2dc74d2e..cfcce148 100644
--- a/message-index/site.hs
+++ b/message-index/site.hs
@@ -22,7 +22,8 @@ import Hakyll
import Lens.Micro (_1, _2, _3)
import Lens.Micro.Extras (view)
import System.FilePath
-import Text.Pandoc.Definition (Meta (..), MetaValue (..), Pandoc (..))
+import qualified Text.Pandoc as Pandoc
+import qualified Text.Pandoc.Definition as Pandoc
main :: IO ()
main = hakyll $ do
@@ -76,13 +77,9 @@ main = hakyll $ do
( mconcat
[ indexlessUrlField "url",
field "name" (pure . view _1 . itemBody),
- -- Set the language that highlight.js should use for syntax highlighting
- field "language" $ \(itemBody -> (filename, _, _)) ->
- pure $ case dropWhile (== '.') $ takeExtension filename of
- "hs" -> "haskell"
- other -> other,
- field "before" (maybe (pure "") (fmap itemBody . load . itemIdentifier) . view _2 . itemBody),
- field "after" (maybe (pure "") (fmap itemBody . load . itemIdentifier) . view _3 . itemBody)
+ -- TODO: pick the right language
+ field "beforeHighlighted" (maybe (pure "") (fmap (T.unpack . highlight "haskell" . T.pack) . fmap itemBody . load . itemIdentifier) . view _2 . itemBody),
+ field "afterHighlighted" (maybe (pure "") (fmap (T.unpack . highlight "haskell" . T.pack) . fmap itemBody . load . itemIdentifier) . view _3 . itemBody)
]
)
(return files),
@@ -287,3 +284,13 @@ indexless url
where
lru = reverse url
toDrop = "index.html"
+
+highlight :: T.Text -> T.Text -> T.Text
+highlight language code =
+ let writerOptions = Pandoc.def
+ -- We make a fake Pandoc document that's just the code embedded in a code block.
+ document =
+ Pandoc.Pandoc mempty [Pandoc.CodeBlock ("", [language], []) code]
+ in case Pandoc.runPure $ Pandoc.writeHtml5String writerOptions document of
+ Left err -> error $ "Unexpected Pandoc error: " ++ show err
+ Right html -> html
diff --git a/message-index/templates/default.html b/message-index/templates/default.html
index aeb02e91..4d03e694 100644
--- a/message-index/templates/default.html
+++ b/message-index/templates/default.html
@@ -8,7 +8,6 @@
$title$ — Haskell Error Index
-
@@ -35,10 +34,6 @@ $title$
Hakyll
-
-