git.iko.soy/typeable/pandoc
on master help sign in
Implement multicolumn support for slide formats.

The structure expected is: <div class="columns"> <div class="column" width="40%"> contents... </div> <div class="column" width="60%"> contents... </div> </div> Support has been added for beamer and all HTML slide formats. Closes #1710. Note: later we could add a more elegant way to create this structure in Markdown than to use raw HTML div elements. This would come for free with a "native div syntax" (#168). Or we could devise something specific to slides

commit892a4edeb1c9b9810c8386e639d8e457bbae7e86 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 14 Aug 2017, 23:05 (9 years ago) parent23d29ee
17 files changed+133−3
data/templates/default.dzslides+1 data/templates/default.html4+1 data/templates/default.html5+1 data/templates/default.revealjs+1 data/templates/default.s5+1 data/templates/default.slideous+1 data/templates/default.slidy+1 src/Text/Pandoc/Writers/HTML.hs+7−1 src/Text/Pandoc/Writers/LaTeX.hs+21−2 test/command/1710.md+91 test/lhs-test.html+1 test/lhs-test.html+lhs+1 test/s5-basic.html+1 test/s5-fancy.html+1 test/s5-inserts.html+1 test/writer.html4+1 test/writer.html5+1
data/templates/default.dzslides+1
@@ -15,6 +15,7 @@ $endif$
1515 <style type="text/css">
1616 code{white-space: pre-wrap;}
1717 .smallcaps{font-variant: small-caps;}
18+ .column{display: inline-block;}
1819$if(quotes)$
1920 q { quotes: "“" "”" "‘" "’"; }
2021$endif$
data/templates/default.html4+1
@@ -18,6 +18,7 @@ $endif$
1818 code{white-space: pre-wrap;}
1919 .smallcaps{font-variant: small-caps;}
2020 .line-block{white-space: pre-line;}
21+ .column{display: inline-block;}
2122$if(quotes)$
2223 q { quotes: "“" "”" "‘" "’"; }
2324$endif$
data/templates/default.html5+1
@@ -18,6 +18,7 @@ $endif$
1818 code{white-space: pre-wrap;}
1919 .smallcaps{font-variant: small-caps;}
2020 .line-block{white-space: pre-line;}
21+ .column{display: inline-block;}
2122$if(quotes)$
2223 q { quotes: "“" "”" "‘" "’"; }
2324$endif$
data/templates/default.revealjs+1
@@ -21,6 +21,7 @@ $endif$
2121 code{white-space: pre-wrap;}
2222 .smallcaps{font-variant: small-caps;}
2323 .line-block{white-space: pre-line;}
24+ .column{display: inline-block;}
2425$if(quotes)$
2526 q { quotes: "“" "”" "‘" "’"; }
2627$endif$
data/templates/default.s5+1
@@ -19,6 +19,7 @@ $endif$
1919 code{white-space: pre-wrap;}
2020 .smallcaps{font-variant: small-caps;}
2121 .line-block{white-space: pre-line;}
22+ .column{display: inline-block;}
2223$if(quotes)$
2324 q { quotes: "“" "”" "‘" "’"; }
2425$endif$
data/templates/default.slideous+1
@@ -20,6 +20,7 @@ $endif$
2020 code{white-space: pre-wrap;}
2121 .smallcaps{font-variant: small-caps;}
2222 .line-block{white-space: pre-line;}
23+ .column{display: inline-block;}
2324$if(quotes)$
2425 q { quotes: "“" "”" "‘" "’"; }
2526$endif$
data/templates/default.slidy+1
@@ -20,6 +20,7 @@ $endif$
2020 code{white-space: pre-wrap;}
2121 .smallcaps{font-variant: small-caps;}
2222 .line-block{white-space: pre-line;}
23+ .column{display: inline-block;}
2324$if(quotes)$
2425 q { quotes: "“" "”" "‘" "’"; }
2526$endif$
src/Text/Pandoc/Writers/HTML.hs+7−1
@@ -640,8 +640,14 @@ blockToHtml opts (LineBlock lns) =
640640 let lf = preEscapedString "\n"
641641 htmlLines <- mconcat . intersperse lf <$> mapM (inlineListToHtml opts) lns
642642 return $ H.div ! A.class_ "line-block" $ htmlLines
643−blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do
643+blockToHtml opts (Div attr@(ident, classes, kvs') bs) = do
644644 html5 <- gets stHtml5
645+ let kvs = kvs' ++
646+ if "column" `elem` classes
647+ then let w = fromMaybe "48%" (lookup "width" kvs')
648+ in [("style", "width:" ++ w ++ ";min-width:" ++ w ++
649+ ";vertical-align:top;")]
650+ else []
645651 let speakerNotes = "notes" `elem` classes
646652 -- we don't want incremental output inside speaker notes, see #1394
647653 let opts' = if speakerNotes then opts{ writerIncremental = False } else opts
src/Text/Pandoc/Writers/LaTeX.hs+21−2
@@ -452,7 +452,25 @@ blockToLaTeX (Div (identifier,classes,kvs) bs) = do
452452 _ -> linkAnchor'
453453 let align dir txt = inCmd "begin" dir $$ txt $$ inCmd "end" dir
454454 lang <- toLang $ lookup "lang" kvs
455− let wrapDir = case lookup "dir" kvs of
455+ let wrapColumns = if "columns" `elem` classes
456+ then \contents ->
457+ inCmd "begin" "columns" <> brackets "T"
458+ $$ contents
459+ $$ inCmd "end" "columns"
460+ else id
461+ wrapColumn = if "column" `elem` classes
462+ then \contents ->
463+ let fromPct xs =
464+ case reverse xs of
465+ '%':ds -> '0':'.': reverse ds
466+ _ -> xs
467+ w = maybe "0.48" fromPct (lookup "width" kvs)
468+ in inCmd "begin" "column" <>
469+ braces (text w <> "\\textwidth")
470+ $$ contents
471+ $$ inCmd "end" "column"
472+ else id
473+ wrapDir = case lookup "dir" kvs of
456474 Just "rtl" -> align "RTL"
457475 Just "ltr" -> align "LTR"
458476 _ -> id
@@ -468,7 +486,8 @@ blockToLaTeX (Div (identifier,classes,kvs) bs) = do
468486 wrapNotes txt = if beamer && "notes" `elem` classes
469487 then "\\note" <> braces txt -- speaker notes
470488 else linkAnchor $$ txt
471− fmap (wrapDir . wrapLang . wrapNotes) $ blockListToLaTeX bs
489+ fmap (wrapColumns . wrapColumn . wrapDir . wrapLang . wrapNotes)
490+ $ blockListToLaTeX bs
472491blockToLaTeX (Plain lst) =
473492 inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
474493-- title beginning with fig: indicates that the image is a figure
test/command/1710.mdnew file+91
@@ -0,0 +1,91 @@
1+```
2+% pandoc -t revealjs
3+# Slide one
4+
5+<div class="columns">
6+<div class="column" width="40%">
7+- a
8+- b
9+</div>
10+<div class="column" width="40%">
11+- c
12+- d
13+</div>
14+<div class="column" width="10%">
15+ok
16+</div>
17+</div>
18+^D
19+<section id="slide-one" class="slide level1">
20+<h1>Slide one</h1>
21+<div class="columns">
22+<div class="column" width="40%" style="width:40%;min-width:40%;vertical-align:top;">
23+<ul>
24+<li>a</li>
25+<li>b</li>
26+</ul>
27+</div>
28+<div class="column" width="40%" style="width:40%;min-width:40%;vertical-align:top;">
29+<ul>
30+<li>c</li>
31+<li>d</li>
32+</ul>
33+</div>
34+<div class="column" width="10%" style="width:10%;min-width:10%;vertical-align:top;">
35+<p>ok</p>
36+</div>
37+</div>
38+</section>
39+```
40+
41+```
42+% pandoc -t beamer
43+# Slide one
44+
45+<div class="columns">
46+<div class="column" width="40%">
47+- a
48+- b
49+</div>
50+<div class="column" width="40%">
51+- c
52+- d
53+</div>
54+<div class="column" width="10%">
55+ok
56+</div>
57+</div>
58+^D
59+\begin{frame}{%
60+\protect\hypertarget{slide-one}{%
61+Slide one}}
62+
63+\begin{columns}[T]
64+\begin{column}{0.40\textwidth}
65+\begin{itemize}
66+\tightlist
67+\item
68+ a
69+\item
70+ b
71+\end{itemize}
72+\end{column}
73+
74+\begin{column}{0.40\textwidth}
75+\begin{itemize}
76+\tightlist
77+\item
78+ c
79+\item
80+ d
81+\end{itemize}
82+\end{column}
83+
84+\begin{column}{0.10\textwidth}
85+ok
86+\end{column}
87+\end{columns}
88+
89+\end{frame}
90+```
91+
test/lhs-test.html+1
@@ -9,6 +9,7 @@
99 code{white-space: pre-wrap;}
1010 .smallcaps{font-variant: small-caps;}
1111 .line-block{white-space: pre-line;}
12+ .column{display: inline-block;}
1213 </style>
1314 <style type="text/css">
1415div.sourceCode { overflow-x: auto; }
test/lhs-test.html+lhs+1
@@ -9,6 +9,7 @@
99 code{white-space: pre-wrap;}
1010 .smallcaps{font-variant: small-caps;}
1111 .line-block{white-space: pre-line;}
12+ .column{display: inline-block;}
1213 </style>
1314 <style type="text/css">
1415div.sourceCode { overflow-x: auto; }
test/s5-basic.html+1
@@ -14,6 +14,7 @@
1414 code{white-space: pre-wrap;}
1515 .smallcaps{font-variant: small-caps;}
1616 .line-block{white-space: pre-line;}
17+ .column{display: inline-block;}
1718 </style>
1819 <!-- configuration parameters -->
1920 <meta name="defaultView" content="slideshow" />
test/s5-fancy.html+1
@@ -14,6 +14,7 @@
1414 code{white-space: pre-wrap;}
1515 .smallcaps{font-variant: small-caps;}
1616 .line-block{white-space: pre-line;}
17+ .column{display: inline-block;}
1718 </style>
1819 <!-- configuration parameters -->
1920 <meta name="defaultView" content="slideshow" />
test/s5-inserts.html+1
@@ -12,6 +12,7 @@
1212 code{white-space: pre-wrap;}
1313 .smallcaps{font-variant: small-caps;}
1414 .line-block{white-space: pre-line;}
15+ .column{display: inline-block;}
1516 </style>
1617 <link rel="stylesheet" href="main.css" type="text/css" />
1718 STUFF INSERTED
test/writer.html4+1
@@ -12,6 +12,7 @@
1212 code{white-space: pre-wrap;}
1313 .smallcaps{font-variant: small-caps;}
1414 .line-block{white-space: pre-line;}
15+ .column{display: inline-block;}
1516 </style>
1617</head>
1718<body>
test/writer.html5+1
@@ -12,6 +12,7 @@
1212 code{white-space: pre-wrap;}
1313 .smallcaps{font-variant: small-caps;}
1414 .line-block{white-space: pre-line;}
15+ .column{display: inline-block;}
1516 </style>
1617 <!--[if lt IE 9]>
1718 <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>