mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-25 09:47:06 +00:00
Typst: Use customized term instead of custom macro for def lists.
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
$definitions.typst()$
|
||||
|
||||
#show terms: it => {
|
||||
it.children
|
||||
.map(child => [
|
||||
#strong[#child.term]
|
||||
#block(inset: (left: 1.5em, top: -0.4em))[#child.description]
|
||||
])
|
||||
.join()
|
||||
}
|
||||
|
||||
$if(template)$
|
||||
#import "$template$": conf
|
||||
$else$
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
// Some definitions presupposed by pandoc's typst output.
|
||||
#let definition(term, ..defs) = [
|
||||
#strong(term) \
|
||||
#(defs.pos().join("\n"))
|
||||
]
|
||||
|
||||
#let blockquote(body) = [
|
||||
#set text( size: 0.92em )
|
||||
#block(inset: (left: 1.5em, top: 0.2em, bottom: 0.2em))[#body]
|
||||
|
||||
@@ -42,11 +42,17 @@ import Text.Collate.Lang (Lang(..), parseLang)
|
||||
writeTypst :: PandocMonad m => WriterOptions -> Pandoc -> m Text
|
||||
writeTypst options document =
|
||||
evalStateT (pandocToTypst options document)
|
||||
WriterState{ stOptions = options, stNotes = [] }
|
||||
WriterState{ stOptions = options,
|
||||
stEscapeContext = NormalContext,
|
||||
stNotes = [] }
|
||||
|
||||
data EscapeContext = NormalContext | TermContext
|
||||
deriving (Show, Eq)
|
||||
|
||||
data WriterState =
|
||||
WriterState {
|
||||
stOptions :: WriterOptions,
|
||||
stEscapeContext :: EscapeContext,
|
||||
stNotes :: [Doc Text]
|
||||
}
|
||||
|
||||
@@ -197,10 +203,12 @@ blockToTypst block =
|
||||
|
||||
defListItemToTypst :: PandocMonad m => ([Inline], [[Block]]) -> TW m (Doc Text)
|
||||
defListItemToTypst (term, defns) = do
|
||||
modify $ \st -> st{ stEscapeContext = TermContext }
|
||||
term' <- inlinesToTypst term
|
||||
modify $ \st -> st{ stEscapeContext = NormalContext }
|
||||
defns' <- mapM blocksToTypst defns
|
||||
return $ "#definition" <> brackets term' <> mconcat (map brackets defns')
|
||||
|
||||
return $ nowrap ("/ " <> term' <> ": " <> "#block[") $$
|
||||
chomp (vcat defns') $$ "]"
|
||||
listItemToTypst :: PandocMonad m => Int -> Doc Text -> [Block] -> TW m (Doc Text)
|
||||
listItemToTypst ind marker blocks = do
|
||||
contents <- blocksToTypst blocks
|
||||
@@ -212,7 +220,9 @@ inlinesToTypst ils = hcat <$> mapM inlineToTypst ils
|
||||
inlineToTypst :: PandocMonad m => Inline -> TW m (Doc Text)
|
||||
inlineToTypst inline =
|
||||
case inline of
|
||||
Str txt -> return $ literal $ escapeTypst txt
|
||||
Str txt -> do
|
||||
context <- gets stEscapeContext
|
||||
return $ literal $ escapeTypst context txt
|
||||
Space -> return space
|
||||
SoftBreak -> do
|
||||
wrapText <- gets $ writerWrapText . stOptions
|
||||
@@ -284,8 +294,8 @@ inlineToTypst inline =
|
||||
textstyle :: PandocMonad m => Doc Text -> [Inline] -> TW m (Doc Text)
|
||||
textstyle s inlines = (s <>) . brackets <$> inlinesToTypst inlines
|
||||
|
||||
escapeTypst :: Text -> Text
|
||||
escapeTypst t =
|
||||
escapeTypst :: EscapeContext -> Text -> Text
|
||||
escapeTypst context t =
|
||||
if T.any needsEscape t
|
||||
then T.concatMap escapeChar t
|
||||
else t
|
||||
@@ -307,6 +317,7 @@ escapeTypst t =
|
||||
needsEscape '=' = True
|
||||
needsEscape '_' = True
|
||||
needsEscape '*' = True
|
||||
needsEscape ':' = context == TermContext
|
||||
needsEscape _ = False
|
||||
|
||||
toLabel :: Text -> Doc Text
|
||||
|
||||
+56
-34
@@ -1,9 +1,4 @@
|
||||
// Some definitions presupposed by pandoc's typst output.
|
||||
#let definition(term, ..defs) = [
|
||||
#strong(term) \
|
||||
#(defs.pos().join("\n"))
|
||||
]
|
||||
|
||||
#let blockquote(body) = [
|
||||
#set text( size: 0.92em )
|
||||
#block(inset: (left: 1.5em, top: 0.2em, bottom: 0.2em))[#body]
|
||||
@@ -16,6 +11,15 @@
|
||||
#let endnote(num, contents) = [
|
||||
#stack(dir: ltr, spacing: 3pt, super[#num], contents)
|
||||
]
|
||||
#show terms: it => {
|
||||
it.children
|
||||
.map(child => [
|
||||
#strong[#child.term]
|
||||
#block(inset: (left: 1.5em, top: -0.4em))[#child.description]
|
||||
])
|
||||
.join()
|
||||
}
|
||||
|
||||
#let conf(
|
||||
title: none,
|
||||
authors: none,
|
||||
@@ -388,43 +392,56 @@ B. Williams
|
||||
#label("definition-lists")
|
||||
Tight using spaces:
|
||||
|
||||
#definition[apple][red fruit]
|
||||
/ apple: #block[
|
||||
red fruit
|
||||
]
|
||||
|
||||
#definition[orange][orange fruit]
|
||||
/ orange: #block[
|
||||
orange fruit
|
||||
]
|
||||
|
||||
#definition[banana][yellow fruit]
|
||||
/ banana: #block[
|
||||
yellow fruit
|
||||
]
|
||||
|
||||
Tight using tabs:
|
||||
|
||||
#definition[apple][red fruit]
|
||||
/ apple: #block[
|
||||
red fruit
|
||||
]
|
||||
|
||||
#definition[orange][orange fruit]
|
||||
/ orange: #block[
|
||||
orange fruit
|
||||
]
|
||||
|
||||
#definition[banana][yellow fruit]
|
||||
/ banana: #block[
|
||||
yellow fruit
|
||||
]
|
||||
|
||||
Loose:
|
||||
|
||||
#definition[apple][red fruit
|
||||
|
||||
/ apple: #block[
|
||||
red fruit
|
||||
]
|
||||
|
||||
#definition[orange][orange fruit
|
||||
|
||||
/ orange: #block[
|
||||
orange fruit
|
||||
]
|
||||
|
||||
#definition[banana][yellow fruit
|
||||
|
||||
/ banana: #block[
|
||||
yellow fruit
|
||||
]
|
||||
|
||||
Multiple blocks with italics:
|
||||
|
||||
#definition[#emph[apple]][red fruit
|
||||
/ #emph[apple]: #block[
|
||||
red fruit
|
||||
|
||||
contains seeds, crisp, pleasant to taste
|
||||
|
||||
]
|
||||
|
||||
#definition[#emph[orange]][orange fruit
|
||||
/ #emph[orange]: #block[
|
||||
orange fruit
|
||||
|
||||
```
|
||||
{ orange code block }
|
||||
@@ -433,42 +450,47 @@ contains seeds, crisp, pleasant to taste
|
||||
#blockquote[
|
||||
orange block quote
|
||||
]
|
||||
|
||||
]
|
||||
|
||||
Multiple definitions, tight:
|
||||
|
||||
#definition[apple][red fruit][computer]
|
||||
/ apple: #block[
|
||||
red fruit
|
||||
computer
|
||||
]
|
||||
|
||||
#definition[orange][orange fruit][bank]
|
||||
/ orange: #block[
|
||||
orange fruit
|
||||
bank
|
||||
]
|
||||
|
||||
Multiple definitions, loose:
|
||||
|
||||
#definition[apple][red fruit
|
||||
|
||||
][computer
|
||||
/ apple: #block[
|
||||
red fruit
|
||||
|
||||
computer
|
||||
]
|
||||
|
||||
#definition[orange][orange fruit
|
||||
|
||||
][bank
|
||||
/ orange: #block[
|
||||
orange fruit
|
||||
|
||||
bank
|
||||
]
|
||||
|
||||
Blank line after term, indented marker, alternate markers:
|
||||
|
||||
#definition[apple][red fruit
|
||||
|
||||
][computer
|
||||
/ apple: #block[
|
||||
red fruit
|
||||
|
||||
computer
|
||||
]
|
||||
|
||||
#definition[orange][orange fruit
|
||||
/ orange: #block[
|
||||
orange fruit
|
||||
|
||||
+ sublist
|
||||
+ sublist
|
||||
|
||||
]
|
||||
|
||||
= HTML Blocks
|
||||
|
||||
Reference in New Issue
Block a user