mikitex70 / plantuml-markdown

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

plugin does not work with markdown.extensions.fenced_code #8

Closed ghost closed 6 years ago

ghost commented 6 years ago

fenced_code extension is removing gitlab block-style code markers before plantuml is running.

lu-zero commented 6 years ago

the current python markdown seems to do something even worse if codehilite is enabled

mikitex70 commented 6 years ago

The problem is in the fenced_code plugin, which parses text before every plugin. In the fenced_code plugin there is cabled a workaround for the codehilite plugin; I'm trying to register the plantuml plugin before fenced_code, maybe with a monkey patch.

lu-zero commented 6 years ago

Yes, my local solution had been patching fenced code and call it a day :)

q3aiml commented 6 years ago

Here's how I fixed this: https://github.com/q3aiml/plantuml-markdown/commit/df3b0ada1c32aa92d1ae4668fae6bdd9b4c4456c. I haven't opened a PR because I only retained support for the github backtick style block syntax. The ::uml:: syntax could still work but the different opening and closing tags likely require a separate regex.

mikitex70 commented 6 years ago

Thanks @q3aiml, I will study your changes and try to merge them in the existing code.

mikitex70 commented 6 years ago

Hi @q3aiml, I've managed to merge your proprosed code. I need to do other (small) changes (comment the code) but it should work. I'm planning to write some test; in the meanwhile can you do some small run to see if all is working as expected? Thanks again for you contribution.

q3aiml commented 6 years ago

:+1: looks good here. Both styles are working. Thanks so much for reviewing and doing all the work to make it mergeable

seanhoughton commented 6 years ago

I'm getting the following error if I use multiple fenced code blocks. However, it works fine with ::uml:: blocks.

[E 180331 15:18:47 ioloop:638] Exception in callback <bound method LiveReloadHandler.poll_tasks of <class 'livereload.handlers.LiveReloadHandler'>>
    Traceback (most recent call last):
      File "/usr/local/lib/python3.5/site-packages/tornado/ioloop.py", line 1026, in _run
        return self.callback()
      File "/usr/local/lib/python3.5/site-packages/livereload/handlers.py", line 67, in poll_tasks
        filepath, delay = cls.watcher.examine()
      File "/usr/local/lib/python3.5/site-packages/livereload/watcher.py", line 73, in examine
        func and func()
      File "/usr/local/lib/python3.5/site-packages/mkdocs/commands/serve.py", line 106, in builder
        build(config, live_server=live_server, dirty=dirty)
      File "/usr/local/lib/python3.5/site-packages/mkdocs/commands/build.py", line 380, in build
        build_pages(config, dirty=dirty)
      File "/usr/local/lib/python3.5/site-packages/mkdocs/commands/build.py", line 333, in build_pages
        dump_json)
      File "/usr/local/lib/python3.5/site-packages/mkdocs/commands/build.py", line 189, in _build_page
        site_navigation=site_navigation
      File "/usr/local/lib/python3.5/site-packages/mkdocs/commands/build.py", line 59, in convert_markdown
        extension_configs=config['mdx_configs']
      File "/usr/local/lib/python3.5/site-packages/mkdocs/utils/__init__.py", line 366, in convert_markdown
        html_content = md.convert(markdown_source)
      File "/usr/local/lib/python3.5/site-packages/markdown/__init__.py", line 371, in convert
        root = self.parser.parseDocument(self.lines).getroot()
      File "/usr/local/lib/python3.5/site-packages/markdown/blockparser.py", line 65, in parseDocument
        self.parseChunk(self.root, '\n'.join(lines))
      File "/usr/local/lib/python3.5/site-packages/markdown/blockparser.py", line 80, in parseChunk
        self.parseBlocks(parent, text.split('\n\n'))
      File "/usr/local/lib/python3.5/site-packages/markdown/blockparser.py", line 98, in parseBlocks
        if processor.run(parent, blocks) is not False:
      File "/usr/local/lib/python3.5/site-packages/markdown/extensions/plantuml.py", line 95, in run
        raise RuntimeError("UML block not closed")
    RuntimeError: UML block not closed
mikitex70 commented 6 years ago

I'm working on, I'm writing some unit test to keep the code tested. Be patient, I will try to fix it in this weekend. What branch have you used, the master or the develop branch?

q3aiml commented 6 years ago

@seanhoughton do you have a small example? I have only done basic testing but it works if I take the develop branch and drop the example from the readme in a doc twice. It was also working with my documents but they are admittedly all fairly similar. Or maybe it depends on either the markdown config or version?

mikitex70 commented 6 years ago

I've release the version v1.2.2 that should fix working with the fenced_code plugin. I've also added some test, just to avoid regressions.

mikitex70 commented 6 years ago

Released version 1.2.3, which fixes an issue with Python 2.7. Now the plugin is tested with various versions of Python, from 2.7 to 3.6. I hope this will reduce the possibility of regressions.