Tuota hyödyllisempiä virheitä huonosti koodatusta syötteestä
This commit is contained in:
parent
824a0e1645
commit
d355a1658d
|
@ -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,
|
||||||
|
|
|
@ -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,8 +17,11 @@ 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
|
||||||
|
Left err -> throwIO err
|
||||||
|
Right text -> do
|
||||||
|
pandoc <- handleError $ readMD text
|
||||||
out <- handleError $ runPure $ writeHtml5String def $ pandocFilter pandoc
|
out <- handleError $ runPure $ writeHtml5String def $ pandocFilter pandoc
|
||||||
T.putStr out
|
T.putStr out
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue