Skip to content

Commit

Permalink
Add test for setext style heading
Browse files Browse the repository at this point in the history
Co-authored-by: Darrick Herwehe <[email protected]>
  • Loading branch information
oprypin and darricktheprogrammer committed Apr 21, 2023
1 parent 5b64d82 commit 7dc2f41
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
12 changes: 8 additions & 4 deletions docs/user-guide/writing-your-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,14 @@ specific page. The following keys are supported:
MkDocs will attempt to determine the title of a document in the following
ways, in order:

1. A title defined in the [nav] configuration setting for a document.
2. A title defined in the `title` meta-data key of a document.
3. A level 1 Markdown header on the first line of the document body. Please note that [Setext-style] headers are not supported.
4. The filename of a document.
1. A title defined in the [nav] configuration setting for a document.

2. A title defined in the `title` meta-data key of a document.

3. A level 1 Markdown header on the first line of the document body.
([Setext-style] headers are supported *only since MkDocs 1.5*.)

4. The filename of a document.

Upon finding a title for a page, MkDoc does not continue checking any
additional sources in the above list.
Expand Down
26 changes: 26 additions & 0 deletions mkdocs/tests/structure/page_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,32 @@ def test_page_title_from_markdown(self):
pg.render(cfg, fl)
self.assertEqual(pg.title, 'Welcome to MkDocs')

def test_page_title_from_setext_markdown(self):
cfg = load_config()
fl = File(
'testing_setext_title.md', cfg['docs_dir'], cfg['site_dir'], cfg['use_directory_urls']
)
pg = Page(None, fl, cfg)
pg.read_source(cfg)
self.assertEqual(pg.url, 'testing_setext_title/')
self.assertEqual(pg.abs_url, None)
self.assertEqual(pg.canonical_url, None)
self.assertEqual(pg.edit_url, None)
self.assertEqual(pg.file, fl)
self.assertEqual(pg.content, None)
self.assertFalse(pg.is_homepage)
self.assertFalse(pg.is_index)
self.assertTrue(pg.is_page)
self.assertFalse(pg.is_section)
self.assertTrue(pg.is_top_level)
self.assertTrue(pg.markdown.startswith('Welcome to MkDocs Setext\n=='))
self.assertEqual(pg.meta, {})
self.assertEqual(pg.next_page, None)
self.assertEqual(pg.parent, None)
self.assertEqual(pg.previous_page, None)
pg.render(cfg, fl)
self.assertEqual(pg.title, 'Welcome to MkDocs Setext')

def test_page_title_from_markdown_stripped_attr_list(self):
cfg = load_config()
cfg.markdown_extensions.append('attr_list')
Expand Down

0 comments on commit 7dc2f41

Please sign in to comment.