Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ways to disable or customize ## comments? #268

Open
sqlalchemy-bot opened this issue Aug 29, 2017 · 5 comments
Open

Ways to disable or customize ## comments? #268

sqlalchemy-bot opened this issue Aug 29, 2017 · 5 comments

Comments

@sqlalchemy-bot
Copy link

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?

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

the preprocessor is there for this use case. What's inefficient about it?

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

well your preprocessor looks a little complicated...usually the <%text> </%text> block is used to delineate sections that should be passed through as is, any reason you can't just inject that?

@sqlalchemy-bot
Copy link
Author

Adam Twardoch (@twardoch) wrote:

The thing is that I’d effectively have to wrap 99.5% of my content in <%text>, which sort of defeats the purpose. My Markdown documents are regular Markdown documents, mostly. I don’t want to mark them up specially just in case I process it with Mako (i.e. they serve as a Mako template). I have a team of editors who are working on the documents. Only occasionally I want to use Mako constructs (usually module-level Python blocks, normal Python blocks, then sometimes Mako expressions and other constructs like for loops or ifs).

Mako serves my purposes perfectly, except for one thing — the inline Mako comments. Because of them, I have to do awkward things to my code that runs Mako. My Python Markdown extension slows the process down because of the extra regex substitution done twice — I have to replace ## by a dummy string, then call Mako, then replace the dummy string by ## again. This is impractical (especially for my other use cases, i.e. not Markdown).

So I wonder what the method would be to "disable" the Mako inline comments in some other way.

@sqlalchemy-bot
Copy link
Author

Adam Twardoch (@twardoch) wrote:

Ps. So are you saying I should regex-replace ^(##) by <%text>##</%text> before calling Mako and that would be it?

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

pretty much, either <%text> or do it as "${'##'}"

imphil added a commit to imphil/opentitan that referenced this issue Sep 17, 2020
The checklist template is processed by Mako, which uses `##` as template
comment. Use syntax which avoids stripping the headings out.

(The Mako comment behavior cannot really be configured; we could write a
pre-processor which does the escaping, but since we're only having a
single template here and many invocations of Mako in different scripts,
doing that seems fragile. See also
sqlalchemy/mako#268.)

Signed-off-by: Philipp Wagner <phw@lowrisc.org>
imphil added a commit to lowRISC/opentitan that referenced this issue Sep 17, 2020
The checklist template is processed by Mako, which uses `##` as template
comment. Use syntax which avoids stripping the headings out.

(The Mako comment behavior cannot really be configured; we could write a
pre-processor which does the escaping, but since we're only having a
single template here and many invocations of Mako in different scripts,
doing that seems fragile. See also
sqlalchemy/mako#268.)

Signed-off-by: Philipp Wagner <phw@lowrisc.org>
@bourke bourke added this to Icebox in Mako prioritization Nov 17, 2021
@bourke bourke moved this from Icebox to Deep Freeze in Mako prioritization Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

1 participant