mosra / m.css

A no-nonsense, no-JavaScript CSS framework, site and documentation theme for content-oriented websites
https://mcss.mosra.cz
MIT License
399 stars 88 forks source link

PlantUML Support #236

Open JonTheBurger opened 1 year ago

JonTheBurger commented 1 year ago

Currently, m.css skips plantuml diagrams with the following message: "ignoring <plantuml> in desc". It looks like some manual workarounds are already required for doxygen limitations, and we have a similar case here. I wrote a quick and dirty snippet that seemed to work at least in the simple case. Is PlantUML similar to the following something you would be interested in accepting upstream? I would be willing to help out with this.

diff --git a/documentation/doxygen.py b/documentation/doxygen.py
index 2d5a6f9..3ed9613 100755
--- a/documentation/doxygen.py
+++ b/documentation/doxygen.py
@@ -1083,6 +1083,54 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
                     out.parsed += '<img class="m-image{}" src="{}" alt="Image"{} />'.format(
                         ' ' + add_css_class if add_css_class else '', name, sizespec)

+        elif i.tag == 'plantuml':
+            import shutil
+            import uuid
+
+            java_home = os.environ.get('JAVA_HOME')
+            if java_home:
+                java_home = os.path.join(java_home, '/bin/')
+            java = shutil.which('java', path=java_home)
+            if not os.path.exists(java):
+                logging.warning('PlantUML failed; Could not find java. Please set environment variable JAVA_HOME or add java to your PATH.')
+                continue
+
+            jar = state.doxyfile.get('PLANTUML_JAR_PATH')
+            print(state.doxyfile)
+            if not os.path.exists(jar):
+                logging.warning('PlantUML failed; Please set PLANTUML_JAR_PATH in your Doxyfile.')
+                continue
+
+            has_block_elements = True
+
+            dot_path = state.doxyfile.get('DOT_PATH')
+            plantuml_config = state.doxyfile.get('PLANTUML_CFG_FILE')
+            plantuml_includes = state.doxyfile.get('PLANTUML_INCLUDE_PATH')
+            name = str(uuid.uuid4())
+            out_path = os.path.join(state.basedir, state.doxyfile['OUTPUT_DIRECTORY'], state.doxyfile['XML_OUTPUT'])
+            img_path = os.path.join(out_path, name + '.png')
+            uml_path = os.path.join(out_path, name + '.uml')
+            with open(uml_path, 'w', encoding='utf-8') as uml:
+                uml.write('@startuml\n' + i.text + '\n@enduml\n')
+
+            plantuml_cmd = [java]
+            if plantuml_includes:
+                plantuml_cmd += ['-Dplantuml.include.path="' + os.pathsep.join(plantuml_includes) + '"']
+            plantuml_cmd += ['-jar', jar]
+            if plantuml_config:
+                plantuml_cmd += ['-config', plantuml_config]
+            if dot_path:
+                plantuml_cmd += ['-graphvizdot', dot_path]
+            plantuml_cmd += [uml_path]
+
+            print(plantuml_cmd)
+            logging.debug('running {}'.format(' '.join(plantuml_cmd)))
+            subprocess.run(plantuml_cmd, cwd=out_path, check=True)
+
+            state.images += [img_path]
+            out.parsed += '<img class="m-image{}" src="{}" alt="Image" />'.format(
+                ' ' + add_css_class if add_css_class else '', name + '.png')
+
         elif i.tag in ['dot', 'dotfile']:
             assert element.tag in ['para', '{http://mcss.mosra.cz/doxygen/}div']
             has_block_elements = True
@@ -3635,6 +3683,10 @@ def parse_doxyfile(state: State, doxyfile, values = None):

         ('DOT_FONTNAME', None, str),
         ('DOT_FONTSIZE', None, int),
+        ('DOT_PATH', None, str),
+        ('PLANTUML_CFG_FILE', None, str),
+        ('PLANTUML_JAR_PATH', None, str),
+        ('PLANTUML_INCLUDE_PATH', None, list),
         ('CREATE_SUBDIRS', None, bool), # processing fails below if this is set
         ('JAVADOC_AUTOBRIEF', None, bool),
         ('QT_AUTOBRIEF', None, bool),
mathisloge commented 4 months ago

I would love that feature