fralau / mkdocs-macros-plugin

Create richer and more beautiful pages in MkDocs, by using variables and calls to macros in the markdown code.
https://mkdocs-macros-plugin.readthedocs.io
Other
318 stars 50 forks source link

Header anchor missing end of comment tag processing content produced with attribute lists #208

Closed jodygarnett closed 4 months ago

jodygarnett commented 6 months ago

I have gotten stuck on an interesting challenge, I am cleaning up some docs converted with pandoc resulting in headers with attribute_list snippets information.

## Installing the Db2 extension {#Db2_install}

This falls squarely into the User Manual "Elsewhere" Solution 5

plugins:
  - macros:
      render_by_default: false
      on_error_fail: true
      on_undefined: keep
      j2_block_start_string: '[[%'
      j2_block_end_string: '%]]'
      j2_variable_start_string: '[['
      j2_variable_end_string: ']]'

These settings are picked up:

INFO    -  Building documentation...
INFO    -  [macros] - Macros arguments: {'module_name': 'main', 'modules': [], 'render_by_default': False, 'include_dir': '', 'include_yaml': [], 'j2_block_start_string': '[[%', 'j2_block_end_string': '%]]', 'j2_variable_start_string': '[[', 'j2_variable_end_string': ']]', 'on_undefined':
           'keep', 'on_error_fail': True, 'verbose': False}
INFO    -  [macros] - Extra variables (config file): ['homepage', 'social', 'version', 'release']
INFO    -  [macros] - Extra filters (module): ['pretty']
INFO    -  [macros] - Found j2 variable 'block_start_string': '[[%'
INFO    -  [macros] - Found j2 variable 'block_end_string': '%]]'
INFO    -  [macros] - Found j2 variable 'variable_start_string': '[['
INFO    -  [macros] - Found j2 variable 'variable_end_string': ']]'

But stumble on {#identifier}:

INFO    -  [macros] - ERROR # _Macro Syntax Error_

           _File_: `data/database/h2.md`

           _Line 7 in Markdown file:_ **Missing end of comment tag**
           ```markdown
           ## Installing the H2 extension {#h2_install}


Is there a need for a `j2_comment_start_string` and `j2_comment_end_string` ?
github-actions[bot] commented 6 months ago

Welcome to this project and thank you!' first issue

jodygarnett commented 6 months ago

As a workaround I am going to try and post process the content to:

## Installing the Db2 extension {: #Db2_install }
fralau commented 6 months ago

Could be 🤔

For reference,

Are you willing to propose a PR and test whether it solves the problem for you?

jodygarnett commented 6 months ago

My workaround (post processing) was successful ; but I know how frustrating it is if people do not report issues.


I am nominally a java developer so I am afraid I am embarrassed to try hacking at Python code.

  1. Let me check if Jina2 supports customization of comment start / end string...
  2. Checking for code you are following naming convention and adding to "Environment"
  3. Looking at Jinja documentation comment_start_string and comment_end_string are documented as parameters
  4. I am not sure how Environment is handed over to Jinja as paramaters but it is worth a test
fralau commented 6 months ago

@jodygarnett No problem. If you prefer, I can do the change and it might still be fun for you to have a look at the diff?

When I didn't know anything at all of Python, I chose a super simple and short manual called Python Phrasebook; it was easy reading, and I completed it in a couple of evenings. It gave the few central ideas on which I could build all the rest. You might need a more recent book, because it covers Python 2 (instead of Python 3), but it's the approach that worked for me.

fralau commented 6 months ago

I pushed an update on github with e.g.:

plugins:
  - search
  - macros:
      j2_block_start_string: '[[%'
      j2_block_end_string: '%]]'
      j2_variable_start_string: '[['
      j2_variable_end_string: ']]'
      j2_comment_start_string: '[#'
      j2_comment_end_string: '#]'

I also updated the new_syntax website (in the test directory) and checked that it works.

Could you try it for your use case and let me know if it works?

jodygarnett commented 6 months ago

Yes happy to try, just need to figure out how to test from GitHub.

fralau commented 6 months ago

Thanks! The best thing is to git clone (or download zip) and install from there.

Capture d’écran 2024-02-23 à 11 31 47