From 7f6021d7b2b01a33701eb4e255f1bf40a71b8ef8 Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Sat, 26 Feb 2022 11:37:46 -0800 Subject: [PATCH] Markdown writer: don't produce redundant header identifier... when the `gfm_auto_identifiers` extension is set. Closes #7941. --- src/Text/Pandoc/Writers/Markdown.hs | 4 +++- test/command/7941.md | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/command/7941.md diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 0ac058893..2d9532dd3 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -470,13 +470,15 @@ blockToMarkdown' opts (Header level attr inlines) = do else return empty variant <- asks envVariant -- we calculate the id that would be used by auto_identifiers + -- or gfm_auto_identifiers -- so we know whether to print an explicit identifier ids <- gets stIds let autoId = uniqueIdent (writerExtensions opts) inlines ids modify $ \st -> st{ stIds = Set.insert autoId ids } let attr' = case attr of ("",[],[]) -> empty - (id',[],[]) | isEnabled Ext_auto_identifiers opts + (id',[],[]) | (isEnabled Ext_auto_identifiers opts + || isEnabled Ext_gfm_auto_identifiers opts) && id' == autoId -> empty (id',_,_) | isEnabled Ext_mmd_header_identifiers opts -> space <> brackets (literal id') diff --git a/test/command/7941.md b/test/command/7941.md new file mode 100644 index 000000000..d68f04085 --- /dev/null +++ b/test/command/7941.md @@ -0,0 +1,6 @@ +``` +% pandoc -f commonmark_x -t commonmark_x +# Class setup +^D +# Class setup +```