mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 13:41:15 -07:00
Update mako to 1.1.0
This commit is contained in:
parent
84ce4758d1
commit
f2d7beec90
27 changed files with 2424 additions and 1890 deletions
|
@ -1,44 +1,73 @@
|
|||
# ext/pygmentplugin.py
|
||||
# Copyright (C) 2006-2015 the Mako authors and contributors <see AUTHORS file>
|
||||
# Copyright 2006-2019 the Mako authors and contributors <see AUTHORS file>
|
||||
#
|
||||
# This module is part of Mako and is released under
|
||||
# the MIT License: http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
from pygments.lexers.web import \
|
||||
HtmlLexer, XmlLexer, JavascriptLexer, CssLexer
|
||||
from pygments.lexers.agile import PythonLexer, Python3Lexer
|
||||
from pygments.lexer import DelegatingLexer, RegexLexer, bygroups, \
|
||||
include, using
|
||||
from pygments.token import \
|
||||
Text, Comment, Operator, Keyword, Name, String, Other
|
||||
from pygments.formatters.html import HtmlFormatter
|
||||
from pygments import highlight
|
||||
from pygments.formatters.html import HtmlFormatter
|
||||
from pygments.lexer import bygroups
|
||||
from pygments.lexer import DelegatingLexer
|
||||
from pygments.lexer import include
|
||||
from pygments.lexer import RegexLexer
|
||||
from pygments.lexer import using
|
||||
from pygments.lexers.agile import Python3Lexer
|
||||
from pygments.lexers.agile import PythonLexer
|
||||
from pygments.lexers.web import CssLexer
|
||||
from pygments.lexers.web import HtmlLexer
|
||||
from pygments.lexers.web import JavascriptLexer
|
||||
from pygments.lexers.web import XmlLexer
|
||||
from pygments.token import Comment
|
||||
from pygments.token import Keyword
|
||||
from pygments.token import Name
|
||||
from pygments.token import Operator
|
||||
from pygments.token import Other
|
||||
from pygments.token import String
|
||||
from pygments.token import Text
|
||||
|
||||
from mako import compat
|
||||
|
||||
|
||||
class MakoLexer(RegexLexer):
|
||||
name = 'Mako'
|
||||
aliases = ['mako']
|
||||
filenames = ['*.mao']
|
||||
name = "Mako"
|
||||
aliases = ["mako"]
|
||||
filenames = ["*.mao"]
|
||||
|
||||
tokens = {
|
||||
'root': [
|
||||
(r'(\s*)(\%)(\s*end(?:\w+))(\n|\Z)',
|
||||
bygroups(Text, Comment.Preproc, Keyword, Other)),
|
||||
(r'(\s*)(\%(?!%))([^\n]*)(\n|\Z)',
|
||||
bygroups(Text, Comment.Preproc, using(PythonLexer), Other)),
|
||||
(r'(\s*)(##[^\n]*)(\n|\Z)',
|
||||
bygroups(Text, Comment.Preproc, Other)),
|
||||
(r'''(?s)<%doc>.*?</%doc>''', Comment.Preproc),
|
||||
(r'(<%)([\w\.\:]+)',
|
||||
bygroups(Comment.Preproc, Name.Builtin), 'tag'),
|
||||
(r'(</%)([\w\.\:]+)(>)',
|
||||
bygroups(Comment.Preproc, Name.Builtin, Comment.Preproc)),
|
||||
(r'<%(?=([\w\.\:]+))', Comment.Preproc, 'ondeftags'),
|
||||
(r'(<%(?:!?))(.*?)(%>)(?s)',
|
||||
bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
|
||||
(r'(\$\{)(.*?)(\})',
|
||||
bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
|
||||
(r'''(?sx)
|
||||
"root": [
|
||||
(
|
||||
r"(\s*)(\%)(\s*end(?:\w+))(\n|\Z)",
|
||||
bygroups(Text, Comment.Preproc, Keyword, Other),
|
||||
),
|
||||
(
|
||||
r"(\s*)(\%(?!%))([^\n]*)(\n|\Z)",
|
||||
bygroups(Text, Comment.Preproc, using(PythonLexer), Other),
|
||||
),
|
||||
(
|
||||
r"(\s*)(##[^\n]*)(\n|\Z)",
|
||||
bygroups(Text, Comment.Preproc, Other),
|
||||
),
|
||||
(r"""(?s)<%doc>.*?</%doc>""", Comment.Preproc),
|
||||
(
|
||||
r"(<%)([\w\.\:]+)",
|
||||
bygroups(Comment.Preproc, Name.Builtin),
|
||||
"tag",
|
||||
),
|
||||
(
|
||||
r"(</%)([\w\.\:]+)(>)",
|
||||
bygroups(Comment.Preproc, Name.Builtin, Comment.Preproc),
|
||||
),
|
||||
(r"<%(?=([\w\.\:]+))", Comment.Preproc, "ondeftags"),
|
||||
(
|
||||
r"(?s)(<%(?:!?))(.*?)(%>)",
|
||||
bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc),
|
||||
),
|
||||
(
|
||||
r"(\$\{)(.*?)(\})",
|
||||
bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc),
|
||||
),
|
||||
(
|
||||
r"""(?sx)
|
||||
(.+?) # anything, followed by:
|
||||
(?:
|
||||
(?<=\n)(?=%(?!%)|\#\#) | # an eval or comment line
|
||||
|
@ -51,72 +80,78 @@ class MakoLexer(RegexLexer):
|
|||
(\\\n) | # an escaped newline
|
||||
\Z # end of string
|
||||
)
|
||||
''', bygroups(Other, Operator)),
|
||||
(r'\s+', Text),
|
||||
""",
|
||||
bygroups(Other, Operator),
|
||||
),
|
||||
(r"\s+", Text),
|
||||
],
|
||||
'ondeftags': [
|
||||
(r'<%', Comment.Preproc),
|
||||
(r'(?<=<%)(include|inherit|namespace|page)', Name.Builtin),
|
||||
include('tag'),
|
||||
"ondeftags": [
|
||||
(r"<%", Comment.Preproc),
|
||||
(r"(?<=<%)(include|inherit|namespace|page)", Name.Builtin),
|
||||
include("tag"),
|
||||
],
|
||||
'tag': [
|
||||
(r'((?:\w+)\s*=)\s*(".*?")',
|
||||
bygroups(Name.Attribute, String)),
|
||||
(r'/?\s*>', Comment.Preproc, '#pop'),
|
||||
(r'\s+', Text),
|
||||
"tag": [
|
||||
(r'((?:\w+)\s*=)\s*(".*?")', bygroups(Name.Attribute, String)),
|
||||
(r"/?\s*>", Comment.Preproc, "#pop"),
|
||||
(r"\s+", Text),
|
||||
],
|
||||
'attr': [
|
||||
('".*?"', String, '#pop'),
|
||||
("'.*?'", String, '#pop'),
|
||||
(r'[^\s>]+', String, '#pop'),
|
||||
"attr": [
|
||||
('".*?"', String, "#pop"),
|
||||
("'.*?'", String, "#pop"),
|
||||
(r"[^\s>]+", String, "#pop"),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
class MakoHtmlLexer(DelegatingLexer):
|
||||
name = 'HTML+Mako'
|
||||
aliases = ['html+mako']
|
||||
name = "HTML+Mako"
|
||||
aliases = ["html+mako"]
|
||||
|
||||
def __init__(self, **options):
|
||||
super(MakoHtmlLexer, self).__init__(HtmlLexer, MakoLexer,
|
||||
**options)
|
||||
super(MakoHtmlLexer, self).__init__(HtmlLexer, MakoLexer, **options)
|
||||
|
||||
|
||||
class MakoXmlLexer(DelegatingLexer):
|
||||
name = 'XML+Mako'
|
||||
aliases = ['xml+mako']
|
||||
name = "XML+Mako"
|
||||
aliases = ["xml+mako"]
|
||||
|
||||
def __init__(self, **options):
|
||||
super(MakoXmlLexer, self).__init__(XmlLexer, MakoLexer,
|
||||
**options)
|
||||
super(MakoXmlLexer, self).__init__(XmlLexer, MakoLexer, **options)
|
||||
|
||||
|
||||
class MakoJavascriptLexer(DelegatingLexer):
|
||||
name = 'JavaScript+Mako'
|
||||
aliases = ['js+mako', 'javascript+mako']
|
||||
name = "JavaScript+Mako"
|
||||
aliases = ["js+mako", "javascript+mako"]
|
||||
|
||||
def __init__(self, **options):
|
||||
super(MakoJavascriptLexer, self).__init__(JavascriptLexer,
|
||||
MakoLexer, **options)
|
||||
super(MakoJavascriptLexer, self).__init__(
|
||||
JavascriptLexer, MakoLexer, **options
|
||||
)
|
||||
|
||||
|
||||
class MakoCssLexer(DelegatingLexer):
|
||||
name = 'CSS+Mako'
|
||||
aliases = ['css+mako']
|
||||
name = "CSS+Mako"
|
||||
aliases = ["css+mako"]
|
||||
|
||||
def __init__(self, **options):
|
||||
super(MakoCssLexer, self).__init__(CssLexer, MakoLexer,
|
||||
**options)
|
||||
super(MakoCssLexer, self).__init__(CssLexer, MakoLexer, **options)
|
||||
|
||||
|
||||
pygments_html_formatter = HtmlFormatter(cssclass='syntax-highlighted',
|
||||
linenos=True)
|
||||
def syntax_highlight(filename='', language=None):
|
||||
pygments_html_formatter = HtmlFormatter(
|
||||
cssclass="syntax-highlighted", linenos=True
|
||||
)
|
||||
|
||||
|
||||
def syntax_highlight(filename="", language=None):
|
||||
mako_lexer = MakoLexer()
|
||||
if compat.py3k:
|
||||
python_lexer = Python3Lexer()
|
||||
else:
|
||||
python_lexer = PythonLexer()
|
||||
if filename.startswith('memory:') or language == 'mako':
|
||||
return lambda string: highlight(string, mako_lexer,
|
||||
pygments_html_formatter)
|
||||
return lambda string: highlight(string, python_lexer,
|
||||
pygments_html_formatter)
|
||||
|
||||
if filename.startswith("memory:") or language == "mako":
|
||||
return lambda string: highlight(
|
||||
string, mako_lexer, pygments_html_formatter
|
||||
)
|
||||
return lambda string: highlight(
|
||||
string, python_lexer, pygments_html_formatter
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue