Highlight code segments in pandoc rendered source file views
This commit is contained in:
parent
3bf7dbea7d
commit
b8b226d15c
8 changed files with 18 additions and 598 deletions
|
@ -20,6 +20,8 @@
|
|||
/favicon.ico FaviconR GET
|
||||
/robots.txt RobotsR GET
|
||||
|
||||
/highlight.css HighlightStyleR GET
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- Federation
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
|
|
@ -33,6 +33,8 @@ module Vervis.Handler.Repo
|
|||
, deleteRepoDevR
|
||||
, postRepoDevR
|
||||
, getDarcsDownloadR
|
||||
|
||||
, getHighlightStyleR
|
||||
)
|
||||
where
|
||||
|
||||
|
@ -62,9 +64,10 @@ import Formatting (sformat, stext, (%))
|
|||
import System.Directory
|
||||
import System.Hourglass (dateCurrent)
|
||||
import Text.Blaze.Html (Html)
|
||||
import Text.Pandoc.Highlighting
|
||||
import Yesod.Auth (requireAuthId)
|
||||
import Yesod.Core (defaultLayout, setMessage)
|
||||
import Yesod.Core.Content (TypedContent)
|
||||
import Yesod.Core.Content
|
||||
import Yesod.Core.Handler (lookupPostParam, redirect, notFound)
|
||||
import Yesod.Form.Functions (runFormPost)
|
||||
import Yesod.Form.Types (FormResult (..))
|
||||
|
@ -359,3 +362,6 @@ postRepoDevR shr rp dev = do
|
|||
case mmethod of
|
||||
Just "DELETE" -> deleteRepoDevR shr rp dev
|
||||
_ -> notFound
|
||||
|
||||
getHighlightStyleR :: Handler TypedContent
|
||||
getHighlightStyleR = pure $ TypedContent typeCss $ toContent $ styleToCss tango
|
||||
|
|
|
@ -36,7 +36,7 @@ import Network.HTTP.Types (StdMethod (DELETE))
|
|||
import System.FilePath ((</>), joinPath)
|
||||
import System.Directory (doesFileExist)
|
||||
import Text.Blaze.Html (Html)
|
||||
import Yesod.Core (defaultLayout, setTitle)
|
||||
import Yesod.Core hiding (joinPath)
|
||||
import Yesod.Core.Content (TypedContent, typeOctet)
|
||||
import Yesod.Core.Handler (selectRep, provideRep, sendFile, notFound)
|
||||
import Yesod.Persist.Core (runDB, get404)
|
||||
|
@ -83,7 +83,9 @@ getDarcsRepoSource repository user repo dir = do
|
|||
Just sv -> do
|
||||
let parent = if null dir then [] else init dir
|
||||
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 shar repo = do
|
||||
|
|
|
@ -46,7 +46,7 @@ import Network.HTTP.Types (StdMethod (DELETE))
|
|||
import System.Directory (createDirectoryIfMissing)
|
||||
import System.Hourglass (dateCurrent)
|
||||
import Text.Blaze.Html (Html)
|
||||
import Yesod.Core (defaultLayout)
|
||||
import Yesod.Core
|
||||
import Yesod.Core.Content (TypedContent)
|
||||
import Yesod.Core.Handler (selectRep, provideRep, notFound)
|
||||
import Yesod.Persist.Core (runDB, get404)
|
||||
|
@ -93,7 +93,9 @@ getGitRepoSource repository user repo ref dir = do
|
|||
Just sv -> do
|
||||
let parent = if null dir then [] else init dir
|
||||
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 repository shar repo =
|
||||
|
|
|
@ -55,10 +55,10 @@ import Text.Blaze.Html (preEscapedToMarkup)
|
|||
import Text.Blaze.Html.Renderer.Text (renderHtml)
|
||||
import Text.Highlighter (lexerFromFilename, runLexer, Lexer (lName))
|
||||
import Text.Highlighter.Formatters.Html (format)
|
||||
import Skylighting.Styles (tango)
|
||||
import Text.HTML.SanitizeXSS (sanitizeBalance)
|
||||
import Text.Pandoc.Class (runPure)
|
||||
import Text.Pandoc.Definition (Pandoc)
|
||||
import Text.Pandoc.Highlighting
|
||||
import Text.Pandoc.Options
|
||||
import Text.Pandoc.Readers.Markdown
|
||||
import Text.Pandoc.Writers.HTML
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -325,8 +325,6 @@ library
|
|||
, resourcet
|
||||
, safe
|
||||
, shakespeare
|
||||
-- for pandoc inline code highlighting
|
||||
, skylighting
|
||||
, smtp-mail
|
||||
, ssh
|
||||
-- for holding actor key in a TVar
|
||||
|
|
Loading…
Reference in a new issue