pandoc 3.7 → 3.7.0.1
raw patch · 12 files changed
+299/−106 lines, 12 files
Files
- AUTHORS.md +1/−1
- MANUAL.txt +3/−4
- changelog.md +22/−13
- data/templates/default.context +5/−0
- pandoc.cabal +2/−1
- src/Text/Pandoc/Writers/ConTeXt.hs +1/−0
- src/Text/Pandoc/Writers/Shared.hs +110/−86
- test/Tests/Old.hs +1/−1
- test/command/10848.md +82/−0
- test/tables/nordics.markdown +18/−0
- test/tables/planets.markdown +31/−0
- test/tables/students.markdown +23/−0
AUTHORS.md view
@@ -297,7 +297,7 @@ - Nick Bart - Nick Berendsen - Nick Fleisher-- Nicolas Kaise+- Nicolas Kaiser - Niklas Eicker - Nikolai Korobeinikov - Nikolay Yakimov
MANUAL.txt view
@@ -1,7 +1,7 @@ --- title: Pandoc User's Guide author: John MacFarlane-date: 2025-05-14+date: 2025-05-17 --- # Synopsis@@ -7590,10 +7590,9 @@ the input. The default ConTeXt markup generated by pandoc is optimized for readability and reuse, not tagging. Enable the [`tagging`](#extension--tagging) format extension to force markup-that is optimized for tagging. This can be combined with the-`pdfa` variable to generate standard-compliant PDFs. E.g.:+that is optimized for tagging. For example: - pandoc --to=context+tagging -V pdfa=3a+ pandoc -t context+tagging doc.md -o doc.pdf A recent `context` version should be used, as older versions contained a bug that lead to invalid PDF metadata.
changelog.md view
@@ -1,5 +1,14 @@ # Revision history for pandoc +## pandoc 3.7.0.1 (2025-05-17)++ * Text.Pandoc.Shared.Writer: Fix numerous problems with `gridTable` and add+ tests (#10848). These fixes affect the Markdown, RST, and Muse writers.++ * Fix context writer/template to produce tagged PDFs (#10846).+ As before, the `tagging` extension must be enabled.+ We now add the command that tells ConTeXt to start tagging.+ ## pandoc 3.7 (2025-05-14) * Add new command-line option `--variable-json` (#10341).@@ -53,7 +62,6 @@ + Support `mark` class on spans (#10747). + Add equation label if math contains `\label{..}` (#10805).- + Handle equation labels with spaces (#10805). * Roff format writers (man, ms): @@ -69,7 +77,8 @@ * Docx writer: - + Ensure that figures and tables with custom styles are not dropped (#10705).+ + Ensure that figures and tables with custom styles are not dropped+ (#10705). + Preserve Relationships for images from reference docx (#10759). This should allow one to include an image in a reference.docx and reference it in an openxml template.@@ -137,14 +146,15 @@ and that could lead to information loss. This was particularly noticeable for inline math environments such as `equation`. Previously, an `equation` environment starting at the beginning of a line would create- a raw block, splitting up the paragraph containing it (see #10836). On the- other hand, an `equation` environment not at the beginning of a line would- be turned into regular inline elements representing the math. (This would- cause the equation number to go missing and in some cases degrade the math- formatting.) Now, we parse all of these as raw "latex"- inlines, which will be omitted when converting to formats- other than LaTeX (and other formats like pandoc's Markdown- that allow raw LaTex).+ a raw block, splitting up the paragraph containing it (see+ #10836). On the other hand, an `equation` environment not+ at the beginning of a line would be turned into regular+ inline elements representing the math. (This would cause+ the equation number to go missing and in some cases degrade+ the math formatting.) Now, we parse all of these as raw+ "latex" inlines, which will be omitted when converting to+ formats other than LaTeX (and other formats like pandoc's+ Markdown that allow raw LaTex). * Beamer template: fix regression in 3.6.4, reverting the omission of `\date` when the document does not have a date. By default, beamer@@ -160,7 +170,7 @@ + Use T rather than P as default font family (#10738). + Put PDF-specific things under a conditional.- Don't inculde them if `pdf-engine` isn't set.+ Don't include them if `pdf-engine` isn't set. * Upgrade reveal.js URL to v5 (#10740, Kolen Cheung). v4 is no longer available on unpkg.com.@@ -178,8 +188,7 @@ * Text.Pandoc.Writers.Shared: - + Export `surroundInlines` [API change].- + Rename `surroundInlines` -> `delimited`.+ + Export `delimited` [API change]. + New version of `gridTable` (#6344) [API change]. This handles row and colspans. It also ensures that cells won't wrap text in places where it wouldn't normally wrap, even
data/templates/default.context view
@@ -1,3 +1,8 @@+$if(tagging)$+\setupbackend[format=pdf/ua-2]+\enabledirectives[backend.usetags=mkiv]+\setuptagging[state=start]+$endif$ $if(context-lang)$ \mainlanguage[$context-lang$] $endif$
pandoc.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: pandoc-version: 3.7+version: 3.7.0.1 build-type: Simple license: GPL-2.0-or-later license-file: COPYING.md@@ -345,6 +345,7 @@ test/tables/*.native test/tables/*.mediawiki test/tables/*.jats_archiving+ test/tables/*.markdown test/testsuite.txt test/ansi-test.txt test/writer.latex
src/Text/Pandoc/Writers/ConTeXt.hs view
@@ -117,6 +117,7 @@ "subsubsubsection","subsubsubsubsection"]) $ defField "body" main $ defField "layout" layoutFromMargins+ $ defField "tagging" (isEnabled Ext_tagging options) $ defField "number-sections" (writerNumberSections options) $ defField "csl-refs" (stHasCslRefs st) $ defField "csl-hanging-indent" (stCslHangingIndent st)
@@ -51,7 +51,7 @@ , delimited ) where-import Safe (lastMay, maximumMay, atDef)+import Safe (lastMay, maximumMay) import qualified Data.ByteString.Lazy as BL import Control.Monad (MonadPlus, mzero) import Data.Either (isRight)@@ -297,14 +297,14 @@ let Ann.Table _ _ colspecs thead tbodies tfoot = Ann.toTable mempty (Caption Nothing mempty) colspecs' thead' tbodies' tfoot'- let widths = map (toCharWidth opts . getColWidth) colspecs- let renderRows = fmap (map (addDummies widths)) . mapM (gridRow opts blocksToDoc)+ let renderRows = fmap addDummies . mapM (gridRow opts blocksToDoc) let getHeadCells (Ann.HeaderRow _ _ cells) = cells let getHeadRows (Ann.TableHead _ rs) = map getHeadCells rs headCells <- renderRows (getHeadRows thead) let getFootRows (Ann.TableFoot _ xs) = map getHeadCells xs footCells <- renderRows (getFootRows tfoot)- let getBodyCells (Ann.BodyRow _ _ _ cells) = cells+ -- We don't distinguish between row head and regular cells here:+ let getBodyCells (Ann.BodyRow _ _ rhcells cells) = rhcells ++ cells let getBody (Ann.TableBody _ _ hs xs) = map getHeadCells hs <> map getBodyCells xs bodyCells <- mapM (renderRows . getBody) tbodies let rows = setTopBorder SingleLine headCells ++@@ -314,30 +314,46 @@ then mempty else setTopBorder DoubleLine . setBottomBorder DoubleLine $ footCells)- let cellHasColSpan c = cellColSpan c > 1- let hasColSpans = any (any cellHasColSpan) rows- let isSimple = all ((== ColWidthDefault) . snd) colspecs && not hasColSpans- pure $ gridRows $- if not hasColSpans -- TODO: figure out how to calculate widths with colspans- then redoWidths isSimple opts rows- else rows+ pure $ gridRows $ redoWidths opts colspecs rows -redoWidths :: Bool -> WriterOptions -> [[RenderedCell Text]] -> [[RenderedCell Text]]+-- Returns (current widths, full widths, min widths)+extractColWidths :: WriterOptions -> [[RenderedCell Text]] -> ([Int], [Int], [Int])+extractColWidths opts rows = (currentwidths, fullwidths, minwidths)+ where+ getWidths calcOffset =+ map (fromMaybe 0 . maximumMay) (transpose (map (concatMap (getCellWidths calcOffset)) rows))+ getCellWidths calcOffset c = replicate (cellColSpan c)+ (calcOffset c `div` (cellColSpan c) ++ calcOffset c `rem` (cellColSpan c))+ fullwidths = getWidths (max 1 . offset . cellContents)+ currentwidths = getWidths cellWidth+ minwidths =+ case writerWrapText opts of+ WrapNone -> fullwidths+ _ -> getWidths (minOffset . cellContents)++resetWidths :: [Int] -> [RenderedCell Text] -> [RenderedCell Text]+resetWidths _ [] = []+resetWidths [] cs = cs+resetWidths (w:ws) (c:cs) =+ case cellColSpan c of+ 1 -> c{ cellWidth = w } : resetWidths ws cs+ n | n < 1 -> c : resetWidths ws cs+ | otherwise -> c{ cellWidth = w + sum (take (n - 1) ws) + (3 * (n-1)) }+ : resetWidths (drop (n - 1) ws) cs++redoWidths :: WriterOptions -> [ColSpec] -> [[RenderedCell Text]] -> [[RenderedCell Text]] redoWidths _ _ [] = []-redoWidths isSimple opts rows@(r:_) =- map (\cs -> zipWith resetWidth newwidths cs) rows+redoWidths opts colspecs rows = map (resetWidths newwidths) rows where- actualWidths = map cellWidth r- fullwidths = calculateFullWidths rows- minwidths = case writerWrapText opts of- WrapNone -> fullwidths- _ -> calculateMinWidths rows- totwidth = writerColumns opts - (3 * length r) - 1- evenwidth = totwidth `div` length r- resetWidth w c = c{ cellWidth = w }+ numcols = length colspecs+ isSimple = all ((== ColWidthDefault) . snd) colspecs+ (actualwidths, fullwidths, minwidths) = extractColWidths opts rows+ totwidth = writerColumns opts - (3 * numcols) - 1+ evenwidth = totwidth `div` numcols + totwidth `rem` numcols keepwidths = filter (< evenwidth) fullwidths evenwidth' = (totwidth - sum keepwidths) `div`- (length r - length keepwidths)+ (numcols - length keepwidths) ensureMinWidths = zipWith max minwidths newwidths = ensureMinWidths $ case isSimple of@@ -345,40 +361,51 @@ | otherwise -> map (\w -> if w < evenwidth then w else evenwidth') fullwidths- False -> actualWidths---- Returns for each column a pair (full width, min width)-calculateFullWidths :: [[RenderedCell Text]] -> [Int]-calculateFullWidths rows =- map (fromMaybe 0 . maximumMay) (transpose (map (map (\c ->- offset (cellContents c))) rows))+ False -> actualwidths -calculateMinWidths :: [[RenderedCell Text]] -> [Int]-calculateMinWidths rows =- map (fromMaybe 0 . maximumMay) (transpose (map (map (\c ->- minOffset (cellContents c))) rows))+makeDummy :: RenderedCell Text -> RenderedCell Text+makeDummy c =+ RenderedCell{ cellColNum = cellColNum c,+ cellColSpan = cellColSpan c,+ cellAlign = AlignDefault,+ cellRowSpan = cellRowSpan c - 1,+ cellWidth = cellWidth c,+ cellContents = mempty,+ cellBottomBorder = NoLine,+ cellTopBorder = NoLine } -makeDummy :: [Int] -> Int -> Int -> RenderedCell Text-makeDummy widths n len =- let width = atDef 0 widths n- in RenderedCell{ cellColNum = n,- cellColSpan = len,- cellAlign = AlignDefault,- cellRowSpan = 0, -- indicates dummy- cellWidth = width,- cellHeight = 0,- cellContents = mempty,- cellBottomBorder = NoLine,- cellTopBorder = NoLine }+addDummies :: [[RenderedCell Text]] -> [[RenderedCell Text]]+addDummies = reverse . foldl' go []+ where+ go [] cs = [cs]+ go (prevRow:rs) cs = addDummiesToRow prevRow cs : prevRow : rs+ addDummiesToRow [] cs = cs+ addDummiesToRow ds [] = map makeDummy ds+ addDummiesToRow (d:ds) (c:cs) =+ if cellColNum d < cellColNum c+ then makeDummy d : addDummiesToRow ds (c:cs)+ else c : addDummiesToRow+ (dropWhile (\x ->+ cellColNum x < cellColNum c + cellColSpan c) (d:ds))+ cs -addDummies :: [Int] -> [RenderedCell Text] -> [RenderedCell Text]-addDummies widths = reverse . snd . foldl' addDummy (0,[])+{-+ reverse $ (case numcols - i' of+ 0 -> id+ -- TODO this is wrong; it assumes that the row span+ -- above covers ALL the relevant columns. We need+ -- to pay attention to the details of the row above+ -- so we get the borders right.+ -- TODO the 2 parameter is a placeholder+ n -> (makeDummy widths i' n 2 :)) cs' where+ (i',cs') = foldl' addDummy (0,[]) cells+ numcols = length widths addDummy (i,cs) c = case cellColNum c - i of- 0 -> (i+1, c:cs)- len -> (cellColNum c + 1, c : makeDummy widths i len : cs)-+ 0 -> (cellColNum c + cellColSpan c, c:cs)+ len -> (cellColNum c + cellColSpan c, c : makeDummy widths i len 2 : cs)+-} setTopBorder :: LineStyle -> [[RenderedCell Text]] -> [[RenderedCell Text]] setTopBorder _ [] = []@@ -403,9 +430,7 @@ -- be interpreted as an indented code block...even though it -- would look better to right-align right-aligned cells... -- (TODO: change this on parsing side?)- lblock (case cellWidth c of- 0 -> 16 -- TODO arbitrary- w -> w) (cellContents c)+ lblock (cellWidth c) (cellContents c) formatRow cs = vfill "| " <> hcat (intersperse (vfill " | ") (map renderCellContents cs)) <> vfill " |"@@ -416,45 +441,46 @@ border2 = render Nothing (formatBorder cellTopBorder False nextRow) go '+' _ = '+' go _ '+' = '+'+ go '|' '-' = '+'+ go '-' '|' = '+'+ go '|' '=' = '+'+ go '=' '|' = '+' go '=' _ = '=' go _ '=' = '='+ go ' ' d = d go c _ = c combinedBorder = if isLastRow then literal border1 else literal $ T.zipWith go border1 border2 in formatRow thisRow $$ combinedBorder --formatBorder :: (RenderedCell Text -> LineStyle) -> Bool -> [RenderedCell Text]+formatBorder :: (RenderedCell a -> LineStyle) -> Bool -> [RenderedCell a] -> Doc Text-formatBorder _ _alignMarkers [] = mempty-formatBorder borderStyle alignMarkers (c:cs)- | borderStyle c == NoLine- = openpipe <> text (replicate (cellWidth c + 2) ' ') <> closepipe <>- formatBorder borderStyle alignMarkers cs- | otherwise- = openplus <> leftalign <> underline <> rightalign <> closeplus <>- formatBorder borderStyle alignMarkers cs- where-- openpipe = "|"- closepipe = if null cs then "|" else mempty- openplus = "+"- closeplus = if null cs- then "+"- else mempty- lineChar = case borderStyle c of- NoLine -> ' '- SingleLine -> '-'- DoubleLine -> '='- (leftalign, rightalign) =- case cellAlign c of- _ | not alignMarkers -> (char lineChar,char lineChar)- AlignLeft -> (char ':',char lineChar)- AlignCenter -> (char ':',char ':')- AlignRight -> (char lineChar,char ':')- AlignDefault -> (char lineChar,char lineChar)- underline = text (replicate (cellWidth c) lineChar)+formatBorder borderStyle alignMarkers cs =+ borderParts <> if lastBorderStyle == NoLine+ then char '|'+ else char '+'+ where+ (lastBorderStyle, borderParts) = foldl' addBorder (NoLine, mempty) cs+ addBorder (prevBorderStyle, accum) c =+ (borderStyle c, accum <> char junctionChar <> toBorderSection c)+ where junctionChar = case (borderStyle c, prevBorderStyle) of+ (NoLine, NoLine) -> '|'+ _ -> '+'+ toBorderSection c =+ text $ leftalign : replicate (cellWidth c) lineChar ++ [rightalign]+ where+ lineChar = case borderStyle c of+ NoLine -> ' '+ SingleLine -> '-'+ DoubleLine -> '='+ (leftalign, rightalign) =+ case cellAlign c of+ _ | not alignMarkers -> (lineChar,lineChar)+ AlignLeft -> (':',lineChar)+ AlignCenter -> (':',':')+ AlignRight -> (lineChar,':')+ AlignDefault -> (lineChar,lineChar) data LineStyle = NoLine | SingleLine | DoubleLine deriving (Show, Ord, Eq)@@ -465,7 +491,6 @@ , cellAlign :: Alignment , cellRowSpan :: Int , cellWidth :: Int- , cellHeight :: Int , cellContents :: Doc a , cellBottomBorder :: LineStyle , cellTopBorder :: LineStyle@@ -498,7 +523,6 @@ cellAlign = align, cellRowSpan = rowspan, cellWidth = width,- cellHeight = height rendered, cellContents = rendered, cellBottomBorder = if rowspan < 2 then SingleLine
test/Tests/Old.hs view
@@ -26,7 +26,7 @@ tests pandocPath = [ testGroup "markdown" [ testGroup "writer"- $ writerTests' "markdown" ++ lhsWriterTests' "markdown"+ $ writerTests' "markdown" ++ lhsWriterTests' "markdown" ++ extWriterTests' "markdown" , testGroup "reader" [ test' "basic" ["-r", "markdown", "-w", "native", "-s"] "testsuite.txt" "testsuite.native"
+ test/command/10848.md view
@@ -0,0 +1,82 @@+```+% pandoc -f html -t markdown+<table>+<tr>+<td colspan="3">A</td>+<td rowspan="1" colspan="2">F</td>+</tr>+<tr>+<td>C</td>+<td colspan="2">B</td>+<td colspan="2">H</td>+</tr>+<tr>+<td colspan="2">D</td>+<td colspan="2">E</td>+<td>G</td>+</tr>+</table>+^D++-----------+-------++| A | F |++---+-------+-------++| C | B | H |++---+---+---+---+---++| D | E | G |++-------+-------+---++```++```+% pandoc -f html -t markdown+<table>+<tr>+<td colspan="2">A</td>+<td colspan="2">J</td>+<td rowspan="3">F</td>+</tr>+<tr>+<td rowspan="3">C</td>+<td>B</td>+<td rowspan="2" colspan="2">H</td>+</tr>+<tr>+<td>D</td>+</tr>+<tr>+<td colspan="4">K</td>+</tr>+</table>+^D++-------+-------+---++| A | J | F |++---+---+-------+ |+| C | B | H | |+| +---+ | |+| | D | | |+| +---+-------+---++| | K |++---+---------------++```++```+% pandoc -f html -t markdown-simple_tables-multiline_tables-pipe_tables+<table>+ <tbody>+ <tr>+ <td>a</td>+ <td></td>+ </tr>+ <tr>+ <td></td>+ <td></td>+ </tr>+ </tbody>+</table>+^D++---+---++| a | |++---+---++| | |++---+---++```+
+ test/tables/nordics.markdown view
@@ -0,0 +1,18 @@+ -------------------------------------------------------------------------------+ Name Capital Population\ Area\+ (in 2018) (in km^2^)+ ----------------------- ----------------------- --------------- ---------------+ Denmark Copenhagen 5,809,502 43,094++ Finland Helsinki 5,537,364 338,145++ Iceland Reykjavik 343,518 103,000++ Norway Oslo 5,372,191 323,802++ Sweden Stockholm 10,313,447 450,295++ Total 27,376,022 1,258,336+ -------------------------------------------------------------------------------++ : States belonging to the *Nordics.* {#nordics}
+ test/tables/planets.markdown view
@@ -0,0 +1,31 @@++------------------+---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------++| | Name | Mass | Diameter | Density | Gravity | Length | Distance | Mean | Number | Notes |+| | | (10\^24kg) | (km) | (kg/m\^3) | (m/s\^2) | of day | from Sun | temperature | of | |+| | | | | | | (hours) | (10\^6km) | (C) | moons | |++==================+=========+============+==========+===========+==========+=========+===========+=============+========+==============++| Terrestrial | Mercury | 0.330 | 4,879 | 5427 | 3.7 | 4222.6 | 57.9 | 167 | 0 | Closest to |+| planets | | | | | | | | | | the Sun |+| +---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------++| | Venus | 4.87 | 12,104 | 5243 | 8.9 | 2802.0 | 108.2 | 464 | 0 | |+| +---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------++| | Earth | 5.97 | 12,756 | 5514 | 9.8 | 24.0 | 149.6 | 15 | 1 | Our world |+| +---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------++| | Mars | 0.642 | 6,792 | 3933 | 3.7 | 24.7 | 227.9 | -65 | 2 | The red |+| | | | | | | | | | | planet |++---------+--------+---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------++| Jovian | Gas | Jupiter | 1898 | 142,984 | 1326 | 23.1 | 9.9 | 778.6 | -110 | 67 | The largest |+| planets | giants | | | | | | | | | | planet |+| | +---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------++| | | Saturn | 568 | 120,536 | 687 | 9.0 | 10.7 | 1433.5 | -140 | 62 | |+| +--------+---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------++| | Ice | Uranus | 86.8 | 51,118 | 1271 | 8.7 | 17.2 | 2872.5 | -195 | 27 | |+| | giants | | | | | | | | | | |+| | +---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------++| | | Neptune | 102 | 49,528 | 1638 | 11.0 | 16.1 | 4495.1 | -200 | 14 | |++---------+--------+---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------++| Dwarf planets | Pluto | 0.0146 | 2,370 | 2095 | 0.7 | 153.3 | 5906.4 | -225 | 5 | Declassified |+| | | | | | | | | | | as a planet |+| | | | | | | | | | | in 2006. |++------------------+---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------+++: Data about the planets of our solar system.
+ test/tables/students.markdown view
@@ -0,0 +1,23 @@++-----------------------------------------+-----------------------------------------++| Student ID | Name |++=========================================+=========================================++| Computer Science |++-----------------------------------------+-----------------------------------------++| 3741255 | Jones, Martha |++-----------------------------------------+-----------------------------------------++| 4077830 | Pierce, Benjamin |++-----------------------------------------+-----------------------------------------++| 5151701 | Kirk, James |++-----------------------------------------+-----------------------------------------++| Russian Literature |++-----------------------------------------+-----------------------------------------++| 3971244 | Nim, Victor |++-----------------------------------------+-----------------------------------------++| Astrophysics |++-----------------------------------------+-----------------------------------------++| 4100332 | Petrov, Alexandra |++-----------------------------------------+-----------------------------------------++| 4100332 | Toyota, Hiroko |++-----------------------------------------+-----------------------------------------+++: List of Students {#students}