Highlight code segments in pandoc rendered source file views

This commit is contained in:
fr33domlover 2019-05-27 13:28:57 +00:00
parent 3bf7dbea7d
commit b8b226d15c
8 changed files with 18 additions and 598 deletions

View file

@ -20,6 +20,8 @@
/favicon.ico FaviconR GET /favicon.ico FaviconR GET
/robots.txt RobotsR GET /robots.txt RobotsR GET
/highlight.css HighlightStyleR GET
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
-- Federation -- Federation
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------

View file

@ -33,6 +33,8 @@ module Vervis.Handler.Repo
, deleteRepoDevR , deleteRepoDevR
, postRepoDevR , postRepoDevR
, getDarcsDownloadR , getDarcsDownloadR
, getHighlightStyleR
) )
where where
@ -62,9 +64,10 @@ import Formatting (sformat, stext, (%))
import System.Directory import System.Directory
import System.Hourglass (dateCurrent) import System.Hourglass (dateCurrent)
import Text.Blaze.Html (Html) import Text.Blaze.Html (Html)
import Text.Pandoc.Highlighting
import Yesod.Auth (requireAuthId) import Yesod.Auth (requireAuthId)
import Yesod.Core (defaultLayout, setMessage) import Yesod.Core (defaultLayout, setMessage)
import Yesod.Core.Content (TypedContent) import Yesod.Core.Content
import Yesod.Core.Handler (lookupPostParam, redirect, notFound) import Yesod.Core.Handler (lookupPostParam, redirect, notFound)
import Yesod.Form.Functions (runFormPost) import Yesod.Form.Functions (runFormPost)
import Yesod.Form.Types (FormResult (..)) import Yesod.Form.Types (FormResult (..))
@ -359,3 +362,6 @@ postRepoDevR shr rp dev = do
case mmethod of case mmethod of
Just "DELETE" -> deleteRepoDevR shr rp dev Just "DELETE" -> deleteRepoDevR shr rp dev
_ -> notFound _ -> notFound
getHighlightStyleR :: Handler TypedContent
getHighlightStyleR = pure $ TypedContent typeCss $ toContent $ styleToCss tango

View file

@ -36,7 +36,7 @@ import Network.HTTP.Types (StdMethod (DELETE))
import System.FilePath ((</>), joinPath) import System.FilePath ((</>), joinPath)
import System.Directory (doesFileExist) import System.Directory (doesFileExist)
import Text.Blaze.Html (Html) import Text.Blaze.Html (Html)
import Yesod.Core (defaultLayout, setTitle) import Yesod.Core hiding (joinPath)
import Yesod.Core.Content (TypedContent, typeOctet) import Yesod.Core.Content (TypedContent, typeOctet)
import Yesod.Core.Handler (selectRep, provideRep, sendFile, notFound) import Yesod.Core.Handler (selectRep, provideRep, sendFile, notFound)
import Yesod.Persist.Core (runDB, get404) import Yesod.Persist.Core (runDB, get404)
@ -83,7 +83,9 @@ getDarcsRepoSource repository user repo dir = do
Just sv -> do Just sv -> do
let parent = if null dir then [] else init dir let parent = if null dir then [] else init dir
dirs = zip parent (tail $ inits parent) dirs = zip parent (tail $ inits parent)
defaultLayout $(widgetFile "repo/source-darcs") defaultLayout $ do
addStylesheet HighlightStyleR
$(widgetFile "repo/source-darcs")
getDarcsRepoHeadChanges :: ShrIdent -> RpIdent -> Handler TypedContent getDarcsRepoHeadChanges :: ShrIdent -> RpIdent -> Handler TypedContent
getDarcsRepoHeadChanges shar repo = do getDarcsRepoHeadChanges shar repo = do

View file

