Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Nov 12, 2023
1 parent 18ad628 commit 09a1b53
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
7 changes: 3 additions & 4 deletions mknodes/basenodes/mkannotations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any

from jinja2 import filters

from mknodes.basenodes import mkcontainer
from mknodes.utils import log, reprhelpers, resources

Expand Down Expand Up @@ -40,11 +42,8 @@ def __repr__(self):

def _to_markdown(self) -> str:
item_str = "\n\n".join(i.to_markdown() for i in self.items)
lines = item_str.split("\n")
space = (3 - len(str(self.num))) * " "
result = [f"{self.num}.{space}{lines[0]}"]
result.extend(f" {i}" for i in lines[1:])
return "\n".join(result) + "\n"
return f"{self.num}.{space}{filters.do_indent(item_str)}\n"


class MkAnnotations(mkcontainer.MkContainer):
Expand Down
9 changes: 2 additions & 7 deletions mknodes/basenodes/mkdefinitionlist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,8 @@ def items(self, data):
raise TypeError(data)

def _to_markdown(self) -> str:
result = []
for k, v in self.data.items():
lines = str(v).split("\n")
result.extend([str(k), f": {lines[0]}"])
result.extend(f" {i}" for i in lines[1:])
result.append("")
return "\n".join(result) + "\n"
items = [f"{k}\n: {filters.do_indent(str(v))}\n" for k, v in self.data.items()]
return "".join(items)

@classmethod
def create_example_page(cls, page):
Expand Down
8 changes: 4 additions & 4 deletions mknodes/basenodes/mktasklist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from typing import Any

from jinja2 import filters

from mknodes.basenodes import mkcontainer, mknode
from mknodes.utils import log, resources

Expand Down Expand Up @@ -32,11 +34,9 @@ def __init__(
self.value = value

def _to_markdown(self) -> str:
lines = super()._to_markdown().split("\n")
text = super()._to_markdown()
val = "x" if self.value else " "
result = [f"- [{val}] {lines[0]}"]
result.extend(f" {i}" for i in lines[1:])
return "\n".join(result) + "\n"
return f"- [{val}] {filters.do_indent(str(text))}\n"


class MkTaskList(mkcontainer.MkContainer):
Expand Down
6 changes: 3 additions & 3 deletions mknodes/extranodes/mkgrid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations
from typing import Any

from jinja2 import filters

from mknodes.basenodes import mkcontainer, mknode
from mknodes.utils import log, xmlhelpers as xml

Expand Down Expand Up @@ -34,9 +36,7 @@ def get_element(self) -> xml.Div:
result = []
for item in self.items:
item_str = item.to_markdown()
lines = item_str.split("\n")
result += [f"- {lines[0]}"]
result.extend(f" {i}" for i in lines[1:])
result += [f"- {filters.do_indent(item_str)}"]
content = "\n".join(result)
root.text = "\n\n" + content + "\n"
return root
Expand Down
3 changes: 2 additions & 1 deletion tests/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
options:
docstring_section_style: 'list'
show_root_heading: True
\n"""
"""


def test_docstrings():
Expand Down

0 comments on commit 09a1b53

Please sign in to comment.