sqlalchemy / sqlalchemy/mako

Proposal: enchance multiline doc regex with optional newline

Open
#247 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Migrated issue, originally created by jvanasco (@jvanasco)

I've run into a bit of an issue with whitespace and comments.

We've been in a push to standardize templates into a few core "layouts" to simplify mobile and device views.

Along with this push, has come a need to better document the mako templates inline.

Comments tend to situate best at the top of a document, however this creates leading whitespace before the doctype/html tags -- which is an issue for some 3rd party services and parsers. The mako-rendered templates can appear malformed, because they have some leading newline characters.

I'd like to propose extending the match_comment regex in lexer.py as follows:

- match = self.match(r"<%doc>(.*?)</%doc>", re.S)
+ match = self.match(r"<%doc>(.*?)</%doc>\n?", re.S)

This would allow this form of comment to be used:

^<%doc>
Docs here
</%doc>
<!DOCTYPE><html>blah</html>$

comments that start with leading ## will grab the newline character and not make it to the python generator

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 in lexer.py at the match_comment regex and compare its current handling of a newline after </%doc>. Verify the provided multiline template example no longer leaves the unwanted newline before the doctype, while the comment content still renders as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
web-dev
Issue type
Feature
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.