Skip to content

Commit

Permalink
more progress on Djot reader.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Jan 13, 2024
1 parent 42d81ee commit 636f48f
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions src/Text/Pandoc/Readers/Djot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ where

import Text.Pandoc.Class
import Text.Pandoc.Sources
import Text.Parsec.Pos (sourceName) -- TODO export from T.P.Sources?
import Text.Parsec.Pos (sourceName, newPos) -- TODO export from T.P.Sources?
import Text.Pandoc.Options
import Text.Pandoc.Definition
import Text.Pandoc.Shared (addPandocAttributes)
import Text.Pandoc.Shared (addPandocAttributes, tshow)
import qualified Text.Pandoc.UTF8 as UTF8
import Djot.Options (ParseOptions(..))
import Djot.Blocks (parseDoc)
Expand All @@ -34,6 +34,7 @@ import Text.Pandoc.Error (PandocError(..))
import Control.Monad.Except (throwError)
import qualified Data.Text as T
import Text.Pandoc.Builder
import Text.Pandoc.Logging
import Text.Pandoc.Emoji (emojiToInline)
import Control.Monad.Reader
import qualified Data.Foldable as F
Expand Down Expand Up @@ -108,12 +109,48 @@ convertInline (D.Node attr il) = addAttrToInline attr <$>
D.Symbol bs -> pure $
let s = UTF8.toText bs
in maybe (spanWith ("",["symbol"],[]) (str s)) singleton $ emojiToInline s
D.Math sty bs -> pure mempty -- TODO
D.Link ils tgt -> pure mempty -- TODO
D.Image ils tgt -> pure mempty -- TODO
D.FootnoteReference bs -> pure mempty -- TODO
D.UrlLink bs -> pure mempty -- TODO
D.EmailLink bs -> pure mempty -- TODO
D.Math sty bs -> pure $
(case sty of
D.DisplayMath -> displayMath
D.InlineMath -> math) (UTF8.toText bs)
D.Link ils target ->
case target of
D.Direct url -> link (UTF8.toText url) "" <$> convertInlines ils
D.Reference label -> do
refs <- asks references
case D.lookupReference label refs of
Just (url, lattr) ->
addAttrToInline lattr .
link (UTF8.toText url) "" <$> convertInlines ils
Nothing -> do
report $ ReferenceNotFound (UTF8.toText label) (newPos "" 0 0)
link "" "" <$> convertInlines ils
D.Image ils target ->
case target of
D.Direct url -> image (UTF8.toText url) "" <$> convertInlines ils
D.Reference label -> do
refs <- asks references
case D.lookupReference label refs of
Just (url, lattr) ->
addAttrToInline lattr .
image (UTF8.toText url) "" <$> convertInlines ils
Nothing -> do
report $ ReferenceNotFound (UTF8.toText label) (newPos "" 0 0)
image "" "" <$> convertInlines ils
D.FootnoteReference bs -> do
notes <- asks footnotes
case D.lookupNote bs notes of
Just bls -> note <$> convertBlocks bls
Nothing -> do
-- TODO consider new warning for this?
report $ IgnoredElement ("Undefined footnote reference " <> tshow bs)
pure mempty
D.UrlLink bs -> do
let url = UTF8.toText bs
pure $ linkWith ("",["uri"],[]) url "" (str url)
D.EmailLink bs -> do
let email = UTF8.toText bs
pure $ linkWith ("",["email"],[]) ("mailto:" <> email) "" (str email)
D.RawInline (D.Format fbs) bs -> pure $
rawInline (UTF8.toText fbs) (UTF8.toText bs)
D.NonBreakingSpace -> pure $ str "\160"
Expand Down

0 comments on commit 636f48f

Please sign in to comment.