Skip to content

Commit

Permalink
Added skeleton for reader.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Jan 13, 2024
1 parent 2dd98b9 commit bc67ffd
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ tests: True
flags: +embed_data_files
constraints: skylighting-format-blaze-html >= 0.1.1.1,
skylighting-format-context >= 0.1.0.2

source-repository-package
type: git
location: https://github.com/jgm/djoths
tag: 511129ccc466acfb948187ff7b0e1ad94c6d1120
4 changes: 3 additions & 1 deletion pandoc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ library
zlib >= 0.5 && < 0.7,
xml >= 1.3.12 && < 1.4,
typst >= 0.5 && < 0.5.1,
vector >= 0.12 && < 0.14
vector >= 0.12 && < 0.14,
djot >= 0.1 && < 0.2

if !os(windows)
build-depends: unix >= 2.4 && < 2.9
Expand Down Expand Up @@ -580,6 +581,7 @@ library
Text.Pandoc.Readers.CSV,
Text.Pandoc.Readers.RTF,
Text.Pandoc.Readers.Typst,
Text.Pandoc.Readers.Djot,
Text.Pandoc.Writers,
Text.Pandoc.Writers.Native,
Text.Pandoc.Writers.DocBook,
Expand Down
1 change: 1 addition & 0 deletions src/Text/Pandoc/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ formatFromFilePath x =
".csv" -> defFlavor "csv"
".ctx" -> defFlavor "context"
".db" -> defFlavor "docbook"
".dj" -> defFlavor "djot"
".doc" -> defFlavor "doc" -- so we get an "unknown reader" error
".docx" -> defFlavor "docx"
".dokuwiki" -> defFlavor "dokuwiki"
Expand Down
4 changes: 3 additions & 1 deletion src/Text/Pandoc/Readers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import Text.Pandoc.Readers.EndNote
import Text.Pandoc.Readers.RIS
import Text.Pandoc.Readers.RTF
import Text.Pandoc.Readers.Typst
import Text.Pandoc.Readers.Djot
import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.Sources (ToSources(..), sourcesToText)

Expand Down Expand Up @@ -164,7 +165,8 @@ readers = [("native" , TextReader readNative)
,("ris" , TextReader readRIS)
,("rtf" , TextReader readRTF)
,("typst" , TextReader readTypst)
]
,("djot" , TextReader readDjot)
]

-- | Retrieve reader, extensions based on format spec (format+extensions).
getReader :: PandocMonad m => Format.FlavoredFormat -> m (Reader m, Extensions)
Expand Down
51 changes: 51 additions & 0 deletions src/Text/Pandoc/Readers/Djot.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE ScopedTypeVariables #-}

{- |
Module : Text.Pandoc.Readers.Djot
Copyright : Copyright (C) 2024 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <[email protected]>
Stability : alpha
Portability : portable
Reads and evaluates a Djot document as a Pandoc AST.
-}
module Text.Pandoc.Readers.Djot
( readDjot
)
where

import Text.Pandoc.Class
import Text.Pandoc.Sources
import Text.Parsec.Pos (sourceName) -- TODO export from T.P.Sources?
import Text.Pandoc.Options
import Text.Pandoc.Definition
import qualified Text.Pandoc.UTF8 as UTF8
import Djot.Options (ParseOptions(..))
import Djot.Blocks (parseDoc)
import qualified Djot.AST as D
import Text.Pandoc.Error (PandocError(..))
import Control.Monad.Except (throwError)
import qualified Data.Text as T

-- import Debug.Trace

-- | Read Djot from an input string and return a Pandoc document.
readDjot :: (PandocMonad m, ToSources a) => ReaderOptions -> a -> m Pandoc
readDjot _opts inp = do
let sources = toSources inp
let inputName = case sources of
Sources ((pos, _):_) -> sourceName pos
_ -> ""
case parseDoc ParseOptions{ optSourcePositions = False }
(UTF8.fromText $ sourcesToText sources) of
Left e -> throwError $ PandocParseError $ T.pack $ show e
Right doc -> do
pure $ Pandoc mempty mempty -- TODO
2 changes: 2 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ extra-deps:
- commonmark-extensions-0.2.5.1
- commonmark-pandoc-0.2.2
- typst-0.5
- git: https://github.com/jgm/djoths
commit: 511129ccc466acfb948187ff7b0e1ad94c6d1120

ghc-options:
"$locals": -fhide-source-paths -Wno-missing-home-modules
Expand Down

0 comments on commit bc67ffd

Please sign in to comment.