Skip to content

Colon in setext title (with '==' underline) causes incorrect page rendering #4079

Open

Description

@frankkusters

I use setext headings. When a page title contains a single word followed by a colon, the page renders incorrectly.

Foo: Bar
===

Lorem ipsum

Result
Image

Expected

Image

Cause

This title is interpreted by mkdocs as MultiMarkdown Style Meta-Data:

# No YAML delimiters. Try MultiMarkdown style
lines = doc.replace('\r\n', '\n').replace('\r', '\n').split('\n')
key = None
while lines:
line = lines.pop(0)
if line.strip() == '':
break # blank line - done
if m1 := META_RE.match(line):
key = m1.group('key').lower().strip()
value = m1.group('value').strip()
if key in data:
data[key] += f' {value}'
else:
data[key] = value

Solution

I'm not sure how this should be fixed without breaking backward compatibility. It might be a good idea to make MultiMarkdown style meta-data an option that can be turned off - in our project we only use YAML style meta-data.

Workaround

All these variants will render correctly:

Atx-style headings:

# Foo: Bar

Lorem ipsum

A space in the text before the colon:

Foo bar: Baz
===

Lorem ipsum

YAML metadata before the title:

---
workaround_mkdocs_colon_in_title: true  # actual data doesn't matter, as long as it is valid YAML
---

Foo: Bar
===

Lorem ipsum

Activity

  1. facelessuser commented on Jan 26, 2026

    @facelessuser
    Contributor

    If I understand, this is due to the meta extension in Python Markdown. It doesn't require explicit fences around key value pairs. So what happens is it sees:

    key: value
    

    If you put a blank line in front, it should render correctly, but MkDocs may be stripping that out. As a workaround, a comment before the header would allow it to work.

    To be honest, maybe Python Markdown Meta extension should require key value pairs to be followed by a new line or the end of the buffer to prevent gobbling up setext headers. Or maybe it should just invalidate an entry if it is followed by ===, etc.

    Additionally, maybe MkDocs should avoid stripping leading white space so people could just put a new line before the header to natural prevent this issue, but also, maybe Python Markdown.

    Anyway, I think maybe creating an issue in Python Markdown might make sense. I think more could be done here to ensure sane results.

  2. facelessuser commented on Jan 26, 2026

    @facelessuser
    Contributor

    It seems you can have an explicit meta data empty container to prevent problems:

    ---
    ---
    Foo: Bar
    ===
    
  3. facelessuser commented on Jan 26, 2026

    @facelessuser
    Contributor

    I've created an issue over at Python Markdown. I have some ideas on how this could be improved.

  4. waylan commented on Jan 26, 2026

    @waylan
    Contributor

    @facelessuser McDocs does not use the meta-data extension but has its own implementation, which @frankkusters properly linked to. The issue seems to be that his first header is being recognized as multimarkdown style metadata. As documented, that is the correct behavior. I'm now out-of-touch with what is going on with MkDocs, so I can't say how MkDocs wants to move forward on this, but at the time that I implemented the current solution, the answer would have been to insert a blank line before the header to avoid a false match. I did consider adding a config option so that the user could choose between the two styles, but ultimately decided against adding unnecessary options.

    Today, multimarkdown has abandoned that old syntax and now supports YAML style. If I was implementing the feature today, I would either (1) only support YAML style or (2) provide the multimarkdown style as an option which can only be enabled by config option (I expect that I would be more likely to chose the first option). That said, MkDocs potentially has a large number of users relying on the current defaults, so it is not clear to me what the best way forward would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions