diff --git a/README.md b/README.md index c3d20a1..68bf223 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,17 @@ # EscapeCode and UnescapeCode +> **Warning** +> +> 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. +> +> 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: +> ``` +> pip install foliantcontrib.escapecode==1.0.4 +> ``` + EscapeCode and UnescapeCode preprocessors work in pair. EscapeCode finds in the source Markdown content the parts that should not be modified by any next preprocessors. Examples of content that should be left raw: fence code blocks, pre code blocks, inline code. diff --git a/changelog.md b/changelog.md index 2e03d1d..1d5109f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# 1.0.8 + +- fix: render loose lists + # 1.0.7 - fix: the bug of incorrect selection of the frontmatter has been fixed diff --git a/foliant/preprocessors/escapecode.py b/foliant/preprocessors/escapecode.py index 088882b..f5df415 100644 --- a/foliant/preprocessors/escapecode.py +++ b/foliant/preprocessors/escapecode.py @@ -434,6 +434,7 @@ def render_thematic_break(self, element: block.ThematicBreak) -> str: def render_list(self, element: block.List) -> str: result = [] + sep = "" if element.ordered: for num, child in enumerate(element.children, element.start): with self.container(f"{num}. ", " " * (len(str(num)) + 2)): @@ -444,19 +445,11 @@ def render_list(self, element: block.List) -> str: result.append(self.render(child)) self._prefix = self._second_prefix for num, item in enumerate(result): - no_new_line = False lines = item.split("\n") - for i, line in enumerate(lines): - if len(lines) <= 2: - no_new_line = True - if line.strip() == "": - lines[i] = "" - if no_new_line: - result[num] = "\n".join(lines) - else: - result[num] = "\n".join(lines) +"\n" - - return "".join(result) + result[num] = "\n".join(lines) + if not element.tight: + sep = f"{self._prefix}\n" + return sep.join(result) def render_html_block(self, element: block.HTMLBlock) -> str: children = element.children diff --git a/setup.py b/setup.py index 44b62b5..81f4b83 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ description=SHORT_DESCRIPTION, long_description=LONG_DESCRIPTION, long_description_content_type='text/markdown', - version='1.0.7', + version='1.0.8', author='Artemy Lomov', author_email='artemy@lomov.ru', url='https://github.com/foliant-docs/foliantcontrib.escapecode', diff --git a/tests/data/expected/inline_code.md b/tests/data/expected/inline_code.md index c31f200..4ee94d2 100644 --- a/tests/data/expected/inline_code.md +++ b/tests/data/expected/inline_code.md @@ -6,3 +6,80 @@ quis nostrud exercitation `` pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia `` deserunt mollit anim id est laborum. + +## List 1 (thing) + +- `` – 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 2 (loose) + +- `` – 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 3 in blockquote (thing) + +> 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. + +## List 4 in blockquote (half-loose) + +> 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. + +## 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 5683d6c..aa458ea 100644 --- a/tests/data/input/inline_code.md +++ b/tests/data/input/inline_code.md @@ -6,3 +6,80 @@ quis nostrud exercitation `$var = 0` ullamco laboris nisi ut aliquip ex ea commo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla `func(start, end)` pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia `` deserunt mollit anim id est laborum. + +## List 1 (thing) + +- `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 2 (loose) + +- `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 3 in blockquote (thing) + +> 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 4 in blockquote (half-loose) + +> 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