"""\ MySilverCity - A customized version of the SilverCity HTML generators Features: - whitespace and linebreaks are optionally preserved - generated css classes can be modified Usage: To modify the generated css classes: 1. take a look at the ScintillaConstants.py file in your SilverCity distribution (typically in the site-packages directory). Locate the names of the lexical states you want to keep and/or modify. 2. Create at dictionary with the selected names as keys. The keys must be in lowercase and without the SCE_ prefix. As value, set to True if you only want to keep the css class unmodified, or set it to a new name. Example: mypython_css = { 'p_commentline': True, # keep unaltered 'p_number': True, # " 'p_string': True, # " 'p_character':'p_string', # rename to 'p_string' 'p_triple':True, 'p_tripledouble' : 'p_triple', # combine p_triple and p_tripledouble 'p_word': True, } All other classes like p_operator and p_default are ignored 3. Use the customization dictionary as a parameter to the modified HTML generator classes Author: Kjell Magne Fauske """ from SilverCity import Python, XML, CSS def cleanCssClasses(s1, s2): """Return only the css classes we are interested in Input: s1 - original dictionary with token id -> css name mappings s2 - a dictionary where the keys are the css names we are interested in and the values are either True or a new css name Output: Returns a dictionary with new token id -> css name mappings """ stmp = {} for (key, value) in s1.items(): s2val = s2.get(value,False) if s2val: if type(s2val) == str: stmp[key] = s2val else: stmp[key] = value return stmp class HTMLGeneratorMixIn: """Adds extra functionality to the SilverCity.HTMLGenerator class The mixin class modifies the behaviour of the SilverCity.HTMLGenerator class in three ways: - It is possible to specify which css classes that are generated - A css class name can be renamed and multiple css classes can share the same name - No markup is inserted for whitespaces and linefeeds """ def __init__(self, htmlgenerator, mycss_classes = None, pre = True): """Initilize HTML generator Input: htmlgenerator - An inststance of the original html generator mycss_classes - A dictionary used to modify the css classes generated by the original html generators. Default to None. pre - If set to True, whitespace and linebreaks are unaltered. Useful for usage in the
..HTML environment. If set to false, whitespace is replaced by and linefeeds with