Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,23 @@ Tabbed fences provide a 'title' for code blocks, and adjacent code blocks will a
```

b. For version 7.x or lower of `pymdown-extensions`, use the following:

```yaml
plugins:
- codeinclude:
title_mode: legacy_pymdownx.superfences
```

c. If no tabbed fences should be used at all:
c. If you are using [`mkdocs-material`](https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#adding-a-title), use the following:

```yaml
plugins:
- codeinclude:
title_mode: mkdocs-material
```

d. If no tabbed fences should be used at all:

```yaml
plugins:
- codeinclude:
Expand Down
11 changes: 10 additions & 1 deletion codeinclude/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CodeIncludePlugin(BasePlugin):
(
"title_mode",
mkdocs.config.config_options.Choice(
choices=["none", "legacy_pymdownx.superfences", "pymdownx.tabbed"],
choices=["none", "legacy_pymdownx.superfences", "pymdownx.tabbed", "mkdocs-material"],
default="pymdownx.tabbed",
),
),
Expand Down Expand Up @@ -171,6 +171,15 @@ def get_substitute(self, page, title, filename, lines, block, inside_block):
```

"""
elif (
self.config.get("title_mode") == "mkdocs-material"
):
return f"""
```{header} title="{title}"
{dedented}
```

"""
else:
return f"""
```{header}
Expand Down
27 changes: 27 additions & 0 deletions tests/codeinclude/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,33 @@ def test_modern_tab_case(self):
result.strip(),
)

def test_mkdocs_material_no_selector(self):
plugin = CodeIncludePlugin()
plugin.load_config({"title_mode": "mkdocs-material"})
result = plugin.on_page_markdown(
MARKDOWN_EXAMPLE_NO_SELECTOR, PAGE_EXAMPLE, dict()
)

print(result)
self.assertEqual(
textwrap.dedent(
"""
# hello world

some text before

```java title=\"foo\"
public class Foo {

}
```

and some text after
"""
).strip(),
result.strip(),
)

def test_empty_title_case(self):
plugin = CodeIncludePlugin()
plugin.load_config({"title_mode": "legacy_pymdownx.superfences"})
Expand Down