@ -46,7 +46,7 @@ import Network.HTTP.Types (StdMethod (DELETE))
import System.Directory (createDirectoryIfMissing) import System.Directory (createDirectoryIfMissing)
import System.Hourglass (dateCurrent) import System.Hourglass (dateCurrent)
import Text.Blaze.Html (Html) import Text.Blaze.Html (Html)
import Yesod.Core (defaultLayout) import Yesod.Core
import Yesod.Core.Content (TypedContent) import Yesod.Core.Content (TypedContent)
import Yesod.Core.Handler (selectRep, provideRep, notFound) import Yesod.Core.Handler (selectRep, provideRep, notFound)
import Yesod.Persist.Core (runDB, get404) import Yesod.Persist.Core (runDB, get404)
@ -93,7 +93,9 @@ getGitRepoSource repository user repo ref dir = do
Just sv -> do Just sv -> do
let parent = if null dir then [] else init dir let parent = if null dir then [] else init dir
dirs = zip parent (tail $ inits parent) dirs = zip parent (tail $ inits parent)
defaultLayout $(widgetFile "repo/source-git") defaultLayout $ do
addStylesheet HighlightStyleR
$(widgetFile "repo/source-git")
getGitRepoHeadChanges :: Repo -> ShrIdent -> RpIdent -> Handler TypedContent getGitRepoHeadChanges :: Repo -> ShrIdent -> RpIdent -> Handler TypedContent
getGitRepoHeadChanges repository shar repo = getGitRepoHeadChanges repository shar repo =

View file

@ -55,10 +55,10 @@ import Text.Blaze.Html (preEscapedToMarkup)
import Text.Blaze.Html.Renderer.Text (renderHtml) import Text.Blaze.Html.Renderer.Text (renderHtml)
import Text.Highlighter (lexerFromFilename, runLexer, Lexer (lName)) import Text.Highlighter (lexerFromFilename, runLexer, Lexer (lName))
import Text.Highlighter.Formatters.Html (format) import Text.Highlighter.Formatters.Html (format)
import Skylighting.Styles (tango)
import Text.HTML.SanitizeXSS (sanitizeBalance) import Text.HTML.SanitizeXSS (sanitizeBalance)
import Text.Pandoc.Class (runPure) import Text.Pandoc.Class (runPure)
import Text.Pandoc.Definition (Pandoc) import Text.Pandoc.Definition (Pandoc)
import Text.Pandoc.Highlighting
import Text.Pandoc.Options import Text.Pandoc.Options
import Text.Pandoc.Readers.Markdown import Text.Pandoc.Readers.Markdown
import Text.Pandoc.Writers.HTML import Text.Pandoc.Writers.HTML

View file

