Search code examples
gramex

Does Gramex have inbuild Markdown handler? If yes, how to use that?


Trying to create a wiki site similar to gramex help document. For that, I have gramex.yaml that reads

url:
  main:
    pattern: /$YAMLURL/
    handler: FileHandler
    kwargs:
      index: false
      path:
        "": $YAMLPATH/{dir}/readme.md
      transform:
        "*.md":
          encoding: utf-8
          function: markdown.markdown(content)
          headers:
            Content-Type: text/html; charset=UTF-8

File tree looks like:

$ tree
.
├── behave
│   └── readme.md
├── gramex.yaml
└── readme.md

But it does not seem to render any MARKDOWN files as HTML. Do I need to create this markdown.markdown function? or Is this function readily available in gramex?


Edit 1:

The render issue came because of {dir} in path.

Solution:

Remove {dir} and make the new path as :- $YAMLPATH/readme.md


EDIT 2: NEW PROBLEM

Markdown tables are not rendered I have a table in the markdown as:

| Criteria | Behave | Pytest |
| --- | --- | --- |
| Readability | Tests are written in natural language format, making them easier to understand by both technical and non-technical stakeholders. | Tests are written in code format, which can be challenging for non-technical stakeholders to understand. |

That must be rendered as:

enter image description here but the webpage shows:

enter image description here


Solution

  • If you change

              function: markdown.markdown(content)
    

    ... to

              function: markdown.markdown(content, extensions=['extra'])
    

    ... it starts working, thanks to the tables extension which is part of the extra extension.

    For more Python markdown options, see https://python-markdown.github.io/reference/.

    For extensions, see https://python-markdown.github.io/extensions/