Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
MoinMoin.support.pygments.lexers.text.RstLexer Class Reference
Inheritance diagram for MoinMoin.support.pygments.lexers.text.RstLexer:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.pygments.lexers.text.RstLexer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def analyse_text

Public Attributes

 handlecodeblocks

Static Public Attributes

string name = 'reStructuredText'
list aliases = ['rst', 'rest', 'restructuredtext']
list filenames = ['*.rst', '*.rest']
list mimetypes = ["text/x-rst", "text/prs.fallenstein.rst"]
 flags = re.MULTILINE
dictionary tokens

Private Member Functions

def _handle_sourcecode

Detailed Description

For `reStructuredText <http://docutils.sf.net/rst.html>`_ markup.

*New in Pygments 0.7.*

Additional options accepted:

`handlecodeblocks`
    Highlight the contents of ``.. sourcecode:: langauge`` and
    ``.. code:: language`` directives with a lexer for the given
    language (default: ``True``). *New in Pygments 0.8.*

Definition at line 577 of file text.py.


Constructor & Destructor Documentation

Definition at line 711 of file text.py.

00711 
00712     def __init__(self, **options):
00713         self.handlecodeblocks = get_bool_opt(options, 'handlecodeblocks', True)
00714         RegexLexer.__init__(self, **options)


Member Function Documentation

Definition at line 596 of file text.py.

00596 
00597     def _handle_sourcecode(self, match):
00598         from pygments.lexers import get_lexer_by_name
00599         from pygments.util import ClassNotFound
00600 
00601         # section header
00602         yield match.start(1), Punctuation, match.group(1)
00603         yield match.start(2), Text, match.group(2)
00604         yield match.start(3), Operator.Word, match.group(3)
00605         yield match.start(4), Punctuation, match.group(4)
00606         yield match.start(5), Text, match.group(5)
00607         yield match.start(6), Keyword, match.group(6)
00608         yield match.start(7), Text, match.group(7)
00609 
00610         # lookup lexer if wanted and existing
00611         lexer = None
00612         if self.handlecodeblocks:
00613             try:
00614                 lexer = get_lexer_by_name(match.group(6).strip())
00615             except ClassNotFound:
00616                 pass
00617         indention = match.group(8)
00618         indention_size = len(indention)
00619         code = (indention + match.group(9) + match.group(10) + match.group(11))
00620 
00621         # no lexer for this language. handle it like it was a code block
00622         if lexer is None:
00623             yield match.start(8), String, code
00624             return
00625 
00626         # highlight the lines with the lexer.
00627         ins = []
00628         codelines = code.splitlines(True)
00629         code = ''
00630         for line in codelines:
00631             if len(line) > indention_size:
00632                 ins.append((len(code), [(0, Text, line[:indention_size])]))
00633                 code += line[indention_size:]
00634             else:
00635                 code += line
00636         for item in do_insertions(ins, lexer.get_tokens_unprocessed(code)):
00637             yield item

Here is the call graph for this function:

Definition at line 715 of file text.py.

00715 
00716     def analyse_text(text):
00717         if text[:2] == '..' and text[2:3] != '.':
00718             return 0.3
00719         p1 = text.find("\n")
00720         p2 = text.find("\n", p1 + 1)
00721         if (p2 > -1 and              # has two lines
00722             p1 * 2 + 1 == p2 and     # they are the same length
00723             text[p1+1] in '-=' and   # the next line both starts and ends with
00724             text[p1+1] == text[p2-1]): # ...a sufficiently high header
00725             return 0.5
00726 


Member Data Documentation

list MoinMoin.support.pygments.lexers.text.RstLexer.aliases = ['rst', 'rest', 'restructuredtext'] [static]

Definition at line 591 of file text.py.

list MoinMoin.support.pygments.lexers.text.RstLexer.filenames = ['*.rst', '*.rest'] [static]

Definition at line 592 of file text.py.

Definition at line 594 of file text.py.

Definition at line 712 of file text.py.

list MoinMoin.support.pygments.lexers.text.RstLexer.mimetypes = ["text/x-rst", "text/prs.fallenstein.rst"] [static]

Definition at line 593 of file text.py.

string MoinMoin.support.pygments.lexers.text.RstLexer.name = 'reStructuredText' [static]

Definition at line 590 of file text.py.

Definition at line 638 of file text.py.


The documentation for this class was generated from the following file: