diff options
-rw-r--r-- | src/Text/Pandoc/Writers/AsciiDoc.hs | 9 | ||||
-rw-r--r-- | test/writer.asciidoc | 31 |
2 files changed, 8 insertions, 32 deletions
diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs index b8f647b66..f91fa8fa0 100644 --- a/src/Text/Pandoc/Writers/AsciiDoc.hs +++ b/src/Text/Pandoc/Writers/AsciiDoc.hs @@ -43,6 +43,7 @@ import Data.Char (isPunctuation, isSpace) import Data.List (intercalate, intersperse, stripPrefix) import qualified Data.Map as M import Data.Maybe (fromMaybe, isJust) +import qualified Data.Set as Set import Data.Text (Text) import qualified Data.Text as T import Text.Pandoc.Class (PandocMonad, report) @@ -60,6 +61,7 @@ data WriterState = WriterState { defListMarker :: String , orderedListLevel :: Int , bulletListLevel :: Int , intraword :: Bool + , autoIds :: Set.Set String } -- | Convert Pandoc to AsciiDoc. @@ -70,6 +72,7 @@ writeAsciiDoc opts document = , orderedListLevel = 1 , bulletListLevel = 1 , intraword = False + , autoIds = Set.empty } type ADW = StateT WriterState @@ -164,7 +167,11 @@ blockToAsciiDoc opts (Header level (ident,_,_) inlines) = do let len = offset contents -- ident seem to be empty most of the time and asciidoc will generate them automatically -- so lets make them not show up when null - let identifier = if null ident then empty else "[[" <> text ident <> "]]" + ids <- gets autoIds + let autoId = uniqueIdent inlines ids + modify $ \st -> st{ autoIds = Set.insert autoId ids } + let identifier = if null ident || (isEnabled Ext_auto_identifiers opts && ident == autoId) + then empty else "[[" <> text ident <> "]]" let setext = writerSetextHeaders opts return (if setext diff --git a/test/writer.asciidoc b/test/writer.asciidoc index 639663743..4dca188e4 100644 --- a/test/writer.asciidoc +++ b/test/writer.asciidoc @@ -8,40 +8,31 @@ markdown test suite. ''''' -[[headers]] Headers ------- -[[level-2-with-an-embedded-link]] Level 2 with an link:/url[embedded link] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -[[level-3-with-emphasis]] Level 3 with _emphasis_ ^^^^^^^^^^^^^^^^^^^^^^^ -[[level-4]] Level 4 +++++++ -[[level-5]] Level 5 -[[level-1]] Level 1 ------- -[[level-2-with-emphasis]] Level 2 with _emphasis_ ~~~~~~~~~~~~~~~~~~~~~~~ -[[level-3]] Level 3 ^^^^^^^ with no blank line -[[level-2]] Level 2 ~~~~~~~ @@ -49,7 +40,6 @@ with no blank line ''''' -[[paragraphs]] Paragraphs ---------- @@ -66,7 +56,6 @@ here. ''''' -[[block-quotes]] Block Quotes ------------ @@ -110,7 +99,6 @@ And a following paragraph. ''''' -[[code-blocks]] Code Blocks ----------- @@ -136,11 +124,9 @@ These should not be escaped: \$ \\ \> \[ \{ ''''' -[[lists]] Lists ----- -[[unordered]] Unordered ~~~~~~~~~ @@ -180,7 +166,6 @@ Minuses loose: * Minus 2 * Minus 3 -[[ordered]] Ordered ~~~~~~~ @@ -216,7 +201,6 @@ Item 1. graf two. The quick brown fox jumped over the lazy dog’s back. 2. Item 2. 3. Item 3. -[[nested]] Nested ~~~~~~ @@ -242,7 +226,6 @@ Same thing but with paragraphs: * Foe 3. Third -[[tabs-and-spaces]] Tabs and spaces ~~~~~~~~~~~~~~~ @@ -251,7 +234,6 @@ Tabs and spaces ** this is an example list item indented with tabs ** this is an example list item indented with spaces -[[fancy-list-markers]] Fancy list markers ~~~~~~~~~~~~~~~~~~ @@ -285,7 +267,6 @@ B. Williams ''''' -[[definition-lists]] Definition Lists ---------------- @@ -367,7 +348,6 @@ orange:: 1. sublist 2. sublist -[[html-blocks]] HTML Blocks ----------- @@ -431,7 +411,6 @@ Hr’s: ''''' -[[inline-markup]] Inline Markup ------------- @@ -462,7 +441,6 @@ spaces: a^b c^d, a~b c~d. ''''' -[[smart-quotes-ellipses-dashes]] Smart quotes, ellipses, dashes ------------------------------ @@ -485,7 +463,6 @@ Ellipses…and…and…. ''''' -[[latex]] LaTeX ----- @@ -512,7 +489,6 @@ Here’s a LaTeX table: ''''' -[[special-characters]] Special Characters ------------------ @@ -568,11 +544,9 @@ Minus: - ''''' -[[links]] Links ----- -[[explicit]] Explicit ~~~~~~~~ @@ -594,7 +568,6 @@ mailto:nobody@nowhere.net[Email link] link:[Empty]. -[[reference]] Reference ~~~~~~~~~ @@ -620,7 +593,6 @@ Foo link:/url/[bar]. Foo link:/url/[biz]. -[[with-ampersands]] With ampersands ~~~~~~~~~~~~~~~ @@ -632,7 +604,6 @@ Here’s an link:/script?foo=1&bar=2[inline link]. Here’s an link:/script?foo=1&bar=2[inline link in pointy braces]. -[[autolinks]] Autolinks ~~~~~~~~~ @@ -656,7 +627,6 @@ or here: <http://example.com/> ''''' -[[images]] Images ------ @@ -668,7 +638,6 @@ Here is a movie image:movie.jpg[movie] icon. ''''' -[[footnotes]] Footnotes --------- |