From 9758720a24d7cc9782579bb237d747d32cf72835 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Fri, 22 Dec 2017 10:35:53 -0800
Subject: [PATCH] RST writer: fix anchors for headers.

We were missing an `_`.
See #4188.
---
 src/Text/Pandoc/Writers/RST.hs | 2 +-
 test/command/3937.md           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 42d4d0040..515276985 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -250,7 +250,7 @@ blockToRST (Header level (name,classes,_) inlines) = do
           let headerChar = if level > 5 then ' ' else "=-~^'" !! (level - 1)
           let border = text $ replicate (offset contents) headerChar
           let anchor | null name || name == autoId = empty
-                     | otherwise = ".. " <> text name <> ":" $$ blankline
+                     | otherwise = ".. _" <> text name <> ":" $$ blankline
           return $ nowrap $ anchor $$ contents $$ border $$ blankline
     else do
           let rub     = "rubric:: " <> contents
diff --git a/test/command/3937.md b/test/command/3937.md
index 1d5e4238a..2f32cd172 100644
--- a/test/command/3937.md
+++ b/test/command/3937.md
@@ -3,7 +3,7 @@
 # My Great Section {#mysection}
 # Other section
 ^D
-.. mysection:
+.. _mysection:
 
 My Great Section
 ================