Tuota hyödyllisempiä virheitä huonosti koodatusta syötteestä

This commit is contained in:
Saku Laesvuori 2023-11-21 12:44:07 +02:00
parent 824a0e1645
commit d355a1658d
2 changed files with 12 additions and 5 deletions

View File

@ -10,6 +10,7 @@ stability: alpha
executable gitea-markdown executable gitea-markdown
build-depends: build-depends:
base, base,
bytestring,
containers, containers,
data-default, data-default,
pandoc, pandoc,

View File

@ -2,10 +2,13 @@
module Gitea.Preview.Markdown where module Gitea.Preview.Markdown where
import Control.Exception (throwIO)
import Data.Default (def) import Data.Default (def)
import Text.Pandoc (Pandoc, PandocError, ReaderOptions(..), readMarkdown, runPure, handleError, pandocExtensions, writeHtml5String)
import Data.Text (Text) import Data.Text (Text)
import Data.Text.Encoding (decodeUtf8')
import Text.Pandoc (Pandoc, PandocError, ReaderOptions(..), readMarkdown, runPure, handleError, pandocExtensions, writeHtml5String)
import qualified Data.ByteString as BS
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
import Gitea.Preview.Markdown.Math import Gitea.Preview.Markdown.Math
@ -14,10 +17,13 @@ import Gitea.Preview.Markdown.Signatures
main :: IO () main :: IO ()
main = do main = do
input <- T.getContents input <- decodeUtf8' <$> BS.getContents
pandoc <- handleError $ readMD input case input of
out <- handleError $ runPure $ writeHtml5String def $ pandocFilter pandoc Left err -> throwIO err
T.putStr out Right text -> do
pandoc <- handleError $ readMD text
out <- handleError $ runPure $ writeHtml5String def $ pandocFilter pandoc
T.putStr out
pandocFilter :: Pandoc -> Pandoc pandocFilter :: Pandoc -> Pandoc
pandocFilter = renderSignatures' pandocFilter = renderSignatures'