Skip to content

Commit 4f2eac8

Browse files
committed
MediaWiki writer: fix code for generating spans for header IDs.
We need to generate a span when the header's ID doesn't match the one MediaWiki would generate automatically. But MediaWiki's generation scheme is different from ours (it uses uppercase letters, and `_` instead of `-`, for example). This means that in going from markdown -> mediawiki, we'll now get spans before almost every heading, unless explicit identifiers are used that correspond to the ones MediaWiki auto-generates. This is uglier output but it's necessary for internal links to work properly. See #7697.
1 parent df5ae1c commit 4f2eac8

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/Text/Pandoc/Writers/MediaWiki.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ blockToMediaWiki HorizontalRule = return "\n-----\n"
130130

131131
blockToMediaWiki (Header level (ident,_,_) inlines) = do
132132
opts <- gets stOptions
133-
let autoId = uniqueIdent (writerExtensions opts) inlines mempty
133+
let autoId = T.replace " " "_" $ stringify inlines
134134
contents <- inlineListToMediaWiki inlines
135135
let eqs = T.replicate level "="
136136
return $

test/command/7697.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ref to top of this section: [[#refsubpage1|refsubpage1]].
2121
```
2222
```
2323
% pandoc -f markdown -t mediawiki
24-
# Heading {#heading}
24+
# My Heading {#My_Heading}
2525
^D
26-
= Heading =
26+
= My Heading =
2727
```

test/writer.mediawiki

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,41 @@ This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
33

44
-----
55

6+
<span id="headers"></span>
67
= Headers =
78

9+
<span id="level-2-with-an-embedded-link"></span>
810
== Level 2 with an [[url|embedded link]] ==
911

12+
<span id="level-3-with-emphasis"></span>
1013
=== Level 3 with ''emphasis'' ===
1114

15+
<span id="level-4"></span>
1216
==== Level 4 ====
1317

18+
<span id="level-5"></span>
1419
===== Level 5 =====
1520

21+
<span id="level-1"></span>
1622
= Level 1 =
1723

24+
<span id="level-2-with-emphasis"></span>
1825
== Level 2 with ''emphasis'' ==
1926

27+
<span id="level-3"></span>
2028
=== Level 3 ===
2129

2230
with no blank line
2331

32+
<span id="level-2"></span>
2433
== Level 2 ==
2534

2635
with no blank line
2736

2837

2938
-----
3039

40+
<span id="paragraphs"></span>
3141
= Paragraphs =
3242

3343
Here’s a regular paragraph.
@@ -42,6 +52,7 @@ here.
4252

4353
-----
4454

55+
<span id="block-quotes"></span>
4556
= Block Quotes =
4657

4758
E-mail style:
@@ -71,6 +82,7 @@ And a following paragraph.
7182

7283
-----
7384

85+
<span id="code-blocks"></span>
7486
= Code Blocks =
7587

7688
Code:
@@ -90,8 +102,10 @@ These should not be escaped: \$ \\ \&gt; \[ \{</pre>
90102

91103
-----
92104

105+
<span id="lists"></span>
93106
= Lists =
94107

108+
<span id="unordered"></span>
95109
== Unordered ==
96110

97111
Asterisks tight:
@@ -130,6 +144,7 @@ Minuses loose:
130144
* Minus 2
131145
* Minus 3
132146
147+
<span id="ordered"></span>
133148
== Ordered ==
134149

135150
Tight:
@@ -164,6 +179,7 @@ Multiple paragraphs:
164179
<li><p>Item 2.</p></li>
165180
<li><p>Item 3.</p></li></ol>
166181

182+
<span id="nested"></span>
167183
== Nested ==
168184

169185
* Tab
@@ -188,13 +204,15 @@ Same thing but with paragraphs:
188204
#* Foe
189205
# Third
190206
207+
<span id="tabs-and-spaces"></span>
191208
== Tabs and spaces ==
192209

193210
* this is a list item indented with tabs
194211
* this is a list item indented with spaces
195212
** this is an example list item indented with tabs
196213
** this is an example list item indented with spaces
197214
215+
<span id="fancy-list-markers"></span>
198216
== Fancy list markers ==
199217

200218
<ol start="2" style="list-style-type: decimal;">
@@ -239,6 +257,7 @@ B. Williams
239257

240258
-----
241259

260+
<span id="definition-lists"></span>
242261
= Definition Lists =
243262

244263
Tight using spaces:
@@ -307,6 +326,7 @@ Blank line after term, indented marker, alternate markers:
307326
;# sublist
308327
;# sublist
309328
329+
<span id="html-blocks"></span>
310330
= HTML Blocks =
311331

312332
Simple block on one line:
@@ -416,6 +436,7 @@ Hr’s:
416436

417437
-----
418438

439+
<span id="inline-markup"></span>
419440
= Inline Markup =
420441

421442
This is ''emphasized'', and so ''is this''.
@@ -445,6 +466,7 @@ These should not be superscripts or subscripts, because of the unescaped spaces:
445466

446467
-----
447468

469+
<span id="smart-quotes-ellipses-dashes"></span>
448470
= Smart quotes, ellipses, dashes =
449471

450472
“Hello,” said the spider. “‘Shelob’ is my name.”
@@ -466,6 +488,7 @@ Ellipses…and…and….
466488

467489
-----
468490

491+
<span id="latex"></span>
469492
= LaTeX =
470493

471494
*
@@ -490,6 +513,7 @@ Here’s a LaTeX table:
490513

491514
-----
492515

516+
<span id="special-characters"></span>
493517
= Special Characters =
494518

495519
Here is some unicode:
@@ -545,8 +569,10 @@ Minus: -
545569

546570
-----
547571

572+
<span id="links"></span>
548573
= Links =
549574

575+
<span id="explicit"></span>
550576
== Explicit ==
551577

552578
Just a [[url/|URL]].
@@ -567,6 +593,7 @@ Just a [[url/|URL]].
567593

568594
[[|Empty]].
569595

596+
<span id="reference"></span>
570597
== Reference ==
571598

572599
Foo [[url/|bar]].
@@ -588,6 +615,7 @@ Foo [[url/|bar]].
588615

589616
Foo [[url/|biz]].
590617

618+
<span id="with-ampersands"></span>
591619
== With ampersands ==
592620

593621
Here’s a [http://example.com/?foo=1&bar=2 link with an ampersand in the URL].
@@ -598,6 +626,7 @@ Here’s an [[script?foo=1&bar=2|inline link]].
598626

599627
Here’s an [[script?foo=1&bar=2|inline link in pointy braces]].
600628

629+
<span id="autolinks"></span>
601630
== Autolinks ==
602631

603632
With an ampersand: http://example.com/?foo=1&bar=2
@@ -616,6 +645,7 @@ Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code>
616645

617646
-----
618647

648+
<span id="images"></span>
619649
= Images =
620650

621651
From “Voyage dans la Lune” by Georges Melies (1902):
@@ -627,6 +657,7 @@ Here is a movie [[File:movie.jpg|movie]] icon.
627657

628658
-----
629659

660+
<span id="footnotes"></span>
630661
= Footnotes =
631662

632663
Here is a footnote reference,<ref>Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.</ref> and another.<ref>Here’s the long note. This one contains multiple blocks.

0 commit comments

Comments
 (0)