git.iko.soy/typeable/pandoc
on master help sign in
AsciiDoc writer: use single-line section headers.

The underline style is now deprecated. Previously `--atx-headers` would enable the single-line style; now the single-line style is always used. Closes #5038.

commit2f652638516fb82fd809842517c07d620e18c40c authorJohn MacFarlane <jgm@berkeley.edu> dateSat 3 Nov 2018, 12:01 (8 years ago) parent9a004b8
4 files changed+43−94
MANUAL.txt+1−1 data/templates/default.asciidoc+1−1 src/Text/Pandoc/Writers/AsciiDoc.hs+9−29 test/writer.asciidoc+32−63
MANUAL.txt+1−1
@@ -882,7 +882,7 @@ Options affecting specific writers {.options}
882882
883883`--atx-headers`
884884
885−: Use ATX-style headers in Markdown and AsciiDoc output. The default is
885+: Use ATX-style headers in Markdown output. The default is
886886 to use setext-style headers for levels 1-2, and then ATX headers.
887887 (Note: for `gfm` output, ATX headers are always used.)
888888
data/templates/default.asciidoc+1−1
@@ -1,5 +1,5 @@
11$if(titleblock)$
2−$title$
2+= $title$
33$if(author)$
44$for(author)$$author$$sep$; $endfor$
55$endif$
src/Text/Pandoc/Writers/AsciiDoc.hs+9−29
@@ -40,14 +40,11 @@ AsciiDoc: <http://www.methods.co.nz/asciidoc/>
4040module Text.Pandoc.Writers.AsciiDoc (writeAsciiDoc) where
4141import Prelude
4242import Control.Monad.State.Strict
43−import Data.Aeson (Result (..), Value (String), fromJSON, toJSON)
4443import Data.Char (isPunctuation, isSpace)
4544import Data.List (intercalate, intersperse, stripPrefix)
46−import qualified Data.Map as M
4745import Data.Maybe (fromMaybe, isJust, listToMaybe)
4846import qualified Data.Set as Set
4947import Data.Text (Text)
50−import qualified Data.Text as T
5148import Text.Pandoc.Class (PandocMonad, report)
5249import Text.Pandoc.Definition
5350import Text.Pandoc.ImageSize
@@ -93,20 +90,13 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
9390 (fmap render' . blockListToAsciiDoc opts)
9491 (fmap render' . inlineListToAsciiDoc opts)
9592 meta
96− let addTitleLine (String t) = String $
97− t <> "\n" <> T.replicate (T.length t) "="
98− addTitleLine x = x
99− let metadata' = case fromJSON metadata of
100− Success m -> toJSON $ M.adjust addTitleLine
101− ("title" :: T.Text) m
102− _ -> metadata
10393 body <- blockListToAsciiDoc opts blocks
10494 let main = render colwidth body
10595 let context = defField "body" main
10696 $ defField "toc"
10797 (writerTableOfContents opts &&
10898 isJust (writerTemplate opts))
109− $defField "titleblock" titleblock metadata'
99+ $defField "titleblock" titleblock metadata
110100 case writerTemplate opts of
111101 Nothing -> return main
112102 Just tpl -> renderTemplate' tpl context
@@ -171,27 +161,17 @@ blockToAsciiDoc _ HorizontalRule =
171161 return $ blankline <> text "'''''" <> blankline
172162blockToAsciiDoc opts (Header level (ident,_,_) inlines) = do
173163 contents <- inlineListToAsciiDoc opts inlines
174− let len = offset contents
175− -- ident seem to be empty most of the time and asciidoc will generate them automatically
176− -- so lets make them not show up when null
177164 ids <- gets autoIds
178165 let autoId = uniqueIdent inlines ids
179166 modify $ \st -> st{ autoIds = Set.insert autoId ids }
180− let identifier = if null ident || (isEnabled Ext_auto_identifiers opts && ident == autoId)
181− then empty else "[[" <> text ident <> "]]"
182− let setext = writerSetextHeaders opts
183− return
184− (if setext
185− then
186− identifier $$ contents $$
187− (case level of
188− 1 -> text $ replicate len '-'
189− 2 -> text $ replicate len '~'
190− 3 -> text $ replicate len '^'
191− 4 -> text $ replicate len '+'
192− _ -> empty) <> blankline
193− else
194− identifier $$ text (replicate level '=') <> space <> contents <> blankline)
167+ let identifier = if null ident ||
168+ (isEnabled Ext_auto_identifiers opts && ident == autoId)
169+ then empty
170+ else "[[" <> text ident <> "]]"
171+ return $ identifier $$
172+ nowrap (text (replicate (level + 1) '=') <> space <> contents) <>
173+ blankline
174+
195175blockToAsciiDoc _ (CodeBlock (_,classes,_) str) = return $ flush (
196176 if null classes
197177 then "...." $$ text str $$ "...."
test/writer.asciidoc+32−63
@@ -1,5 +1,4 @@
1−Pandoc Test Suite
2−=================
1+= Pandoc Test Suite
32John MacFarlane; Anonymous
43July 17, 2006
54
@@ -8,40 +7,31 @@ markdown test suite.
87
98'''''
109
11−Headers
12−-------
10+== Headers
1311
14−Level 2 with an link:/url[embedded link]
15−~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12+=== Level 2 with an link:/url[embedded link]
1613
17−Level 3 with _emphasis_
18−^^^^^^^^^^^^^^^^^^^^^^^
14+==== Level 3 with _emphasis_
1915
20−Level 4
21−+++++++
16+===== Level 4
2217
23−Level 5
18+====== Level 5
2419
25−Level 1
26−-------
20+== Level 1
2721
28−Level 2 with _emphasis_
29−~~~~~~~~~~~~~~~~~~~~~~~
22+=== Level 2 with _emphasis_
3023
31−Level 3
32−^^^^^^^
24+==== Level 3
3325
3426with no blank line
3527
36−Level 2
37−~~~~~~~
28+=== Level 2
3829
3930with no blank line
4031
4132'''''
4233
43−Paragraphs
44−----------
34+== Paragraphs
4535
4636Here’s a regular paragraph.
4737
@@ -56,8 +46,7 @@ here.
5646
5747'''''
5848
59−Block Quotes
60−------------
49+== Block Quotes
6150
6251E-mail style:
6352
@@ -99,8 +88,7 @@ And a following paragraph.
9988
10089'''''
10190
102−Code Blocks
103−-----------
91+== Code Blocks
10492
10593Code:
10694
@@ -124,11 +112,9 @@ These should not be escaped: \$ \\ \> \[ \{
124112
125113'''''
126114
127−Lists
128−-----
115+== Lists
129116
130−Unordered
131−~~~~~~~~~
117+=== Unordered
132118
133119Asterisks tight:
134120
@@ -166,8 +152,7 @@ Minuses loose:
166152* Minus 2
167153* Minus 3
168154
169−Ordered
170−~~~~~~~
155+=== Ordered
171156
172157Tight:
173158
@@ -201,8 +186,7 @@ Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.
2011862. Item 2.
2021873. Item 3.
203188
204−Nested
205−~~~~~~
189+=== Nested
206190
207191* Tab
208192** Tab
@@ -226,16 +210,14 @@ Same thing but with paragraphs:
226210* Foe
2272113. Third
228212
229−Tabs and spaces
230−~~~~~~~~~~~~~~~
213+=== Tabs and spaces
231214
232215* this is a list item indented with tabs
233216* this is a list item indented with spaces
234217** this is an example list item indented with tabs
235218** this is an example list item indented with spaces
236219
237−Fancy list markers
238−~~~~~~~~~~~~~~~~~~
220+=== Fancy list markers
239221
2402221. begins with 2
2412232. and now 3
@@ -267,8 +249,7 @@ B. Williams
267249
268250'''''
269251
270−Definition Lists
271−----------------
252+== Definition Lists
272253
273254Tight using spaces:
274255
@@ -348,8 +329,7 @@ orange::
348329 1. sublist
349330 2. sublist
350331
351−HTML Blocks
352−-----------
332+== HTML Blocks
353333
354334Simple block on one line:
355335
@@ -411,8 +391,7 @@ Hr’s:
411391
412392'''''
413393
414−Inline Markup
415−-------------
394+== Inline Markup
416395
417396This is _emphasized_, and so _is this_.
418397
@@ -441,8 +420,7 @@ spaces: a^b c^d, a~b c~d.
441420
442421'''''
443422
444−Smart quotes, ellipses, dashes
445−------------------------------
423+== Smart quotes, ellipses, dashes
446424
447425``Hello,'' said the spider. ```Shelob' is my name.''
448426
@@ -463,8 +441,7 @@ Ellipses…and…and….
463441
464442'''''
465443
466−LaTeX
467−-----
444+== LaTeX
468445
469446*
470447* latexmath:[$2+2=4$]
@@ -489,8 +466,7 @@ Here’s a LaTeX table:
489466
490467'''''
491468
492−Special Characters
493−------------------
469+== Special Characters
494470
495471Here is some unicode:
496472
@@ -544,11 +520,9 @@ Minus: -
544520
545521'''''
546522
547−Links
548−-----
523+== Links
549524
550−Explicit
551−~~~~~~~~
525+=== Explicit
552526
553527Just a link:/url/[URL].
554528
@@ -568,8 +542,7 @@ mailto:nobody@nowhere.net[Email link]
568542
569543link:[Empty].
570544
571−Reference
572−~~~~~~~~~
545+=== Reference
573546
574547Foo link:/url/[bar].
575548
@@ -593,8 +566,7 @@ Foo link:/url/[bar].
593566
594567Foo link:/url/[biz].
595568
596−With ampersands
597−~~~~~~~~~~~~~~~
569+=== With ampersands
598570
599571Here’s a http://example.com/?foo=1&bar=2[link with an ampersand in the URL].
600572
@@ -604,8 +576,7 @@ Here’s an link:/script?foo=1&bar=2[inline link].
604576
605577Here’s an link:/script?foo=1&bar=2[inline link in pointy braces].
606578
607−Autolinks
608−~~~~~~~~~
579+=== Autolinks
609580
610581With an ampersand: http://example.com/?foo=1&bar=2
611582
@@ -627,8 +598,7 @@ or here: <http://example.com/>
627598
628599'''''
629600
630−Images
631−------
601+== Images
632602
633603From ``Voyage dans la Lune'' by Georges Melies (1902):
634604
@@ -638,8 +608,7 @@ Here is a movie image:movie.jpg[movie] icon.
638608
639609'''''
640610
641−Footnotes
642−---------
611+== Footnotes
643612
644613Here is a footnote reference,footnote:[Here is the footnote. It can go
645614anywhere after the footnote reference. It need not be placed at the end of the