From bb55caf53b68fdb68628896f2b3f0fddadad75cf Mon Sep 17 00:00:00 2001 From: Timur Osmanov Date: Wed, 21 Aug 2024 17:21:33 +0300 Subject: [PATCH] fix: loose list in blockquote --- README.md | 1 - foliant/preprocessors/escapecode.py | 11 ++++------- tests/data/expected/inline_code.md | 25 +++++++++++++++++++++++++ tests/data/input/inline_code.md | 29 +++++++++++++++++++++++++++-- 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bc93594..68bf223 100644 --- a/README.md +++ b/README.md @@ -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: > ``` diff --git a/foliant/preprocessors/escapecode.py b/foliant/preprocessors/escapecode.py index b0645d1..31b5912 100644 --- a/foliant/preprocessors/escapecode.py +++ b/foliant/preprocessors/escapecode.py @@ -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)): @@ -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 diff --git a/tests/data/expected/inline_code.md b/tests/data/expected/inline_code.md index 0d1c92b..4ee94d2 100644 --- a/tests/data/expected/inline_code.md +++ b/tests/data/expected/inline_code.md @@ -52,9 +52,34 @@ proident, sunt in culpa qui officia `` – tempor incididunt ut labore et dolore magna aliqua `` : > > - `` – lorem ipsum `` dolor sit amet, consectetur adipisicing; +> > - `` – aute irure dolor in reprehenderit in voluptate velit esse: > > - `` – enim ad minim veniam, quis nostrud exercitation; +> > - `` – aute irure dolor in reprehenderit in voluptate velit esse; +> > - `` – velit esse cillum dolore eu fugiat nulla ``; +> > - `` – aute irure dolor in reprehenderit in voluptate velit esse. + +## List in the blockquote in the list + +- test 1 + > Test: + > + > - `` – tempor incididunt ut labore et dolore magna aliqua `` : + > + > - `` – lorem ipsum `` dolor sit amet, consectetur adipisicing; + > + > - `` – aute irure dolor in reprehenderit in voluptate velit esse: + > + > - `` – enim ad minim veniam, quis nostrud exercitation; + > + > - `` – aute irure dolor in reprehenderit in voluptate velit esse; + > + > - `` – velit esse cillum dolore eu fugiat nulla ``; + > + > - `` – aute irure dolor in reprehenderit in voluptate velit esse. + +- test 2 \ No newline at end of file diff --git a/tests/data/input/inline_code.md b/tests/data/input/inline_code.md index 048f369..aa458ea 100644 --- a/tests/data/input/inline_code.md +++ b/tests/data/input/inline_code.md @@ -50,11 +50,36 @@ proident, sunt in culpa qui officia `` 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