Cloned DMOJ
This commit is contained in:
parent
f623974b58
commit
49dc9ff10c
513 changed files with 132349 additions and 39 deletions
29
judge/jinja2/spaceless.py
Normal file
29
judge/jinja2/spaceless.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import re
|
||||
|
||||
from jinja2 import Markup, nodes
|
||||
from jinja2.ext import Extension
|
||||
|
||||
|
||||
class SpacelessExtension(Extension):
|
||||
"""
|
||||
Removes whitespace between HTML tags at compile time, including tab and newline characters.
|
||||
It does not remove whitespace between jinja2 tags or variables. Neither does it remove whitespace between tags
|
||||
and their text content.
|
||||
Adapted from coffin:
|
||||
https://github.com/coffin/coffin/blob/master/coffin/template/defaulttags.py
|
||||
Adapted from StackOverflow:
|
||||
https://stackoverflow.com/a/23741298/1090657
|
||||
"""
|
||||
|
||||
tags = {'spaceless'}
|
||||
|
||||
def parse(self, parser):
|
||||
lineno = next(parser.stream).lineno
|
||||
body = parser.parse_statements(['name:endspaceless'], drop_needle=True)
|
||||
return nodes.CallBlock(
|
||||
self.call_method('_strip_spaces', [], [], None, None),
|
||||
[], [], body,
|
||||
).set_lineno(lineno)
|
||||
|
||||
def _strip_spaces(self, caller=None):
|
||||
return Markup(re.sub(r'>\s+<', '><', caller().unescape().strip()))
|
Loading…
Add table
Add a link
Reference in a new issue