示例#1
0
 def _create_stylesheet(self):
     t2c = self.ttype2class = {Token: ''}
     c2s = self.class2style = {}
     cp = self.classprefix
     for ttype, ndef in self.style:
         name = cp + _get_ttype_class(ttype)
         style = ''
         if ndef['color']:
             style += 'color: #%s; ' % ndef['color']
             style += 'text-fill-color:transparent; '
             style += '-webkit-text-fill-color:transparent; '
             style += '-moz-text-fill-color:transparent; '
             style += 'text-shadow: #%s %s; ' % (ndef['color'], SHADOW)
             style += 'text-stroke: #%s 1px; ' % ndef['color']
             style += '-webkit-text-stroke: #%s 1px; ' % ndef['color']
             style += '-moz-text-stroke: #%s 1px; ' % ndef['color']
         if ndef['bold']:
             style += 'font-weight: bold; '
         if ndef['italic']:
             style += 'font-style: italic; '
         if ndef['underline']:
             style += 'text-decoration: underline; '
         if ndef['bgcolor']:
             style += 'background-color: #%s; ' % ndef['bgcolor']
         if ndef['border']:
             style += 'border: 1px solid #%s; ' % ndef['border']
         if style:
             t2c[ttype] = name
             # save len(ttype) to enable ordering the styles by
             # hierarchy (necessary for CSS cascading rules!)
             c2s[name] = (style[:-2], ttype, len(ttype))
示例#2
0
 def _create_stylesheet(self):
     t2c = self.ttype2class = {Token: ''}
     c2s = self.class2style = {}
     cp = self.classprefix
     for ttype, ndef in self.style:
         name = cp + _get_ttype_class(ttype)
         style = ''
         if ndef['color']:
             style += 'color: #%s; '%ndef['color']
             style += 'text-fill-color:transparent; '
             style += '-webkit-text-fill-color:transparent; '
             style += '-moz-text-fill-color:transparent; '
             style += 'text-shadow: #%s %s; '%(ndef['color'], SHADOW)
             style += 'text-stroke: #%s 1px; '%ndef['color']
             style += '-webkit-text-stroke: #%s 1px; '%ndef['color']
             style += '-moz-text-stroke: #%s 1px; '%ndef['color']
         if ndef['bold']:
             style += 'font-weight: bold; '
         if ndef['italic']:
             style += 'font-style: italic; '
         if ndef['underline']:
             style += 'text-decoration: underline; '
         if ndef['bgcolor']:
             style += 'background-color: #%s; ' % ndef['bgcolor']
         if ndef['border']:
             style += 'border: 1px solid #%s; ' % ndef['border']
         if style:
             t2c[ttype] = name
             # save len(ttype) to enable ordering the styles by
             # hierarchy (necessary for CSS cascading rules!)
             c2s[name] = (style[:-2], ttype, len(ttype))
示例#3
0
 def make_nodes():
     yield nodes.inline(left_space, left_space)
     for ttype, text in tokens:
         yield nodes.inline(text, text, classes=[
             _get_ttype_class(ttype)
         ])
     yield nodes.inline(right_space, right_space)
    def __iter__(self):
        """parse code string and yield "clasified" tokens
        """
        try:
            tokens = self.lex()
        except IOError:
            yield ('', self.code)
            return

        for ttype, value in self.join(tokens):
            yield (_get_ttype_class(ttype), value)
    def __iter__(self):
        """parse code string and yield "clasified" tokens
        """
        try:
            tokens = self.lex()
        except IOError:
            yield ('', self.code)
            return

        for ttype, value in self.join(tokens):
            yield (_get_ttype_class(ttype), value)
示例#6
0
 def __iter__(self):
     """Parse self.code and yield "classified" tokens
     """
     codestring = u'\n'.join(self.code)
     if self.lexer is None:
         yield [('', codestring)]
         return
     tokens = pygments.lex(codestring, self.lexer)
     for ttype, value in self.merge(tokens):
         # yield (ttype, value)  # token type objects
         yield (_get_ttype_class(ttype), value)  # short name strings
 def __iter__(self):
     """Parse self.code and yield "classified" tokens
     """
     codestring = u"\n".join(self.code)
     if self.lexer is None:
         yield [("", codestring)]
         return
     tokens = pygments.lex(codestring, self.lexer)
     for ttype, value in self.merge(tokens):
         # yield (ttype, value)  # token type objects
         yield (_get_ttype_class(ttype), value)  # short name strings
示例#8
0
    def __iter__(self):
        """parse code string and yield "clasified" tokens"""
        try:
            tokens = self.lex()
        except IOError:
            log.info("Pygments lexer not found, using fallback")
            # TODO: write message to INFO
            yield ('', self.code)
            return

        for ttype, value in self.join(tokens):
            yield (_get_ttype_class(ttype), value)
示例#9
0
    def __iter__(self):
        """parse code string and yield "clasified" tokens
        """
        try:
            tokens = self.lex()
        except IOError:
            print "INFO: Pygments lexer not found, using fallback"
            # TODO: write message to INFO 
            yield ('', self.code)
            return

        for ttype, value in self.join(tokens):
            yield (_get_ttype_class(ttype), value)
示例#10
0
 def __iter__(self):
     """Parse self.code and yield "classified" tokens.
     """
     if self.lexer is None:
         yield ([], self.code)
         return
     tokens = pygments.lex(self.code, self.lexer)
     for tokentype, value in self.merge(tokens):
         if self.tokennames == 'long': # long CSS class args
             classes = str(tokentype).lower().split('.')
         else: # short CSS class args
             classes = [_get_ttype_class(tokentype)]
         classes = [cls for cls in classes if cls not in unstyled_tokens]
         yield (classes, value)
示例#11
0
 def __iter__(self):
     """Parse self.code and yield "classified" tokens.
     """
     if self.lexer is None:
         yield ([], self.code)
         return
     tokens = pygments.lex(self.code, self.lexer)
     for tokentype, value in self.merge(tokens):
         if self.tokennames == 'long':  # long CSS class args
             classes = str(tokentype).lower().split('.')
         else:  # short CSS class args
             classes = [_get_ttype_class(tokentype)]
         classes = [cls for cls in classes if cls not in unstyled_tokens]
         yield (classes, value)