aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Writers/MediaWiki.hs10
-rw-r--r--test/command/7697.md27
2 files changed, 35 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/MediaWiki.hs b/src/Text/Pandoc/Writers/MediaWiki.hs
index c7c53943a..e5e2dfde2 100644
--- a/src/Text/Pandoc/Writers/MediaWiki.hs
+++ b/src/Text/Pandoc/Writers/MediaWiki.hs
@@ -128,10 +128,16 @@ blockToMediaWiki b@(RawBlock f str)
blockToMediaWiki HorizontalRule = return "\n-----\n"
-blockToMediaWiki (Header level _ inlines) = do
+blockToMediaWiki (Header level (ident,_,_) inlines) = do
+ opts <- gets stOptions
+ let autoId = uniqueIdent (writerExtensions opts) inlines mempty
contents <- inlineListToMediaWiki inlines
let eqs = T.replicate level "="
- return $ eqs <> " " <> contents <> " " <> eqs <> "\n"
+ return $
+ (if T.null ident || autoId == ident
+ then ""
+ else "<span id=\"" <> ident <> "\"></span>\n")
+ <> eqs <> " " <> contents <> " " <> eqs <> "\n"
blockToMediaWiki (CodeBlock (_,classes,keyvals) str) = do
let at = Set.fromList classes `Set.intersection` highlightingLangs
diff --git a/test/command/7697.md b/test/command/7697.md
new file mode 100644
index 000000000..28e865c82
--- /dev/null
+++ b/test/command/7697.md
@@ -0,0 +1,27 @@
+```
+% pandoc -f rst -t mediawiki
+.. _refsubpage1:
+
+heading
+-------
+
+ref to top of this section: `refsubpage1`_.
+^D
+<span id="refsubpage1"></span>
+= heading =
+
+ref to top of this section: [[#refsubpage1|refsubpage1]].
+```
+```
+% pandoc -f markdown -t mediawiki
+# Heading {#foo}
+^D
+<span id="foo"></span>
+= Heading =
+```
+```
+% pandoc -f markdown -t mediawiki
+# Heading {#heading}
+^D
+= Heading =
+```