From 430e6be1f41358bed21b2edf02bcdb41dbee88cc Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 4 May 2017 12:36:52 +0300 Subject: [PATCH] Muse writer: omit automatic header identifiers (#3633) --- src/Text/Pandoc/Writers/Muse.hs | 11 ++++++++- test/writer.muse | 40 --------------------------------- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs index 8f6493975..8b083e2c6 100644 --- a/src/Text/Pandoc/Writers/Muse.hs +++ b/src/Text/Pandoc/Writers/Muse.hs @@ -53,6 +53,7 @@ import Text.Pandoc.Shared import Text.Pandoc.Templates (renderTemplate') import Text.Pandoc.Writers.Math import Text.Pandoc.Writers.Shared +import qualified Data.Set as Set type Notes = [[Block]] data WriterState = @@ -60,6 +61,7 @@ data WriterState = , stOptions :: WriterOptions , stTopLevel :: Bool , stInsideBlock :: Bool + , stIds :: Set.Set String } -- | Convert Pandoc to Muse. @@ -72,6 +74,7 @@ writeMuse opts document = , stOptions = opts , stTopLevel = True , stInsideBlock = False + , stIds = Set.empty } in evalStateT (pandocToMuse document) st @@ -184,8 +187,14 @@ blockToMuse (DefinitionList items) = do let ind = offset label'' return $ hang ind label'' contents blockToMuse (Header level (ident,_,_) inlines) = do + opts <- gets stOptions contents <- inlineListToMuse inlines - let attr' = if null ident + + ids <- gets stIds + let autoId = uniqueIdent inlines ids + modify $ \st -> st{ stIds = Set.insert autoId ids } + + let attr' = if null ident || (isEnabled Ext_auto_identifiers opts && ident == autoId) then empty else "#" <> text ident <> cr let header' = text $ replicate level '*' diff --git a/test/writer.muse b/test/writer.muse index c19cb8ab2..73f1cf604 100644 --- a/test/writer.muse +++ b/test/writer.muse @@ -9,47 +9,30 @@ markdown test suite. * Headers -#headers - ** Level 2 with an [[/url][embedded link]] -#level-2-with-an-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 with no blank line ---- * Paragraphs -#paragraphs Here’s a regular paragraph. In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item. @@ -65,7 +48,6 @@ here. * Block Quotes -#block-quotes E-mail style: @@ -105,7 +87,6 @@ And a following paragraph. * Code Blocks -#code-blocks Code: @@ -130,11 +111,8 @@ These should not be escaped: \$ \\ \> \[ \{ * Lists -#lists - ** Unordered -#unordered Asterisks tight: - asterisk 1 @@ -173,7 +151,6 @@ Minuses loose: ** Ordered -#ordered Tight: 1. First @@ -208,7 +185,6 @@ Multiple paragraphs: ** Nested -#nested - Tab - Tab - Tab @@ -234,7 +210,6 @@ Same thing but with paragraphs: ** Tabs and spaces -#tabs-and-spaces - this is a list item indented with tabs - this is a list item indented with spaces @@ -243,7 +218,6 @@ Same thing but with paragraphs: ** Fancy list markers -#fancy-list-markers 2. begins with 2 3. and now 3 @@ -277,7 +251,6 @@ B. Williams * Definition Lists -#definition-lists Tight using spaces: apple :: red fruit @@ -339,7 +312,6 @@ Blank line after term, indented marker, alternate markers: * HTML Blocks -#html-blocks Simple block on one line: fooAnd nested without indentation: @@ -489,7 +461,6 @@ Hr’s: * Inline Markup -#inline-markup This is emphasized, and so is this. This is strong, and so is this. @@ -521,7 +492,6 @@ spaces: a^b c^d, a~b c~d. * Smart quotes, ellipses, dashes -#smart-quotes-ellipses-dashes "Hello," said the spider. "'Shelob' is my name." 'A', 'B', and 'C' are letters. @@ -543,7 +513,6 @@ Ellipses…and…and…. * LaTeX -#latex - \cite[22-23]{smith.1899} - 2 + 2 = 4 - x ∈ y @@ -578,7 +547,6 @@ Cat & 1 \\ \hline * Special Characters -#special-characters Here is some unicode: - I hat: Î @@ -633,11 +601,8 @@ Minus: - * Links -#links - ** Explicit -#explicit Just a [[/url/][URL]]. [[/url/][URL and title]]. @@ -658,7 +623,6 @@ Just a [[/url/][URL]]. ** Reference -#reference Foo [[/url/][bar]]. Foo [[/url/][bar]]. @@ -687,7 +651,6 @@ Foo [[/url/][biz]]. ** With ampersands -#with-ampersands Here’s a [[http://example.com/?foo=1&bar=2][link with an ampersand in the URL]]. @@ -699,7 +662,6 @@ Here’s an [[/script?foo=1&bar=2][inline link in pointy braces]]. ** Autolinks -#autolinks With an ampersand: [[http://example.com/?foo=1&bar=2]] - In a list? @@ -723,7 +685,6 @@ or here: * Images -#images From "Voyage dans la Lune" by Georges Melies (1902): [[lalune.jpg][Voyage dans la Lune]] @@ -734,7 +695,6 @@ Here is a movie [[movie.jpg][movie]] icon. * Footnotes -#footnotes Here is a footnote reference,[1] and another.[2] This should not be a footnote reference, because it contains a space.[^my note] Here is an inline note.[3]