def content_callback(self, match):
content_type = getattr(self, 'content_type', None)
content = match.group()
offset = match.start() if content_type: from pygments.lexers import get_lexer_for_mimetype
possible_lexer_mimetypes = [content_type] if'+'in content_type: # application/calendar+xml can be treated as application/xml # if there's not a better match.
general_type = re.sub(r'^(.*)/.*\+(.*)$', r'\1/\2',
content_type)
possible_lexer_mimetypes.append(general_type)
for i in possible_lexer_mimetypes: try:
lexer = get_lexer_for_mimetype(i) except ClassNotFound: pass else: for idx, token, value in lexer.get_tokens_unprocessed(content): yield offset + idx, token, value return yield offset, Text, content
def analyse_text(text): return any (
re.search(pattern, text) isnotNone for pattern in (
r'^([a-zA-Z][-_a-zA-Z]+)( +)([^ ]+)( +)(HTTP)(/)(1\.[01]|2(?:\.0)?|3)(\r?\n|\Z)',
r'^(HTTP)(/)(1\.[01]|2(?:\.0)?|3)( +)(\d{3})(?:( +)([^\r\n]*))?(\r?\n|\Z)',
)
)
class TodotxtLexer(RegexLexer): """
Lexer for Todo.txt todo list format. """
name = 'Todotxt'
url = 'http://todotxt.com/'
aliases = ['todotxt']
version_added = '2.0' # *.todotxt is not a standard extension for Todo.txt files; including it # makes testing easier, and also makes autodetecting file type easier.
filenames = ['todo.txt', '*.todotxt']
mimetypes = ['text/x-todo']
# Aliases mapping standard token types of Todo.txt format concepts
CompleteTaskText = Operator # Chosen to de-emphasize complete tasks
IncompleteTaskText = Text # Incomplete tasks should look like plain text
# Priority should have most emphasis to indicate importance of tasks
Priority = Generic.Heading # Dates should have next most emphasis because time is important
Date = Generic.Subheading
# Project and context should have equal weight, and be in different colors
Project = Generic.Error
Context = String
# If tag functionality is added, it should have the same weight as Project # and Context, and a different color. Generic.Traceback would work well.
# Regex patterns for building up rules; dates, priorities, projects, and # contexts are all atomic # TODO: Make date regex more ISO 8601 compliant
date_regex = r'\d{4,}-\d{2}-\d{2}'
priority_regex = r'\([A-Z]\)'
project_regex = r'\+\S+'
context_regex = r'@\S+'
tokens = { # Should parse starting at beginning of line; each line is a task 'root': [ # Complete task entry points: two total: # 1. Complete task with two dates
(complete_two_date_regex, bygroups(CompleteTaskText, Date,
CompleteTaskText, Date), 'complete'), # 2. Complete task with one date
(complete_one_date_regex, bygroups(CompleteTaskText, Date), 'complete'),
# Incomplete task entry points: six total: # 1. Priority plus date
(priority_date_regex, bygroups(Priority, IncompleteTaskText, Date), 'incomplete'), # 2. Priority only
(priority_regex, Priority, 'incomplete'), # 3. Leading date
(date_regex, Date, 'incomplete'), # 4. Leading context
(context_regex, Context, 'incomplete'), # 5. Leading project
(project_regex, Project, 'incomplete'), # 6. Non-whitespace catch-all
(r'\S+', IncompleteTaskText, 'incomplete'),
],
# Parse a complete task 'complete': [ # Newline indicates end of task, should return to root
(r'\s*\n', CompleteTaskText, '#pop'), # Tokenize contexts and projects
(context_regex, Context),
(project_regex, Project), # Tokenize non-whitespace text
(r'\S+', CompleteTaskText), # Tokenize whitespace not containing a newline
(r'\s+', CompleteTaskText),
],
# Parse an incomplete task 'incomplete': [ # Newline indicates end of task, should return to root
(r'\s*\n', IncompleteTaskText, '#pop'), # Tokenize contexts and projects
(context_regex, Context),
(project_regex, Project), # Tokenize non-whitespace text
(r'\S+', IncompleteTaskText), # Tokenize whitespace not containing a newline
(r'\s+', IncompleteTaskText),
],
}
class NotmuchLexer(RegexLexer): """ For Notmuch email text format.
Additional options accepted:
`body_lexer` If given, highlight the contents of the message body with the specified
lexer, else guess it according to the body content (default: ``None``). """
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.