Skip to content

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

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

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