Example #1
0
    def render(self, req, mimetype, content, filename=None, rev=None):
        import SilverCity
        try:
            typelang = types[mimetype]
            lang = typelang[0]
            module = getattr(SilverCity, lang)
            generator = getattr(module, lang + "HTMLGenerator")
            try:
                allprops = typelang[1]
                propset = SilverCity.PropertySet()
                for p in allprops.keys():
                    propset[p] = allprops[p]
            except IndexError:
                pass
        except (KeyError, AttributeError):
            err = "No SilverCity lexer found for mime-type '%s'." % mimetype
            raise Exception, err

        # SilverCity generates extra empty line against some types of
        # the line such as comment or #include with CRLF. So we
        # standardize to LF end-of-line style before call.
        content = CRLF_RE.sub('', content)

        buf = StringIO()
        generator().generate_html(buf, content)

        br_re = re.compile(r'<br\s*/?>$', re.MULTILINE)
        span_default_re = re.compile(r'<span class="p_default">(.*?)</span>',
                                     re.DOTALL)
        html = span_default_re.sub(r'\1', br_re.sub('', buf.getvalue()))

        # SilverCity generates _way_ too many non-breaking spaces...
        # We don't need them anyway, so replace them by normal spaces
        return html.replace('&nbsp;', ' ').splitlines()
Example #2
0
 def __init__(self):
     self._properties = SilverCity.PropertySet()
     self._lexer = SilverCity.find_lexer_module_by_id(
         ScintillaConstants.SCLEX_PYTHON)
     self._keyword_lists = [
         SilverCity.WordList(SilverCity.Keywords.python_keywords)
     ]
Example #3
0
 def __init__(self):
     self._properties = SilverCity.PropertySet()
     self._lexer = SilverCity.find_lexer_module_by_id(
         ScintillaConstants.SCLEX_TCL)
     self._keyword_lists = [
         SilverCity.WordList(' '.join(sorted(keywords + v8_6_keywords)))
     ]
Example #4
0
 def __init__(self):
     self._properties = SilverCity.PropertySet()
     self._lexer = SilverCity.find_lexer_module_by_id(ScintillaConstants.SCLEX_PYTHON)
     self._keyword_lists = [
         SilverCity.WordList(python_keywords),
         SilverCity.WordList(""), # hilighted identifiers
     ]
Example #5
0
 def __init__(self):
     self._properties = SilverCity.PropertySet()
     self._lexer = SilverCity.find_lexer_module_by_id(ScintillaConstants.SCLEX_UDL)
     lexres_path = _urlescape(self._get_lexres_path())
     log.debug("escaped lexres_path: %r", lexres_path)
     self._keyword_lists = [
         SilverCity.WordList(lexres_path),
     ]
Example #6
0
 def __init__(self):
     self._properties = SilverCity.PropertySet()
     self._lexer = SilverCity.find_lexer_module_by_id(
         ScintillaConstants.SCLEX_CPP)
     self._keyword_lists = [
         # Dev Notes: What goes here depends on the C++ lexer
         # implementation.
     ]
Example #7
0
 def __init__(self):
     self._properties = SilverCity.PropertySet()
     self._lexer = SilverCity.find_lexer_module_by_id(ScintillaConstants.SCLEX_CPP)
     self._keyword_lists = [
         SilverCity.WordList(' '.join(sorted(GoLangInfo.reserved_keywords))),
         SilverCity.WordList(' '.join(
                         sorted(GoLangInfo.predeclared_identifiers.
                                union(GoLangInfo.predeclared_functions)))),
     ]
Example #8
0
def display(data, mimetype, filename, rev, env):
    import SilverCity
    from SilverCity import LanguageInfo
    try:
        typelang = type_lang[mimetype]
        lang = typelang[0]
        module = getattr(SilverCity, lang)
        generator = getattr(module, lang + "HTMLGenerator")
        try:
            allprops = typelang[1]
            propset = SilverCity.PropertySet()
            for p in allprops.keys():
                propset[p] = allprops[p]
        except IndexError:
            pass
    except (KeyError, AttributeError):
        err = "No SilverCity lexer found for mime-type '%s'." % mimetype
        raise Exception, err
    io = StringIO.StringIO(data)
    generator().generate_html(io, data)
    env.log.debug("type: %s" % mimetype)
    html = '<div class="code-block">%s</div>\n' % io.getvalue()
    return html