backstage / mkdocs-techdocs-core

The core MkDocs plugin used by Backstage's TechDocs as a wrapper around multiple MkDocs plugins and Python Markdown extensions
Apache License 2.0
87 stars 64 forks source link

Bug: Issue with Liquid template in markdown caused by `markdown_inline_graphviz` #102

Closed joshbranham closed 10 months ago

joshbranham commented 1 year ago

We are utilizing this plugin for our TechDocs generation for Backstage. We have a few markdown files with liquid templates nested in code blocks/fences, and they are being parsed as functions by what appears to be markdown_inline_graphviz per the below trace.

Example of a markdown block using this:

### Examples

```liquid
{% capture category %}{{ entity | property_value: 'Category' }}{% endcapture %}
{% if category == 'Pants' %}
  Resolution A
{% elsif category == 'Shoes' %}
  Resolution B
{% else %}
  Unknown
{% endif %}

Per the readme shouldn't this plugin be disabled unless I say to enable it?

markdown_inline_graphviz: A Python Markdown extension replaces inline Graphviz definitions with inline SVGs or PNGs. Activate the inline_graphviz extension using the usage instructions.


Our error:

verbose: [docker/mkdocs] ERROR - Error reading page 'public/guides/built-in-step-types.md': Command not supported: else verbose: [docker/mkdocs] Traceback (most recent call last): verbose: [docker/mkdocs] File "/usr/local/bin/mkdocs", line 8, in verbose: [docker/mkdocs] sys.exit(cli()) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1130, in call verbose: [docker/mkdocs] return self.main(args, kwargs) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1055, in main verbose: [docker/mkdocs] rv = self.invoke(ctx) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1657, in invoke verbose: [docker/mkdocs] return _process_result(sub_ctx.command.invoke(sub_ctx)) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1404, in invoke verbose: [docker/mkdocs] return ctx.invoke(self.callback, ctx.params) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/click/core.py", line 760, in invoke verbose: [docker/mkdocs] return __callback(args, kwargs) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/mkdocs/main.py", line 181, in serve_command verbose: [docker/mkdocs] serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, kwargs) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/mkdocs/commands/serve.py", line 63, in serve verbose: [docker/mkdocs] config = builder() verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/mkdocs/commands/serve.py", line 58, in builder verbose: [docker/mkdocs] build(config, live_server=live_server, dirty=dirty) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/mkdocs/commands/build.py", line 292, in build verbose: [docker/mkdocs] _populate_page(file.page, config, files, dirty) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/mkdocs/commands/build.py", line 174, in _populate_page verbose: [docker/mkdocs] page.render(config, files) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/mkdocs/structure/pages.py", line 175, in render verbose: [docker/mkdocs] self.content = md.convert(self.markdown) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/markdown/core.py", line 261, in convert verbose: [docker/mkdocs] self.lines = prep.run(self.lines) verbose: [docker/mkdocs] File "/usr/local/lib/python3.8/site-packages/markdown_inline_graphviz.py", line 68, in run verbose: [docker/mkdocs] raise Exception('Command not supported: %s' % command) verbose: [docker/mkdocs] Exception: Command not supported: else


Our `mkdocs.yml`:

... plugins:

I opened this issue but I don't think it is a specific mkdocs issue https://github.com/mkdocs/mkdocs/issues/3067

Also of note, if I remove plugins from our config file and run npx @techdocs/cli serve -v the error goes away (although the resulting documentation is blank, which I imagine is due to removing all plugins.)

joshbranham commented 1 year ago

I can see here in the source we load the markdown_inline_graphviz plugin no matter what, which I think is the problem here. In our case we are not even using it, so being able to disable it would be helpful. Is there a path to do that?

https://github.com/backstage/mkdocs-techdocs-core/blob/c45280572c590e33ff5bbd82edede53830fdf9bb/src/core.py#L118

joshbranham commented 1 year ago

I can also see someone forked that plugin (https://github.com/cesaremorel/markdown-inline-graphviz) and changed it to use the following to denote an image instead of conflicting with Liquid/Jinja {% syntax. Anyway to use that instead of the other one?

```graphviz
kunickiaj commented 1 year ago

Running into the same issue here actually. The plugin version you linked is the one used here by techdocs-core. While it has the new syntax it does not disable the legacy (conflicting) syntax.

I haven't yet found a workaround and this is certainly a blocker for me atm.

kunickiaj commented 1 year ago

BTW, it seems this fork has continued some work and removed the legacy syntax so that it doesn't conflict.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Pike commented 1 year ago

Bump

robinselmer commented 1 year ago

We are utilizing this plugin for our TechDocs generation for Backstage, too. When using Symfony Twig code like this

{% if areaname is defined and areaname is not empty %}
    ...
{% endif %}

it throws following error

verbose: [docker/mkdocs]   File "/usr/local/lib/python3.8/site-packages/markdown_inline_graphviz.py", line 68, in run
verbose: [docker/mkdocs]     raise Exception('Command not supported: %s' % command)
verbose: [docker/mkdocs] Exception: Command not supported: endif
owenbush commented 11 months ago

I was experiencing this same issue with twig template syntax, the way I managed to work around it was to just indent the twig markup inside of the code block.

```twig
{% if foo %}
  {{ foo }}
{% endif %}
I did 
  {% if foo %}
    {{ foo }}
  {% endif %}
CasperGN commented 10 months ago

Can only chime into the choir here that using standard mkdocs file:

site_name: 'Bifrost Docs'

exclude_docs: |
  documentation-templates/

plugins:
  - techdocs-core

the exclude is to NOT pick up the templates that are causing the rendering issue

I also observe that any liquid syntaxed markdown will throw an error on the keywords if, else, continue and so on. I've yet to find a way to make it not parse the liquid template but rather just render the markdown into html.

For now we circumvent it by excluding the template directory but I do see valid use-cases for liquid syntax'ed markdown being rendered without being parsed.

Should I open a separate issue on this matter?