diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs
index cf5fec86f..460cce3ae 100644
--- a/src/Text/Pandoc/Writers/AsciiDoc.hs
+++ b/src/Text/Pandoc/Writers/AsciiDoc.hs
@@ -520,9 +520,11 @@ inlineToAsciiDoc opts (Note [Plain inlines]) = do
inlineToAsciiDoc _ (Note _) = return "[multiblock footnote omitted]"
inlineToAsciiDoc opts (Span (ident,classes,_) ils) = do
contents <- inlineListToAsciiDoc opts ils
+ isIntraword <- gets intraword
+ let marker = if isIntraword then "##" else "#"
if null ident && null classes
then return contents
else do
let modifier = brackets $ text $ unwords $
[ '#':ident | not (null ident)] ++ map ('.':) classes
- return $ modifier <> "#" <> contents <> "#"
+ return $ modifier <> marker <> contents <> marker
diff --git a/test/command/5566.md b/test/command/5566.md
new file mode 100644
index 000000000..356a5468a
--- /dev/null
+++ b/test/command/5566.md
@@ -0,0 +1,6 @@
+```
+% pandoc -t asciidoc -f html
+foo foo foo foo
+^D
+fo[.c]##o## f[.c]##o##o [.c]##f##oo [.c]#foo#
+```