Skip to content

Commit 57d61da

Browse files
committed
2 parents f0827ee + 578c9c1 commit 57d61da

File tree

11 files changed

+115
-26
lines changed

11 files changed

+115
-26
lines changed

MANUAL.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -1505,11 +1505,10 @@ header when requesting a document from a URL:
15051505
order they appear on the command line. For more
15061506
information, see the section on [Citations].
15071507

1508-
Note: if your target format is `markdown`, `org`, or `typst`,
1509-
you will need to disable the `citations` extension (e.g., `-t
1510-
markdown-citations`) to see the rendered citations and
1511-
bibliography. Otherwise the format's own citation syntax will
1512-
be used.
1508+
Note: if this option is specified, the `citations` extension
1509+
will be disabled automatically in the writer, to ensure that
1510+
the citeproc-generated citations will be rendered instead of
1511+
the format's own citation syntax.
15131512

15141513
`--bibliography=`*FILE*
15151514

src/Text/Pandoc/App/OutputSettings.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import System.FilePath
3838
import System.IO (stdout)
3939
import Text.Pandoc.Chunks (PathTemplate(..))
4040
import Text.Pandoc
41+
import Text.Pandoc.Filter (Filter(CiteprocFilter))
4142
import Text.Pandoc.App.Opt (Opt (..))
4243
import Text.Pandoc.App.CommandLineOptions (engines)
4344
import Text.Pandoc.Format (FlavoredFormat (..), applyExtensionsDiff,
@@ -121,7 +122,7 @@ optToOutputSettings scriptingEngine opts = do
121122
then getAndCompile (tp <.> T.unpack format)
122123
else throwError e)
123124

124-
(writer, writerExts, mtemplate) <-
125+
(writer, writerExts', mtemplate) <-
125126
if "lua" `T.isSuffixOf` format
126127
then do
127128
let path = T.unpack format
@@ -150,6 +151,10 @@ optToOutputSettings scriptingEngine opts = do
150151
tmpl <- processCustomTemplate (compileDefaultTemplate format)
151152
return (w, wexts, tmpl)
152153

154+
-- see #10662:
155+
let writerExts = if CiteprocFilter `elem` optFilters opts
156+
then disableExtension Ext_citations writerExts'
157+
else writerExts'
153158

154159
let addSyntaxMap existingmap f = do
155160
res <- liftIO (parseSyntaxDefinition f)

src/Text/Pandoc/Filter.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import Control.Monad (foldM, when)
4141
data Filter = LuaFilter FilePath
4242
| JSONFilter FilePath
4343
| CiteprocFilter -- built-in citeproc
44-
deriving (Show, Generic)
44+
deriving (Show, Generic, Eq)
4545

4646
instance FromJSON Filter where
4747
parseJSON node =

src/Text/Pandoc/Readers/LaTeX.hs

+17-11
Original file line numberDiff line numberDiff line change
@@ -386,20 +386,18 @@ inlineCommands = M.unions
386386
, ("lowercase", makeLowercase <$> tok)
387387
, ("thanks", skipopts >> note <$> grouped block)
388388
, ("footnote", skipopts >> footnote)
389+
, ("newline", pure B.linebreak)
390+
, ("linebreak", pure B.linebreak)
389391
, ("passthrough", fixPassthroughEscapes <$> tok)
390392
-- \passthrough macro used by latex writer
391393
-- for listings
392394
, ("includegraphics", do options <- option [] keyvals
393-
src <- braced
394-
mkImage options .
395-
unescapeURL .
396-
removeDoubleQuotes $ untokenize src)
395+
src <- bracedFilename
396+
mkImage options . unescapeURL $ src)
397397
-- svg
398398
, ("includesvg", do options <- option [] keyvals
399-
src <- braced
400-
mkImage options .
401-
unescapeURL .
402-
removeDoubleQuotes $ untokenize src)
399+
src <- bracedFilename
400+
mkImage options . unescapeURL $ src)
403401
-- hyperref
404402
, ("url", (\url -> linkWith ("",["uri"],[]) url "" (str url))
405403
. unescapeURL . untokenize <$> bracedUrl)
@@ -438,6 +436,14 @@ inlineCommands = M.unions
438436
, ("today", today)
439437
]
440438

439+
bracedFilename :: PandocMonad m => LP m Text
440+
bracedFilename =
441+
removeDoubleQuotes . T.strip . untokenize . filter (not . isComment) <$> braced
442+
443+
isComment :: Tok -> Bool
444+
isComment (Tok _ Comment _) = True
445+
isComment _ = False
446+
441447
today :: PandocMonad m => LP m Inlines
442448
today =
443449
text . T.pack . showGregorian . localDay . zonedTimeToLocalTime
@@ -719,7 +725,7 @@ rawBlockOr name fallback = do
719725
doSubfile :: PandocMonad m => LP m Blocks
720726
doSubfile = do
721727
skipMany opt
722-
f <- T.unpack . removeDoubleQuotes . T.strip . untokenize <$> braced
728+
f <- T.unpack <$> bracedFilename
723729
oldToks <- getInput
724730
setInput $ TokStream False []
725731
insertIncluded (ensureExtension (/= "") ".tex" f)
@@ -737,15 +743,15 @@ include name = do
737743
_ -> const False
738744
skipMany opt
739745
fs <- map (T.unpack . removeDoubleQuotes . T.strip) . T.splitOn "," .
740-
untokenize <$> braced
746+
untokenize . filter (not . isComment) <$> braced
741747
mapM_ (insertIncluded . ensureExtension isAllowed ".tex") fs
742748
return mempty
743749

