diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2023-12-11 10:44:10 -0800 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2023-12-11 10:44:10 -0800 |
| commit | 14e44385e3269157c232e15f3cc95e7e337aaf83 (patch) | |
| tree | e8a39502628aa41f4e9cbe2e7c1d52b2faadfad0 /src | |
| parent | ea9317c73d508d0ce7993db66edb239a3e968cdb (diff) | |
Typst reader: don't include metadata from document element.
The problem is that typst doesn't print this metadata; it is only
used in PDF properties. The title, authors, and so on are represented
in the typst document (and there is no standardized method like
LaTeX's `\maketitle`). So if we parse this as metadata then converting
a typst document will likely lead to a double title.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Readers/Typst.hs | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/src/Text/Pandoc/Readers/Typst.hs b/src/Text/Pandoc/Readers/Typst.hs index 3b9d5b7cb..b0be897da 100644 --- a/src/Text/Pandoc/Readers/Typst.hs +++ b/src/Text/Pandoc/Readers/Typst.hs @@ -131,33 +131,39 @@ pPandoc :: PandocMonad m => P m B.Pandoc pPandoc = do Elt "document" _ fields <- pTok isDocument bs <- getField "body" fields >>= pWithContents pBlocks - title <- (getField "title" fields >>= pWithContents pInlines) <|> - pure mempty - authors <- (getField "author" fields >>= - mapM (pWithContents pInlines) . V.toList) <|> - ((:[]) <$> (getField "author" fields >>= - (\x -> guard (not (null x)) *> - pWithContents pInlines x))) <|> - pure [] - date <- (getField "date" fields >>= pWithContents pInlines) <|> - pure mempty - keywords <- (getField "keywords" fields >>= - mapM (pWithContents pInlines) . V.toList) - <|> pure [] - pure $ - (if title == mempty - then id - else B.setMeta "title" title) . - (if null authors - then id - else B.setMeta "author" authors) . - (if null date - then id - else B.setMeta "date" date) . - (if null keywords - then id - else B.setMeta "keywords" keywords) $ - B.doc bs + pure $ B.doc bs + -- The following alternative code would add metadata from the + -- fields on the document element. It is commented out because + -- the typst metadata doesn't print anything by default, in contrast + -- to pandoc with its usual templates. Hence, with this code, + -- converting a typst document might yield a double title, author, etc. + -- + -- title <- (getField "title" fields >>= pWithContents pInlines) <|> + -- pure mempty + -- authors <- (getField "author" fields >>= + -- mapM (pWithContents pInlines) . V.toList) <|> + -- ((:[]) <$> (getField "author" fields >>= + -- (\x -> guard (not (null x)) *> + -- pWithContents pInlines x))) <|> + -- pure [] + -- date <- (getField "date" fields >>= pWithContents pInlines) <|> + -- pure mempty + -- keywords <- (getField "keywords" fields >>= + -- mapM (pWithContents pInlines) . V.toList) + -- <|> pure [] + -- pure $ + -- (if title == mempty + -- then id + -- else B.setMeta "title" title) . + -- (if null authors + -- then id + -- else B.setMeta "author" authors) . + -- (if null date + -- then id + -- else B.setMeta "date" date) . + -- (if null keywords + -- then id + -- else B.setMeta "keywords" keywords) $ B.doc bs pBlocks :: PandocMonad m => P m B.Blocks pBlocks = mconcat <$> many pBlock |
