git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: omit automatic header identifiers (#3633)
commit430e6be1f41358bed21b2edf02bcdb41dbee88cc authorAlexander Krotov <ilabdsf@gmail.com> dateThu 4 May 2017, 12:36 (9 years ago) parent57cba3f
2 files changed+10−41
src/Text/Pandoc/Writers/Muse.hs+10−1 test/writer.muse−40
src/Text/Pandoc/Writers/Muse.hs+10−1
@@ -53,6 +53,7 @@ import Text.Pandoc.Shared
5353import Text.Pandoc.Templates (renderTemplate')
5454import Text.Pandoc.Writers.Math
5555import Text.Pandoc.Writers.Shared
56+import qualified Data.Set as Set
5657
5758type Notes = [[Block]]
5859data WriterState =
@@ -60,6 +61,7 @@ data WriterState =
6061 , stOptions :: WriterOptions
6162 , stTopLevel :: Bool
6263 , stInsideBlock :: Bool
64+ , stIds :: Set.Set String
6365 }
6466
6567-- | Convert Pandoc to Muse.
@@ -72,6 +74,7 @@ writeMuse opts document =
7274 , stOptions = opts
7375 , stTopLevel = True
7476 , stInsideBlock = False
77+ , stIds = Set.empty
7578 }
7679 in evalStateT (pandocToMuse document) st
7780
@@ -184,8 +187,14 @@ blockToMuse (DefinitionList items) = do
184187 let ind = offset label''
185188 return $ hang ind label'' contents
186189blockToMuse (Header level (ident,_,_) inlines) = do
190+ opts <- gets stOptions
187191 contents <- inlineListToMuse inlines
188− let attr' = if null ident
192+
193+ ids <- gets stIds
194+ let autoId = uniqueIdent inlines ids
195+ modify $ \st -> st{ stIds = Set.insert autoId ids }
196+
197+ let attr' = if null ident || (isEnabled Ext_auto_identifiers opts && ident == autoId)
189198 then empty
190199 else "#" <> text ident <> cr
191200 let header' = text $ replicate level '*'
test/writer.muse−40
@@ -9,47 +9,30 @@ markdown test suite.
99
1010* Headers
1111
12−#headers
13−
1412** Level 2 with an [[/url][embedded link]]
1513
16−#level-2-with-an-embedded-link
17−
1814*** Level 3 with <em>emphasis</em>
1915
20−#level-3-with-emphasis
21−
2216**** Level 4
2317
24−#level-4
25−
2618***** Level 5
2719
28−#level-5
29−
3020* Level 1
3121
32−#level-1
33−
3422** Level 2 with <em>emphasis</em>
3523
36−#level-2-with-emphasis
37−
3824*** Level 3
3925
40−#level-3
4126with no blank line
4227
4328** Level 2
4429
45−#level-2
4630with no blank line
4731
4832----
4933
5034* Paragraphs
5135
52−#paragraphs
5336Here’s a regular paragraph.
5437
5538In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item.
@@ -65,7 +48,6 @@ here.
6548
6649* Block Quotes
6750
68−#block-quotes
6951E-mail style:
7052
7153<quote>
@@ -105,7 +87,6 @@ And a following paragraph.
10587
10688* Code Blocks
10789
108−#code-blocks
10990Code:
11091
11192<example>
@@ -130,11 +111,8 @@ These should not be escaped: \$ \\ \> \[ \{
130111
131112* Lists
132113
133−#lists
134−
135114** Unordered
136115
137−#unordered
138116Asterisks tight:
139117
140118 - asterisk 1
@@ -173,7 +151,6 @@ Minuses loose:
173151
174152** Ordered
175153
176−#ordered
177154Tight:
178155
179156 1. First
@@ -208,7 +185,6 @@ Multiple paragraphs:
208185
209186** Nested
210187
211−#nested
212188 - Tab
213189 - Tab
214190 - Tab
@@ -234,7 +210,6 @@ Same thing but with paragraphs:
234210
235211** Tabs and spaces
236212
237−#tabs-and-spaces
238213 - this is a list item indented with tabs
239214 - this is a list item indented with spaces
240215
@@ -243,7 +218,6 @@ Same thing but with paragraphs:
243218
244219** Fancy list markers
245220
246−#fancy-list-markers
247221 2. begins with 2
248222 3. and now 3
249223
@@ -277,7 +251,6 @@ B. Williams
277251
278252* Definition Lists
279253
280−#definition-lists
281254Tight using spaces:
282255
283256 apple :: red fruit
@@ -339,7 +312,6 @@ Blank line after term, indented marker, alternate markers:
339312
340313* HTML Blocks
341314
342−#html-blocks
343315Simple block on one line:
344316
345317fooAnd nested without indentation:
@@ -489,7 +461,6 @@ Hr’s:
489461
490462* Inline Markup
491463
492−#inline-markup
493464This is <em>emphasized</em>, and so <em>is this</em>.
494465
495466This is <strong>strong</strong>, and so <strong>is this</strong>.
@@ -521,7 +492,6 @@ spaces: a^b c^d, a~b c~d.
521492
522493* Smart quotes, ellipses, dashes
523494
524−#smart-quotes-ellipses-dashes
525495"Hello," said the spider. "'Shelob' is my name."
526496
527497'A', 'B', and 'C' are letters.
@@ -543,7 +513,6 @@ Ellipses…and…and….
543513
544514* LaTeX
545515
546−#latex
547516 - <literal style="tex">\cite[22-23]{smith.1899}</literal>
548517 - 2 + 2 <verbatim>=</verbatim> 4
549518 - <em>x</em> ∈ <em>y</em>
@@ -578,7 +547,6 @@ Cat & 1 \\ \hline
578547
579548* Special Characters
580549
581−#special-characters
582550Here is some unicode:
583551
584552 - I hat: Î
@@ -633,11 +601,8 @@ Minus: -
633601
634602* Links
635603
636−#links
637−
638604** Explicit
639605
640−#explicit
641606Just a [[/url/][URL]].
642607
643608[[/url/][URL and title]].
@@ -658,7 +623,6 @@ Just a [[/url/][URL]].
658623
659624** Reference
660625
661−#reference
662626Foo [[/url/][bar]].
663627
664628Foo [[/url/][bar]].
@@ -687,7 +651,6 @@ Foo [[/url/][biz]].
687651
688652** With ampersands
689653
690−#with-ampersands
691654Here’s a [[http://example.com/?foo=1&bar=2][link with an ampersand in the
692655URL]].
693656
@@ -699,7 +662,6 @@ Here’s an [[/script?foo=1&bar=2][inline link in pointy braces]].
699662
700663** Autolinks
701664
702−#autolinks
703665With an ampersand: [[http://example.com/?foo=1&bar=2]]
704666
705667 - In a list?
@@ -723,7 +685,6 @@ or here: <http://example.com/>
723685
724686* Images
725687
726−#images
727688From "Voyage dans la Lune" by Georges Melies (1902):
728689
729690[[lalune.jpg][Voyage dans la Lune]]
@@ -734,7 +695,6 @@ Here is a movie [[movie.jpg][movie]] icon.
734695
735696* Footnotes
736697
737−#footnotes
738698Here is a footnote reference,[1] and another.[2] This should <em>not</em> be a
739699footnote reference, because it contains a <verbatim>space.[^my</verbatim>
740700<verbatim>note]</verbatim> Here is an inline note.[3]