744750
usepackage :: (PandocMonad m, Monoid a) => LP m a
745751
usepackage = do
746752
skipMany opt
747753
fs <- map (T.unpack . removeDoubleQuotes . T.strip) . T.splitOn "," .
748-
untokenize <$> braced
754+
untokenize . filter (not . isComment) <$> braced
749755
let parsePackage f = do
750756
TokStream _ ts <- getIncludedToks (ensureExtension (== ".sty") ".sty" f)
751757
parseFromToks (do _ <- blocks

src/Text/Pandoc/Readers/LaTeX/Parsing.hs

+2
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ withRaw parser = do
934934

935935
keyval :: PandocMonad m => LP m (Text, Text)
936936
keyval = try $ do
937+
sp
937938
key <- untokenize <$> many1 (notFollowedBy (symbol '=') >>
938939
(symbol '-' <|> symbol '_' <|> satisfyTok isWordTok))
939940
sp
@@ -952,6 +953,7 @@ keyval = try $ do
952953
Tok _ Symbol "{" -> False
953954
Tok _ Symbol "}" -> False
954955
_ -> True)))))
956+
sp
955957
optional (symbol ',')
956958
sp
957959
return (key, T.strip val)

src/Text/Pandoc/Writers/Typst.hs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pandocToTypst options (Pandoc meta blocks) = do
8585
Right l ->
8686
resetField "lang" (langLanguage l) .
8787
maybe id (resetField "region") (langRegion l))
88+
$ defField "csl" (lookupMetaString "citation-style" meta) -- #10661
8889
$ defField "smart" (isEnabled Ext_smart options)
8990
$ defField "toc-depth" (tshow $ writerTOCDepth options)
9091
$ defField "figure-caption-position"

test/command/10659.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
```
2+
% pandoc -f latex -t native
3+
\includegraphics[
4+
width=5cm,
5+
]{abc.jpg}
6+
^D
7+
[ Para
8+
[ Image
9+
( "" , [] , [ ( "width" , "5cm" ) ] )
10+
[ Str "image" ]
11+
( "abc.jpg" , "" )
12+
]
13+
]
14+
```
15+
16+
```
17+
% pandoc -f latex -t native
18+
\includegraphics[%
19+
width=5cm,%
20+
]{abc.jpg}
21+
^D
22+
[ Para
23+
[ Image
24+
( "" , [] , [ ( "width" , "5cm" ) ] )
25+
[ Str "image" ]
26+
( "abc.jpg" , "" )
27+
]
28+
]
29+
```
30+
31+
```
32+
% pandoc -f latex -t native
33+
\includegraphics[width=5cm]{%
34+
abc.jpg%
35+
}
36+
^D
37+
[ Para
38+
[ Image
39+
( "" , [] , [ ( "width" , "5cm" ) ] )
40+
[ Str "image" ]
41+
( "abc.jpg" , "" )
42+
]
43+
]
44+
```
45+

test/command/7329.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
% pandoc -f markdown -t org -C --bibliography command/biblio.bib
2828
- [@item1]
2929
^D
30-
- [cite:@item1]
30+
- (Doe 2005)
31+
32+
<<refs>>
33+
34+
<<ref-item1>>
35+
Doe, John. 2005. /First Book/. Cambridge: Cambridge University Press.
3136
```
3237

3338

test/docx/definition_list.docx

719 Bytes
Binary file not shown.

test/docx/definition_list.native

+33-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1-
[DefinitionList
2-
[([Str "Term",Space,Str "1"],
3-
[[Para [Str "Definition",Space,Str "1"]]])
4-
,([Str "Term",Space,Str "2",Space,Str "with",Space,Emph [Str "inline",Space,Str "markup"]],
5-
[[Para [Str "Definition",Space,Str "2"]
6-
,CodeBlock ("",[],[]) "{ some code, part of Definition 2 }"
7-
,Para [Str "Third",Space,Str "paragraph",Space,Str "of",Space,Str "definition",Space,Str "2."]]])]]
1+
[ DefinitionList
2+
[ ( [ Str "Term" , Space , Str "1" ]
3+
, [ [ Para [ Str "Definition" , Space , Str "1" ] ] ]
4+
)
5+
, ( [ Str "Term"
6+
, Space
7+
, Str "2"
8+
, Space
9+
, Str "with"
10+
, Space
11+
, Emph [ Str "inline" , Space , Str "markup" ]
12+
]
13+
, [ [ Para [ Str "Definition" , Space , Str "2" ]
14+
, Para
15+
[ Code
16+
( "" , [] , [] ) "{ some code, part of Definition 2 }"
17+
]
18+
, Para
19+
[ Str "Third"
20+
, Space
21+
, Str "paragraph"
22+
, Space
23+
, Str "of"
24+
, Space
25+
, Str "definition"
26+
, Space
27+
, Str "2."
28+
]
29+
]
30+
]
31+
)
32+
]
33+
]

test/docx/golden/definition_list.docx

-9 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)