Esempio n. 1
0
 def handle_entityref(self, name):
     # Unescape special chars in code -- pygments will re-escape them
     if self.in_code():
         if name == 'quot':
             self.data.append('"')
         elif name == 'gt':
             self.data.append('>')
         elif name == 'lt':
             self.data.append('<')
         else:
             self.data.append('&%s;' % name)
     else:
         # Default, pass through as-is
         HTMLPassThrough.handle_entityref(self, name)
Esempio n. 2
0
    def handle_endtag(self, tag):
        if self.data:
            # We've ended a <code> tag within <pre>.
            options, hl_lines = {}, []
            # Parts of self.data will have \n in them.
            data = ''.join(self.data)

            lines = data.split('\n')
            if ':::' in self.data[0]:
                firstline, lines = lines[0], lines[1:]
                options = self.parse_code_header(firstline)

            if options.get('highlight'):
                # Highlighted lines within the code example.
                hl_lines = options['highlight'].split(',')

            code = '\n'.join(lines)
            self.emit(self.highlight(code, options.get('lang'), hl_lines))
            self.data = []
        HTMLPassThrough.handle_endtag(self, tag)
Esempio n. 3
0
    def handle_endtag(self, tag):
        if self.data:
            # We've ended a <code> tag within <pre>.
            options, hl_lines = {}, []
            # Parts of self.data will have \n in them.
            data = ''.join(self.data)

            lines = data.split('\n')
            if ':::' in self.data[0]:
                firstline, lines = lines[0], lines[1:]
                options = self.parse_code_header(firstline)

            if options.get('highlight'):
                # Highlighted lines within the code example.
                hl_lines = options['highlight'].split(',')

            code = '\n'.join(lines)
            self.emit(self.highlight(code, options.get('lang'), hl_lines))
            self.data = []
        HTMLPassThrough.handle_endtag(self, tag)
Esempio n. 4
0
    def handle_endtag(self, tag):
        if self.data:
            options, hl_lines = {}, []
            # parts of self.data will have \n in them
            data = ''.join(self.data)

            # TODO: document the format we're parsing in README
            if ':::' in self.data[0]:
                lines = data.split('\n')
                firstline, lines = lines[0], lines[1:]
                options = self.parse_code_header(firstline)
                if options.get('highlight'):
                    # Highlighted lines within the code example
                    hl_lines = options['highlight'].split(',')

                code = '\n'.join(lines)
                self.emit(self.highlight(code, options.get('lang'), hl_lines))
            else:
                self.emit(self.plain(data, hl_lines))
            self.data = []
        HTMLPassThrough.handle_endtag(self, tag)
Esempio n. 5
0
 def reset(self):
     HTMLPassThrough.reset(self)
     self.data = []
Esempio n. 6
0
 def handle_data(self, data):
     if self.in_code():
         self.data.append(data)
     else:
         HTMLPassThrough.handle_data(self, data)