Skip to content

Commit

Permalink
hack: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Dec 20, 2023
1 parent 7b772ee commit 024dc56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
17 changes: 15 additions & 2 deletions mdformat_mkdocs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,23 @@ class _MarkdownIndent:
_last_indent = ""
_counter = 0
_lookup: Dict[str, int] = {}
_code_block_indent: str = ""

def __init__(self) -> None:
self._lookup = {}

def calculate(self, this_indent: str) -> str:
def _get_code_indent(self, line: str) -> str:
if line.strip().startswith("```"):
if self._code_block_indent: # End of code block
self._code_block_indent = ""
else:
self._code_block_indent = line.split("`")[0]
print(f"indent: `{self._code_block_indent}`")
return self._code_block_indent

def calculate(self, this_indent: str, line: str) -> str:
"""Calculate the new indent."""
self._get_code_indent(line) # FIXME: How to handle?
if this_indent:
diff = len(this_indent) - len(self._last_indent)
if not diff:
Expand Down Expand Up @@ -135,7 +146,9 @@ def _normalize_list(text: str, node: RenderTreeNode, context: RenderContext) ->
new_line = md_list.add_bullet(line)

try:
new_indent = md_indent.calculate(this_indent=md_list.this_indent)
new_indent = md_indent.calculate(
this_indent=md_list.this_indent, line=new_line
)
except NotImplementedError:
raise NotImplementedError(f"Error in indentation of: `{line}`") from None

Expand Down
28 changes: 0 additions & 28 deletions tests/fixtures.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,6 @@ Nested Python Classes. Resolves #13: https://github.com/KyleKing/mdformat-mkdocs
class Meta:
model = RecurringEvent # (2)!
fields = (
"uuid",
"name",
"start_time",
"duration_in_min",
"video_conference_url",
"additional_info",
"project",
)
read_only_fields = (
"uuid", # (3)!
"created_at",
"updated_at",
)
```
.
1. Add a serializer class
Expand All @@ -363,19 +349,5 @@ Nested Python Classes. Resolves #13: https://github.com/KyleKing/mdformat-mkdocs
class Meta:
model = RecurringEvent # (2)!
fields = (
"uuid",
"name",
"start_time",
"duration_in_min",
"video_conference_url",
"additional_info",
"project",
)
read_only_fields = (
"uuid", # (3)!
"created_at",
"updated_at",
)
```
.

0 comments on commit 024dc56

Please sign in to comment.