@ -1,295 +0,0 @@
/* This file is part of Vervis.
*
* Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
*
* ♡ Copying is an act of love. Please copy, reuse and share.
*
* The author(s) have dedicated all copyright and related and neighboring
* rights to this software to the public domain worldwide. This software is
* distributed without any warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication along
* with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
/* Comment */
.c
color: #ff0000
background-color: #ffffff
/* Error */
.err
color: #ff0000
background-color: #ffffff
/* Keyword */
.k
color: #{dark magenta}
/* Comment.Multiline */
.cm
color: #{dark blue}
/* Comment.Preproc */
.cp
color: #ff0000
background-color: #ffffff
/* Comment.Single */
.c1
color: #{dark blue}
/* Comment.Special */
.cs
color: #ff0000
background-color: #ffffff
/* Generic.Deleted */
.gd
color: #ff0000
background-color: #ffffff
/* Generic.Emph */
.ge
font-style: italic
/* Generic.Error */
.gr
color: #ff0000
background-color: #ffffff
/* Generic.Heading */
.gh
color: #ff0000
background-color: #ffffff
/* Generic.Inserted */
.gi
color: #ff0000
background-color: #ffffff
/* Generic.Output */
.go
color: #ff0000
background-color: #ffffff
/* Generic.Prompt */
.gp
color: #ff0000
background-color: #ffffff
/* Generic.Strong */
.gs
font-weight: bold
/* Generic.Subheading */
.gu
color: #ff0000
background-color: #ffffff
/* Generic.Traceback */
.gt
color: #ff0000
background-color: #ffffff
/* Keyword.Constant */
.kc
color: #ff0000
background-color: #ffffff
/* Keyword.Declaration */
.kd
color: #ff0000
background-color: #ffffff
/* Keyword.Namespace */
.kn
color: #ff0000
background-color: #ffffff
/* Keyword.Pseudo */
.kp
color: #ff0000
background-color: #ffffff
/* Keyword.Reserved */
.kr
color: #{dark green}
/* Keyword.Type */
.kt
color: #{plain}
/* Literal.Number */
.m
color: #ff0000
background-color: #ffffff
/* Literal.String */
.s
color: #{dark red}
/* Name.Attribute */
.na
color: #ff0000
background-color: #ffffff
/* Name.Builtin */
.nb
color: #{plain}
/* Name.Class */
.nc
color: #ff0000
background-color: #ffffff
/* Name.Constant */
.no
color: #ff0000
background-color: #ffffff
/* Name.Decorator */
.nd
color: #ff0000
background-color: #ffffff
/* Name.Exception */
.ne
color: #ff0000
background-color: #ffffff
/* Name.Function */
.nf
color: #{plain}
/* Name.Label */
.nl
color: #ff0000
background-color: #ffffff
/* Name.Namespace */
.nn
color: #{plain}
/* Name.Property */
.py
color: #ff0000
background-color: #ffffff
/* Name.Tag */
.nt
color: #ff0000
background-color: #ffffff
/* Name.Variable */
.nv
color: #ff0000
background-color: #ffffff
/* Operator.Word */
.ow
color: #{dark yellow}
/* Text.Whitespace */
.w
color: #ff0000
background-color: #ffffff
/* Literal.Number.Float */
.mf
color: #ff0000
background-color: #ffffff
/* Literal.Number.Hex */
.mh
color: #ff0000
background-color: #ffffff
/* Literal.Number.Integer */
.mi
color: #{dark red}
/* Literal.Number.Oct */
.mo
color: #ff0000
background-color: #ffffff
/* Literal.String.Backtick */
.sb
color: #ff0000
background-color: #ffffff
/* Literal.String.Char */
.sc
color: #ff0000
background-color: #ffffff
/* Literal.String.Doc */
.sd
color: #ff0000
background-color: #ffffff
/* Literal.String.Double */
.s2
color: #ff0000
background-color: #ffffff
/* Literal.String.Escape */
.se
color: #{dark magenta}
/* Literal.String.Heredoc */
.sh
color: #dd2200
background-color: #fff0f0
/* Literal.String.Interpol */
.si
color: #ff0000
background-color: #ffffff
/* Literal.String.Other */
.sx
color: #ff0000
background-color: #ffffff
/* Literal.String.Regex */
.sr
color: #ff0000
background-color: #ffffff
/* Literal.String.Single */
.s1
color: #ff0000
background-color: #ffffff
/* Literal.String.Symbol */
.ss
color: #ff0000
background-color: #ffffff
/* Name.Builtin.Pseudo */
.bp
color: #ff0000
background-color: #ffffff
/* Name.Variable.Class */
.vc
color: #ff0000
background-color: #ffffff
/* Name.Variable.Global */
.vg
color: #ff0000
background-color: #ffffff
/* Name.Variable.Instance */
.vi
color: #ff0000
background-color: #ffffff
/* Literal.Number.Integer.Long */
.il
color: #ff0000
background-color: #ffffff

View file

