Skip to content

Commit

Permalink
fix: loose list in blockquote
Browse files Browse the repository at this point in the history
  • Loading branch information
TOsmanov committed Aug 21, 2024
1 parent 8bac764 commit bb55caf
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
> Starting from version `1.0.5`, the preprocessor uses the [marko parser](https://github.com/frostming/marko/tree/6ee598746bc9a76e62a158c5aa5226a3d65c0864).
> This is necessary to more accurately identify code blocks nested in other markdown elements. But using the parser imposes the following restrictions:
> - the indent of the list items will be converted to 2 spaces after processing by the preprocessor.
> - the loose lists in the blockquote will be converted to tight lists after processing by the preprocessor,
>
> If your documentation does not use deep nesting of markdown elements, you may want to use version `1.0.4`, as it is more stable. For install version `1.0.4`, run:
> ```
Expand Down
11 changes: 4 additions & 7 deletions foliant/preprocessors/escapecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,7 @@ def render_thematic_break(self, element: block.ThematicBreak) -> str:

def render_list(self, element: block.List) -> str:
result = []
if 'in_quote' in dir(element):
if element.in_quote == True:
element.tight = True
sep = ""
if element.ordered:
for num, child in enumerate(element.children, element.start):
with self.container(f"{num}. ", " " * (len(str(num)) + 2)):
Expand All @@ -449,10 +447,9 @@ def render_list(self, element: block.List) -> str:
for num, item in enumerate(result):
lines = item.split("\n")
result[num] = "\n".join(lines)
if element.tight:
return "".join(result)
else:
return "\n".join(result)
if not element.tight:
sep = f"{self._prefix}\n"
return sep.join(result)

def render_quote(self, element: block.Quote) -> str:
# adds a key 'in_quote' to all lists
Expand Down
25 changes: 25 additions & 0 deletions tests/data/expected/inline_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,34 @@ proident, sunt in culpa qui officia `<escaped hash="48e04d12f0f44333e6e80e00aec3
> - `<escaped hash="0f618b27b0067206888dc852850ff192"></escaped>` – tempor incididunt ut labore et dolore magna aliqua `<escaped hash="49b4b9995319e31372cf09aff7885915"></escaped>` :
>
> - `<escaped hash="ebb67a4271abe715344471b0f16321f6"></escaped>` – lorem ipsum `<escaped hash="17c3d4fb075d05370d828e0915b7335a"></escaped>` dolor sit amet, consectetur adipisicing;
>
> - `<escaped hash="730bfa378b905ab806a3e0a03a170835"></escaped>` – aute irure dolor in reprehenderit in voluptate velit esse:
>
> - `<escaped hash="e0ebc3c409070d07f1df0f2f4132509e"></escaped>` – enim ad minim veniam, quis nostrud exercitation;
>
> - `<escaped hash="8529ac387c11f1f51d71758ccd492692"></escaped>` – aute irure dolor in reprehenderit in voluptate velit esse;
>
> - `<escaped hash="8b5742f168cb41d71453f903bd423ea6"></escaped>` – velit esse cillum dolore eu fugiat nulla `<escaped hash="bdb40bfe98082570a65394f4f2049943"></escaped>`;
>
> - `<escaped hash="28bd2a64abfe3383d3ce89d3348a48fc"></escaped>` – aute irure dolor in reprehenderit in voluptate velit esse.
## List in the blockquote in the list

- test 1
> Test:
>
> - `<escaped hash="0f618b27b0067206888dc852850ff192"></escaped>` – tempor incididunt ut labore et dolore magna aliqua `<escaped hash="49b4b9995319e31372cf09aff7885915"></escaped>` :
>
> - `<escaped hash="ebb67a4271abe715344471b0f16321f6"></escaped>` – lorem ipsum `<escaped hash="17c3d4fb075d05370d828e0915b7335a"></escaped>` dolor sit amet, consectetur adipisicing;
>
> - `<escaped hash="730bfa378b905ab806a3e0a03a170835"></escaped>` – aute irure dolor in reprehenderit in voluptate velit esse:
>
> - `<escaped hash="e0ebc3c409070d07f1df0f2f4132509e"></escaped>` – enim ad minim veniam, quis nostrud exercitation;
>
> - `<escaped hash="8529ac387c11f1f51d71758ccd492692"></escaped>` – aute irure dolor in reprehenderit in voluptate velit esse;
>
> - `<escaped hash="8b5742f168cb41d71453f903bd423ea6"></escaped>` – velit esse cillum dolore eu fugiat nulla `<escaped hash="bdb40bfe98082570a65394f4f2049943"></escaped>`;
>
> - `<escaped hash="28bd2a64abfe3383d3ce89d3348a48fc"></escaped>` – aute irure dolor in reprehenderit in voluptate velit esse.
- test 2
29 changes: 27 additions & 2 deletions tests/data/input/inline_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,36 @@ proident, sunt in culpa qui officia `<tag>` deserunt mollit anim id est laborum.
> Test:
>
> - `cache_dir` – tempor incididunt ut labore et dolore magna aliqua `$var = 0` :
>
>
> - `actions` – lorem ipsum `inline code` dolor sit amet, consectetur adipisicing;
>
> - `normalize` – aute irure dolor in reprehenderit in voluptate velit esse:
>
>
> - `escape` – enim ad minim veniam, quis nostrud exercitation;
>
> - `fence_blocks` – aute irure dolor in reprehenderit in voluptate velit esse;
>
> - `pre_blocks` – velit esse cillum dolore eu fugiat nulla `action = normalize`;
>
> - `inline_code` – aute irure dolor in reprehenderit in voluptate velit esse.
## List in the blockquote in the list

- test 1
> Test:
>
> - `cache_dir` – tempor incididunt ut labore et dolore magna aliqua `$var = 0` :
>
> - `actions` – lorem ipsum `inline code` dolor sit amet, consectetur adipisicing;
>
> - `normalize` – aute irure dolor in reprehenderit in voluptate velit esse:
>
> - `escape` – enim ad minim veniam, quis nostrud exercitation;
>
> - `fence_blocks` – aute irure dolor in reprehenderit in voluptate velit esse;
>
> - `pre_blocks` – velit esse cillum dolore eu fugiat nulla `action = normalize`;
>
> - `inline_code` – aute irure dolor in reprehenderit in voluptate velit esse.
- test 2

0 comments on commit bb55caf

Please sign in to comment.