Skip to content

Commit

Permalink
fix: usr: fixed error with external plantuml server (fixes #61)
Browse files Browse the repository at this point in the history
When using an external PlantUML server to render diagrams, if a diagram
has syntax errors and the remote server returns an error code (HTTP >=
400), and exception was thrown immediatly stopping markdown parsing.
Now the error is intercepted and logged, and markdown can continue its
work.
  • Loading branch information
Michele Tessaro committed Feb 25, 2022
1 parent d51f988 commit 8d2b7bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion plantuml_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import logging
import markdown
import uuid
import requests
from markdown.util import AtomicString
from xml.etree import ElementTree as etree

Expand Down Expand Up @@ -314,7 +315,13 @@ def _render_local_uml_map(plantuml_code, img_format):
return out

def _render_remote_uml_image(self, plantuml_code, img_format):
return PlantUML("%s/%s/" % (self.config['server'], img_format)).processes(plantuml_code)
image_url = PlantUML("%s/%s/" % (self.config['server'], img_format)).get_url(plantuml_code)
# download manually the image to be able to continue in case of errors
with requests.get(image_url) as r:
if r.status_code >= 400:
print('WARNING in "uml" directive: remote server has returned error %d' % r.status_code)

return r.content


# For details see https://pythonhosted.org/Markdown/extensions/api.html#extendmarkdown
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Markdown
plantuml
requests
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setuptools.setup(
name="plantuml-markdown",
version="3.5.1",
version="3.5.2",
author="Michele Tessaro",
author_email="[email protected]",
description="A PlantUML plugin for Markdown",
Expand Down

0 comments on commit 8d2b7bf

Please sign in to comment.