@ -1,295 +0,0 @@
/* This file is part of Vervis.
*
* Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
*
* ♡ Copying is an act of love. Please copy, reuse and share.
*
* The author(s) have dedicated all copyright and related and neighboring
* rights to this software to the public domain worldwide. This software is
* distributed without any warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication along
* with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
/* Comment */
.c
color: #ff0000
background-color: #ffffff
/* Error */
.err
color: #ff0000
background-color: #ffffff
/* Keyword */
.k
color: #{dark magenta}
/* Comment.Multiline */
.cm
color: #{dark blue}
/* Comment.Preproc */
.cp
color: #ff0000
background-color: #ffffff
/* Comment.Single */
.c1
color: #{dark blue}
/* Comment.Special */
.cs
color: #ff0000
background-color: #ffffff
/* Generic.Deleted */
.gd
color: #ff0000
background-color: #ffffff
/* Generic.Emph */
.ge
font-style: italic
/* Generic.Error */
.gr
color: #ff0000
background-color: #ffffff
/* Generic.Heading */
.gh
color: #ff0000
background-color: #ffffff
/* Generic.Inserted */
.gi
color: #ff0000
background-color: #ffffff
/* Generic.Output */
.go
color: #ff0000
background-color: #ffffff
/* Generic.Prompt */
.gp
color: #ff0000
background-color: #ffffff
/* Generic.Strong */
.gs
font-weight: bold
/* Generic.Subheading */
.gu
color: #ff0000
background-color: #ffffff
/* Generic.Traceback */
.gt
color: #ff0000
background-color: #ffffff
/* Keyword.Constant */
.kc
color: #ff0000
background-color: #ffffff
/* Keyword.Declaration */
.kd
color: #ff0000
background-color: #ffffff
/* Keyword.Namespace */
.kn
color: #ff0000
background-color: #ffffff
/* Keyword.Pseudo */
.kp
color: #ff0000
background-color: #ffffff
/* Keyword.Reserved */
.kr
color: #{dark green}
/* Keyword.Type */
.kt
color: #{plain}
/* Literal.Number */
.m
color: #ff0000
background-color: #ffffff
/* Literal.String */
.s
color: #{dark red}
/* Name.Attribute */
.na
color: #ff0000
background-color: #ffffff
/* Name.Builtin */
.nb
color: #{plain}
/* Name.Class */
.nc
color: #ff0000
background-color: #ffffff
/* Name.Constant */
.no
color: #ff0000
background-color: #ffffff
/* Name.Decorator */
.nd
color: #ff0000
background-color: #ffffff
/* Name.Exception */
.ne
color: #ff0000
background-color: #ffffff
/* Name.Function */
.nf
color: #{plain}
/* Name.Label */
.nl
color: #ff0000
background-color: #ffffff
/* Name.Namespace */
.nn
color: #{plain}
/* Name.Property */
.py
color: #ff0000
background-color: #ffffff
/* Name.Tag */
.nt
color: #ff0000
background-color: #ffffff
/* Name.Variable */
.nv
color: #ff0000
background-color: #ffffff
/* Operator.Word */
.ow
color: #{dark yellow}
/* Text.Whitespace */
.w
color: #ff0000
background-color: #ffffff
/* Literal.Number.Float */
.mf
color: #ff0000
background-color: #ffffff
/* Literal.Number.Hex */
.mh
color: #ff0000
background-color: #ffffff
/* Literal.Number.Integer */
.mi
color: #{dark red}
/* Literal.Number.Oct */
.mo
color: #ff0000
background-color: #ffffff
/* Literal.String.Backtick */
.sb
color: #ff0000
background-color: #ffffff
/* Literal.String.Char */
.sc
color: #ff0000
background-color: #ffffff
/* Literal.String.Doc */
.sd
color: #ff0000
background-color: #ffffff
/* Literal.String.Double */
.s2
color: #ff0000
background-color: #ffffff
/* Literal.String.Escape */
.se
color: #{dark magenta}
/* Literal.String.Heredoc */
.sh
color: #dd2200
background-color: #fff0f0
/* Literal.String.Interpol */
.si
color: #ff0000
background-color: #ffffff
/* Literal.String.Other */
.sx
color: #ff0000
background-color: #ffffff
/* Literal.String.Regex */
.sr
color: #ff0000
background-color: #ffffff
/* Literal.String.Single */
.s1
color: #ff0000
background-color: #ffffff
/* Literal.String.Symbol */
.ss
color: #ff0000
background-color: #ffffff
/* Name.Builtin.Pseudo */
.bp
color: #ff0000
background-color: #ffffff
/* Name.Variable.Class */
.vc
color: #ff0000
background-color: #ffffff
/* Name.Variable.Global */
.vg
color: #ff0000
background-color: #ffffff
/* Name.Variable.Instance */
.vi
color: #ff0000
background-color: #ffffff
/* Literal.Number.Integer.Long */
.il
color: #ff0000
background-color: #ffffff

View file

@ -325,8 +325,6 @@ library
, resourcet , resourcet
, safe , safe
, shakespeare , shakespeare
-- for pandoc inline code highlighting
, skylighting
, smtp-mail , smtp-mail
, ssh , ssh
-- for holding actor key in a TVar -- for holding actor key in a TVar