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
build-depends:
base,
bytestring,
containers,
data-default,
pandoc,

View File

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