Skip to content

Commit 25bba0c

Browse files
committed
MediaWiki writer: use HTML spans for anchors when header has id.
Closes #7697.
1 parent 005dc7c commit 25bba0c

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/Text/Pandoc/Writers/MediaWiki.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,16 @@ blockToMediaWiki b@(RawBlock f str)
128128

129129
blockToMediaWiki HorizontalRule = return "\n-----\n"
130130

131-
blockToMediaWiki (Header level _ inlines) = do
131+
blockToMediaWiki (Header level (ident,_,_) inlines) = do
132+
opts <- gets stOptions
133+
let autoId = uniqueIdent (writerExtensions opts) inlines mempty
132134
contents <- inlineListToMediaWiki inlines
133135
let eqs = T.replicate level "="
134-
return $ eqs <> " " <> contents <> " " <> eqs <> "\n"
136+
return $
137+
(if T.null ident || autoId == ident
138+
then ""
139+
else "<span id=\"" <> ident <> "\"></span>\n")
140+
<> eqs <> " " <> contents <> " " <> eqs <> "\n"
135141

136142
blockToMediaWiki (CodeBlock (_,classes,keyvals) str) = do
137143
let at = Set.fromList classes `Set.intersection` highlightingLangs

test/command/7697.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
```
2+
% pandoc -f rst -t mediawiki
3+
.. _refsubpage1:
4+
5+
heading
6+
-------
7+
8+
ref to top of this section: `refsubpage1`_.
9+
^D
10+
<span id="refsubpage1"></span>
11+
= heading =
12+
13+
ref to top of this section: [[#refsubpage1|refsubpage1]].
14+
```
15+
```
16+
% pandoc -f markdown -t mediawiki
17+
# Heading {#foo}
18+
^D
19+
<span id="foo"></span>
20+
= Heading =
21+
```
22+
```
23+
% pandoc -f markdown -t mediawiki
24+
# Heading {#heading}
25+
^D
26+
= Heading =
27+
```

0 commit comments

Comments
 (0)