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

Support Macros escaping #192

Closed oleg-nenashev closed 7 months ago

oleg-nenashev commented 8 months ago

It would be nice to be able to escape Macros so that they are ignored by the engine, e.g. if they are supposed to be added to documentation as is. At least, the triple bracket for Handlebars does not work, and there are also non-fatal resolution warnings for other macros in code samples

My use-case

Error for `{{{ in code

In https://github.com/wiremock/wiremock.org/pull/228 I am moving the documentation for WireMock which also includes its internal Handlebars-based engine. Based on that, there might be documentation lines like the following:

`--filename-template`: Set filename template in handlebar format. For endpoint: `GET /pets/{id}` using the format: `{{{method}}}-{{{url}}}.json` output will be `get-pets-id.json`. Default format: `{{{method}}}-{{{path}}}-{{{id}}}.json` hence by default template filename will be: `get-pets-id-1.json`.
Note: introduced in [3.0.0-beta-8](https://github.com/wiremock/wiremock/releases/tag/3.0.0-beta-8).

And this macro gets picked up by the plugins, and it results in page rendering failure:

INFO    -  [macros] - ERROR # _Macro Syntax Error_

           _File_: `standalone/java-jar.md`

           _Line 172 in Markdown file:_ **expected token ':', got '}'**
           ```markdown
           `--filename-template`: Set filename template in handlebar format. For endpoint: `GET /pets/{id}` using the format:
           `{{{method}}}-{{{url}}}.json` output will be `get-pets-id.json`. Default format: `{{{method}}}-{{{path}}}-{{{id}}}.json` hence by default
           template filename will be: `get-pets-id-1.json`.

## Warnings during the build

WARNING - A relative path to 'dotgithub/SECURITY.md' is included in the 'nav' configuration, which is not found in the documentation files. INFO - [macros] - ERROR # Macro Syntax Error

       _File_: `configuration.md`

       _Line 239 in Markdown file:_ **expected token ':', got '}'**
       ```markdown
       For instance for endpoint `PUT /hosts/{id}` and format `{{{method}}}-{{{request.url}}}.json`
       ```

WARNING - Doc file 'download-and-installation.md' contains a relative link './running-standalone.md', but the target 'running-standalone.md' is not found among documentation files. INFO - [macros] - ERROR # Macro Syntax Error

       _File_: `grpc.md`

       _Line 80 in Markdown file:_ **expected token 'end of print statement', got 'request'**
       ```markdown
                       "{ \"greeting\": \"Hello {{jsonPath request.body '$.name'}}\" }")));
       ```

INFO - Doc file 'participate.md' contains an unrecognized relative link '../support', it was left as is. INFO - Doc file 'proxying.md' contains an unrecognized relative link '../api/#tag/System/paths/~1__admin~1settings/post', it was left as is. INFO - [macros] - ERROR # Macro Syntax Error

       _File_: `standalone/java-jar.md`

       _Line 170 in Markdown file:_ **expected token ':', got '}'**
       ```markdown
       `--filename-template`: Set filename template in handlebar format. For endpoint: `GET /pets/{id}` using the format:
       `{{{method}}}-{{{url}}}.json` output will be `get-pets-id.json`. Default format: `{{{method}}}-{{{path}}}-{{{id}}}.json` hence by default
       template filename will be: `get-pets-id-1.json`.
       ```

INFO - [SASS] Build CSS "assets/stylesheets/extra-style.hiztdwb7.min.css" from "extra_sass/style.css.scss"

fralau commented 8 months ago

This documentation page provides a number of possible approaches to controlling the rendering of pages. Solution 4 might do it for you?

oleg-nenashev commented 8 months ago

@fralau Indeed, option 4 works. I saw it, but didn't think it could work for inline definitions. Indeed it does: https://github.com/wiremock/wiremock.org/pull/228/commits/9fcfe90135e3fd5daee7f3b4ec747e01340b0526

fralau commented 8 months ago

Problem solved, documentation updated.