-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve dark mode; also change source code highlighting
- Loading branch information
1 parent
86e6bd8
commit 98d54d2
Showing
7 changed files
with
201 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
module HighlightCSS ( | ||
processHighlightCSS, | ||
) where | ||
|
||
import Control.Monad (void) | ||
import Data.ByteString (ByteString) | ||
import qualified Data.ByteString.Char8 as BS8 | ||
import Data.Char (isSpace) | ||
import Data.List (intercalate) | ||
import Text.Parsec | ||
|
||
|
||
processHighlightCSS :: IO ByteString | ||
processHighlightCSS = do | ||
cssl <- parseCSS "highlight-light.pack.css" <$> readFile "highlight-light.pack.css" | ||
cssd <- parseCSS "highlight-dark.pack.css" <$> readFile "highlight-dark.pack.css" | ||
let css = namespaceSels (Selector ".clrl") cssl <> namespaceSels (Selector ".clrd") cssd | ||
result = BS8.pack (writeCSS css) | ||
result `seq` return result | ||
|
||
|
||
namespaceSels :: Selector -> CSS -> CSS | ||
namespaceSels sel (CSS items) = | ||
CSS [(mc, [Block (map (sel <>) sels) rules | ||
| Block sels rules <- blocks]) | ||
| (mc, blocks) <- items] | ||
|
||
|
||
newtype CSS = CSS [(Maybe Comment, [Block])] | ||
deriving (Show) | ||
|
||
data Block = Block [Selector] [Rule] | ||
deriving (Show) | ||
|
||
newtype Selector = Selector String | ||
deriving (Show) | ||
|
||
data Rule = Rule String String | ||
deriving (Show) | ||
|
||
newtype Comment = Comment String | ||
deriving (Show) | ||
|
||
instance Semigroup CSS where | ||
CSS l <> CSS l' = CSS (l ++ l') | ||
|
||
instance Semigroup Selector where | ||
Selector s <> Selector s' = Selector (s ++ ' ' : s') | ||
|
||
parseCSS :: FilePath -> String -> CSS | ||
parseCSS fname s = | ||
case parse (pCSS <* eof) fname s of | ||
Left err -> error (show err) | ||
Right res -> res | ||
|
||
writeCSS :: CSS -> String | ||
writeCSS (CSS items) = | ||
intercalate "\n" | ||
[maybe "" (\(Comment c) -> "/*" ++ c ++ "*/\n") mcomment ++ | ||
concat [intercalate "," [s | Selector s <- sels] ++ | ||
"{" ++ | ||
intercalate ";" [k ++ ":" ++ v | Rule k v <- rules] ++ | ||
"}" | ||
| Block sels rules <- blocks] | ||
| (mcomment, blocks) <- items] | ||
|
||
type Parser = Parsec String () | ||
|
||
pCSS :: Parser CSS | ||
pCSS = CSS <$> many ((,) <$> optionMaybe pHeaderComment <*> many1 pBlock) | ||
|
||
pHeaderComment :: Parser Comment | ||
pHeaderComment = do | ||
string' "/*" | ||
s <- manyTill anyChar (string' "*/") | ||
void endOfLine | ||
return (Comment s) | ||
|
||
pBlock :: Parser Block | ||
pBlock = do | ||
sels <- pSelector `sepBy1` (try (whitespace >> char ',') >> whitespace) | ||
whitespace | ||
void $ char '{' | ||
rules <- pRule `sepBy` (try (whitespace >> char ';') >> whitespace) | ||
whitespace | ||
void $ char '}' | ||
whitespace | ||
return (Block sels rules) | ||
|
||
pSelector :: Parser Selector | ||
pSelector = Selector <$> many (noneOf ",{}") | ||
|
||
pRule :: Parser Rule | ||
pRule = do | ||
key <- try (whitespace >> many1 (satisfy (\c -> c `notElem` ":;}" && not (isSpace c)))) | ||
whitespace | ||
void $ char ':' | ||
whitespace | ||
value <- many (noneOf ";}") | ||
return (Rule key value) | ||
|
||
string' :: String -> Parser () | ||
string' s = void (try (string s)) | ||
|
||
whitespace :: Parser () | ||
whitespace = void (many (satisfy isSpace)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,19 +8,20 @@ author: Tom Smeding | |
maintainer: [email protected] | ||
build-type: Simple | ||
homepage: https://github.com/tomsmeding/pastebin-haskell | ||
extra-source-files: index.mustache read.mustache highlight.pack.css highlight.pack.js | ||
extra-source-files: index.mustache read.mustache highlight-light.pack.css highlight-dark.pack.css highlight.pack.js | ||
extra-source-files: migrate_db_1_2.sh migrate_db_2_3.sh migrate_db_3_4.sh migrate_db_4_5.sh | ||
extra-source-files: robots.txt ChangeLog.md | ||
|
||
executable pastebin-haskell | ||
main-is: Main.hs | ||
other-modules: Archive, DB, Options, Pages, SpamDetect | ||
other-modules: Archive, DB, HighlightCSS, Options, Pages, SpamDetect | ||
build-depends: base >= 4.13 && < 4.15, | ||
array >= 0.5.4 && < 0.6, | ||
bytestring >= 0.10.12 && < 0.11, | ||
containers >= 0.6.3.1 && < 0.7, | ||
clock >= 0.8 && < 0.9, | ||
mustache >= 2.3.1 && < 2.4, | ||
parsec >= 3.1.14.0 && < 3.2, | ||
stm >= 2.5 && < 2.6, | ||
random >= 1.2.0 && < 1.3, | ||
snap-server >= 1.1.1.2 && < 1.2, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters