mikitex70 / plantuml-markdown

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

External includes broken in 3.6.0 #71

Closed davidgiga1993 closed 2 years ago

davidgiga1993 commented 2 years ago

Issue

When trying to render diagrams with external icons mkdocs fails. This was working fine in the previous version.

ERROR    -  Error reading page 'cloud-architecture.md': [Errno 2] No such file or directory: 'AWSPuml/Containers/EKSCloud.puml'
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 431, in _readInclLine
    temp_file = self._read_incl_line_file(
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 458, in _read_incl_line_file
    with open(inc_file_abs, "r") as inc:
FileNotFoundError: [Errno 2] No such file or directory: 'AWSPuml/Containers/EKSCloud.puml'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line [140], in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py", line 192, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 292, in build
    _populate_page(file.page, config, files, dirty)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 174, in _populate_page
    page.render(config, files)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/structure/pages.py", line 175, in render
    self.content = md.convert(self.markdown)
  File "/usr/local/lib/python3.9/site-packages/markdown/core.py", line 261, in convert
    self.lines = prep.run(self.lines)
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 126, in run
    text1, idx1 = self._replace_block(text[idx:])
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 184, in _replace_block
    diagram = self._render_diagram(code, requested_format, base_dir)
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 274, in _render_diagram
    diagram = self._render_remote_uml_image(code, requested_format, base_dir)
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 350, in _render_remote_uml_image
    temp_file = self._readFile(plantuml_code, base_dir, False)
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 385, in _readFile
    temp_file = "@startuml\n" + self._readFileRec(lines, "", directory, dark_mode) + "@enduml\n"
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 393, in _readFileRec
    temp_file = self._readInclLine(
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 444, in _readInclLine
    raise e2
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 439, in _readInclLine
    temp_file = self._read_incl_line_file(
  File "/usr/local/lib/python3.9/site-packages/plantuml_markdown.py", line 458, in _read_incl_line_file
    with open(inc_file_abs, "r") as inc:
FileNotFoundError: [Errno 2] No such file or directory: 'AWSPuml/Containers/EKSCloud.puml'

The page content:


```plantuml
@startuml
!define AWSPuml https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v13.0/dist
!include <awslib/AWSCommon>
!include <awslib/Storage/S3Bucket>
!include AWSPuml/Containers/EKSCloud.puml
!include <awslib/Compute/Lambda>
!include <awslib/GroupIcons/VirtualPrivateCloudVPC>
!include <awslib/GroupIcons/VPCSubnetPublic>
!include <awslib/GroupIcons/VPCSubnetPrivate>
!include AWSPuml/NetworkingContentDelivery/ElasticLoadBalancingNetworkLoadBalancer.puml
!include AWSPuml/NetworkingContentDelivery/VPCNATGateway.puml
!include AWSPuml/NetworkingContentDelivery/TransitGateway.puml
!include <awslib/Database/RDS>
skinparam linetype ortho
...
mikitex70 commented 2 years ago

Hi @davidgiga1993, thanks for reporting the issue. It was caused by the !include directives not using explicitly the https prefix, but instead using the AWSPuml variable declared with the !define directive. The fix is now released in the 3.6.1 version.

davidgiga1993 commented 2 years ago

Thanks for the very quick fix!