mikitex70 / plantuml-markdown

PlantUML plugin for Python-Markdown
BSD 2-Clause "Simplified" License
192 stars 55 forks source link

Indented blocks are not processed #31

Closed gadamiak closed 4 years ago

gadamiak commented 4 years ago

I find that indented or nested blocks are not parsed. They are parsed only when starting at beginning of the line. To illustrate, this block is processed correctly

```plantuml
A --> B : I am processed
```

while a block nested under a list item (or whatever) is not processed

  * A list item with nested block

    ```plantuml
    A --> B : I am not processed
    ```

Is it possible to enable processing of nested/indented blocks?

gadamiak commented 4 years ago

The below patch makes indented fenced blocks get processed correctly:

--- plantuml_markdown.py~       2019-08-26 13:22:37.183784233 +0200
+++ plantuml_markdown.py        2019-08-26 13:22:44.336668395 +0200
@@ -89,7 +89,7 @@
         ''', re.MULTILINE | re.DOTALL | re.VERBOSE)

     FENCED_BLOCK_RE = re.compile(r'''
-        (?P<fence>^(?:~{3,}|`{3,}))[ ]*         # Opening ``` or ~~~
+        (?P<fence>^\s*(?:~{3,}|`{3,}))[ ]*      # Opening ``` or ~~~
         (\{?\.?(plant)?uml)[ ]*                 # Optional {, and lang
         # args
         \s*(format=(?P<quot>"|')(?P<format>\w+)(?P=quot))?

However, they still are not nested correctly, i.e. in the example the paragraph containing an image is not nested under the list item.

gadamiak commented 4 years ago

After some more playing around I think I found a solution for fenced blocks:

--- plantuml_markdown.py~       2019-08-26 13:22:37.183784233 +0200
+++ plantuml_markdown.py        2019-08-26 16:08:31.235838534 +0200
@@ -89,7 +89,7 @@
         ''', re.MULTILINE | re.DOTALL | re.VERBOSE)

     FENCED_BLOCK_RE = re.compile(r'''
-        (?P<fence>^(?:~{3,}|`{3,}))[ ]*         # Opening ``` or ~~~
+        (?P<fence>(?:~{3,}|`{3,}))[ ]*          # Opening ``` or ~~~
         (\{?\.?(plant)?uml)[ ]*                 # Optional {, and lang
         # args
         \s*(format=(?P<quot>"|')(?P<format>\w+)(?P=quot))?
@@ -101,7 +101,7 @@
         [ ]*
         }?[ ]*\n                                # Optional closing }
         (?P<code>.*?)(?<=\n)
-        (?P=fence)[ ]*$
+        \s*(?P=fence)[ ]*$
         ''', re.MULTILINE | re.DOTALL | re.VERBOSE)

     def __init__(self, md):
gadamiak commented 4 years ago

Thanks!