sqlalchemy / sqlalchemy/mako

Ways to disable or customize `##` comments?

Open
#268 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

task
Dominant language
Python
Stars
459
Forks
90
PR merge metrics
No merged PRs in 30d

Description

Migrated issue, originally created by Adam Twardoch (@twardoch)

I'm using Mako to process not HTML but other types of human-readable documents, specifically:

  • Markdown
  • YAML
  • Adobe FEA
  • A few other, similar dialects

By "process" I mean that I have files written in such a dialect with Mako inserts (so they're templates) and I use the Mako code to fill in some data and generate a final document in the same dialect.

I highly value the fact that Mako allows direct and simple embedding of Python blocks into the templates and does not insist on putting logic into some complicated external modules (like for instance Jinja2 does). This aspect of Mako is really great. I'm not concerned with super-high performance because my Mako templates are deployed in a very controlled scenarios.

One common thing to all those dialects is that they use single-line comments prefixed by # or sometimes ##. In case of Markdown, these are not comments of course but ## actually stands for H2 headings.

But Mako interprets ## as its own comments, which interfers with those dialects.

For my md_mako extension for Python Markdown, which preprocesses Markdown with embedded Mako portions and returns regularized Markdown:

I used a stupid trick (replacing ## with a stub string before calling Mako, and then reversing the change afterwards). But this is very inefficient.

So: how can I prevent those from processing those single-line Mako comments that are prefixed with ##? I could settle for specifying another more elaborate prefix instead or not having such comments at all.

In other words: I want Mako to treat lines that start with ## like any other text lines.

How do I do that?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced mdx_steroids/md_mako.py extension and the Mako comment-processing behavior described in the issue. Determine whether configurable comment prefixes or disabled ## handling can support Markdown, YAML, and similar dialects; done means lines beginning with ## pass through as text without the replacement workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
markdown, python, yaml
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.