Skip to content

Commit

Permalink
Merge pull request #192 from daizutabi/191-output-language
Browse files Browse the repository at this point in the history
Change output language of Examples from Python to text
  • Loading branch information
daizutabi authored Sep 16, 2024
2 parents 76c8744 + 216bf05 commit ddf4a1b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/mkapi/css/mkapi-common.css
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,16 @@ ul.mkapi-item-list {
.mkapi-parent-toggle {
cursor: pointer;
}

.mkapi-page-object {
margin-block-end: 0px;
border-bottom: 1px solid var(--mkapi-object-border-color);
}

.mkapi-source {
margin-top: 0px !important;
}

.mkapi-source > table.highlighttable {
margin-top: 0px !important;
}
2 changes: 1 addition & 1 deletion src/mkapi/css/mkapi-material.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[data-md-color-scheme="default"],
[data-md-color-scheme="slate"] {
--mkapi-object-border-color: var(--md-default-fg-color--light);
--mkapi-object-border-color: var(--md-default-fg-color--lightest);
--mkapi-object-kind-color: var(--md-default-fg-color--light);
--mkapi-object-name-color: var(--md-code-hl-name-color);
--mkapi-object-name-font-family: var(--md-code-font-family);
Expand Down
5 changes: 2 additions & 3 deletions src/mkapi/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,15 @@ def _convert_examples(examples: list[doctest.Example]) -> str:
Returns:
str: The Markdown representation of the provided examples.
"""
attr = ".python .mkapi-example-"
prefix = " " * examples[0].indent
lines = [f"{prefix}```{{{attr}input}}"]
lines = [f"{prefix}```{{.python .mkapi-example-input}}"]

lines.extend(textwrap.indent(e.source.rstrip(), prefix) for e in examples)
lines.append(f"{prefix}```\n")

if want := examples[-1].want:
want = textwrap.indent(want.rstrip(), prefix)
output = f"{prefix}```{{{attr}output}}\n"
output = f"{prefix}```{{.text .mkapi-example-output}}\n"
output = f"{output}{want}\n{prefix}```\n"
lines.append(output)

Expand Down
2 changes: 1 addition & 1 deletion src/mkapi/templates/object.jinja2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p class="mkapi-object" id="{{ id }}" markdown="1">
<p class="mkapi-object mkapi-page-{{ namespace }}" id="{{ id }}" markdown="1">
<span class="mkapi-object-link">
[{{ namespace }}][__mkapi__.__{{ namespace }}__.{{ obj_id }}]
<span class="mkapi-document-toggle" title="Toggle all docs">[-]</span>
Expand Down
3 changes: 2 additions & 1 deletion tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def test_render_object_module():
assert parser
name_set = parser.parse_name_set()
m = render_object(name_set, 1, "object", [])
assert '<p class="mkapi-object" id="examples._styles" markdown="1">' in m
x = '<p class="mkapi-object mkapi-page-object" id="examples._styles" markdown="1">'
assert x in m
x = "[object][__mkapi__.__object__.examples._styles]"
assert x in m

Expand Down

0 comments on commit ddf4a1b

Please sign in to comment.