From b8b226d15cc58ba264e8daea07337b785fe14a49 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Mon, 27 May 2019 13:28:57 +0000 Subject: [PATCH] Highlight code segments in pandoc rendered source file views --- config/routes | 2 + src/Vervis/Handler/Repo.hs | 8 +- src/Vervis/Handler/Repo/Darcs.hs | 6 +- src/Vervis/Handler/Repo/Git.hs | 6 +- src/Vervis/Render.hs | 2 +- templates/repo/source-darcs.cassius | 295 ---------------------------- templates/repo/source-git.cassius | 295 ---------------------------- vervis.cabal | 2 - 8 files changed, 18 insertions(+), 598 deletions(-) delete mode 100644 templates/repo/source-darcs.cassius delete mode 100644 templates/repo/source-git.cassius diff --git a/config/routes b/config/routes index 9012106..a029cd4 100644 --- a/config/routes +++ b/config/routes @@ -20,6 +20,8 @@ /favicon.ico FaviconR GET /robots.txt RobotsR GET +/highlight.css HighlightStyleR GET + -- ---------------------------------------------------------------------------- -- Federation -- ---------------------------------------------------------------------------- diff --git a/src/Vervis/Handler/Repo.hs b/src/Vervis/Handler/Repo.hs index 79c7207..49ab1cb 100644 --- a/src/Vervis/Handler/Repo.hs +++ b/src/Vervis/Handler/Repo.hs @@ -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 diff --git a/src/Vervis/Handler/Repo/Darcs.hs b/src/Vervis/Handler/Repo/Darcs.hs index 7cdd436..adc19c9 100644 --- a/src/Vervis/Handler/Repo/Darcs.hs +++ b/src/Vervis/Handler/Repo/Darcs.hs @@ -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 diff --git a/src/Vervis/Handler/Repo/Git.hs b/src/Vervis/Handler/Repo/Git.hs index 2664155..44abeac 100644 --- a/src/Vervis/Handler/Repo/Git.hs +++ b/src/Vervis/Handler/Repo/Git.hs @@ -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 = diff --git a/src/Vervis/Render.hs b/src/Vervis/Render.hs index 51539bf..f5a544e 100644 --- a/src/Vervis/Render.hs +++ b/src/Vervis/Render.hs @@ -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 diff --git a/templates/repo/source-darcs.cassius b/templates/repo/source-darcs.cassius deleted file mode 100644 index 4b1cb13..0000000 --- a/templates/repo/source-darcs.cassius +++ /dev/null @@ -1,295 +0,0 @@ -/* This file is part of Vervis. - * - * Written in 2016 by fr33domlover . - * - * ♡ 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 - * . - */ - -/* 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 diff --git a/templates/repo/source-git.cassius b/templates/repo/source-git.cassius deleted file mode 100644 index 4b1cb13..0000000 --- a/templates/repo/source-git.cassius +++ /dev/null @@ -1,295 +0,0 @@ -/* This file is part of Vervis. - * - * Written in 2016 by fr33domlover . - * - * ♡ 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 - * . - */ - -/* 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 diff --git a/vervis.cabal b/vervis.cabal index 4d589fc..d5f685e 100644 --- a/vervis.cabal +++ b/vervis.cabal @@ -325,8 +325,6 @@ library , resourcet , safe , shakespeare - -- for pandoc inline code highlighting - , skylighting , smtp-mail , ssh -- for holding actor key in a TVar