preprocessors.py 600 B

1234567891011121314151617181920
  1. # ext/preprocessors.py
  2. # Copyright (C) 2006-2016 the Mako authors and contributors <see AUTHORS file>
  3. #
  4. # This module is part of Mako and is released under
  5. # the MIT License: http://www.opensource.org/licenses/mit-license.php
  6. """preprocessing functions, used with the 'preprocessor'
  7. argument on Template, TemplateLookup"""
  8. import re
  9. def convert_comments(text):
  10. """preprocess old style comments.
  11. example:
  12. from mako.ext.preprocessors import convert_comments
  13. t = Template(..., preprocessor=convert_comments)"""
  14. return re.sub(r'(?<=\n)\s*#[^#]', "##", text)