[ANN] PySourceColor 1.9.6 much new code please review

mefjr75_at_hotmail.com
Date: 12/16/04


Date: 16 Dec 2004 13:27:20 -0800

Hello all ,
I have just finished PySourceColor.py ver 1.9.6.
I am near the end of this tool, and would appreciate a little bit of
review.
Please help me find the pesky little bugs that have escaped me.
I had much difficulty getting linenumbers to work properly.
If you see a simpler way to do linenumbers, by all means, please share.

Website: http://bellsouthpwp.net/m/e/mefjr75/
Here is the module docstring to start you off:

"""
#############################################################################
# PySourceColor.py
#############################################################################
# A python source to colorized html/css/xhtml converter.
# Hacked by M.E.Farmer Jr. 2004
# Python license
#############################################################################
# Now supports two types of output markup:
# - HTML markup does not create w3c valid html, but it works on every
# browser i've tried so far.
# (I.E.,Mozilla/Firefox,Opera,Konqueror,wxHTML).
# - CSS markup is w3c validated html 4.01 strict,
# but will not render correctly on all browsers.
# - XHTML markup is w3c validated xhtml 1.0 strict,
# like html 4.01, will not render correctly on all browsers.
#############################################################################
# Features:
# -Three types of markup:
# html (default)
# css/html 4.01 strict
# xhtml 1.0 strict
#
# -Can tokenize and colorize:
# 12 types of strings
# 2 comment types
# numbers
# operators
# brackets
# math operators
# class / name
# def / name
# decorator / name
# keywords
# arguments class/def/decorator
# text
# linenumbers
#
# -Eight colorschemes built-in:
# null
# mono
# dark (default)
# dark2
# lite
# idle
# viewcvs
# pythonwin
#
# -Header and footer
# set to '' for builtin header / footer
# or give path to a file containing the html
# you want added as header and footer
#
# -Linenumbers
# Supports all styles. New token is called LINE.
# Defaults to NAME if not defined
#
# Style options
# -ALL markups support these text styles:
# b = bold
# i = italic
# u = underline
# -CSS and XHTML has limited support for borders:
# HTML markup functions will ignore these.
# Optional: Border color in RGB hex
# Defaults to the text forecolor.
# #rrggbb = border color
# Optional: specify one type only
# - = dashed
# . = dotted
# s = solid
# d = double
# g = groove
# r = ridge
# n = inset
# o = outset
# You can specify multiple sides,
# they will all use the same style.
# Optional: Default is full border.
# v = bottom
# < = left
# > = right
# ^ = top
# NOTE: Specify the styles you want.
# The markups will ignore unsupported styles
# Also note not all browsers can show these options
#
# -All tokens default to NAME if not defined
# so the only absolutely critical ones to define are:
# NAME, ERRORTOKEN, PAGEBACKGROUND
#
#############################################################################
# Example usage:
#############################################################################
# # import
# import PySourceColor as psc
# psc.convert('c:/Python22/PySourceColor.py', colors=psc.idle, show=1)
#----------------------------------------------------------------------------
# # from module import *
# from PySourceColor import *
# convert('c:/Python22/Lib', colors=lite, markup="css", header='')
#----------------------------------------------------------------------------
# # How to use a custom colorscheme, and most of the 'features'
# # Warning this is an *ugly* colorscheme it is just an example
# from PySourceColor import *
# new = {
# ERRORTOKEN: ('bui','#FF8080',''),
# DECORATOR_NAME: ('s','#AACBBC',''),
# DECORATOR: ('n','#333333',''),
# NAME: ('t.<v','#1133AA','#DDFF22'),
# NUMBER: ('','#236676','#FF5555'),
# OPERATOR: ('b','#454567','#BBBB11'),
# MATH_OPERATOR: ('','#935623','#423afb'),
# BRACKETS: ('b','#ac34bf','#6457a5'),
# COMMENT: ('t-#0022FF','#545366','#AABBFF'),
# DOUBLECOMMENT: ('<l#553455','#553455','#FF00FF'),
# CLASS_NAME: ('m^v-','#000000','#FFFFFF'),
# DEF_NAME: ('l=<v','#897845','#000022'),
# KEYWORD: ('.b','#345345','#FFFF22'),
# SINGLEQUOTE: ('mn','#223344','#AADDCC'),
# SINGLEQUOTE_R: ('','#344522',''),
# SINGLEQUOTE_U: ('','#234234',''),
# DOUBLEQUOTE: ('m#0022FF','#334421',''),
# DOUBLEQUOTE_R: ('','#345345',''),
# DOUBLEQUOTE_U: ('','#678673',''),
# TRIPLESINGLEQUOTE: ('tv','#FFFFFF','#000000'),
# TRIPLESINGLEQUOTE_R: ('tbu','#443256','#DDFFDA'),
# TRIPLESINGLEQUOTE_U: ('','#423454','#DDFFDA'),
# TRIPLEDOUBLEQUOTE: ('li#236fd3b<>','#000000','#FFFFFF'),
# TRIPLEDOUBLEQUOTE_R: ('tub','#000000','#FFFFFF'),
# TRIPLEDOUBLEQUOTE_U: ('-', '#CCAABB','#FFFAFF'),
# LINE: ('ib-','#ff66aa','#7733FF'),
# PAGEBACKGROUND: '#FFFAAA',
# }
# if __name__ == '__main__':
# import sys
# convert(sys.argv[1], './css.html',colors=new,
# markup='css', show=1, linenumbers=1)
# convert(sys.argv[1], './html.html',colors=new,
# markup='html', show=1, linenumbers=1)
#############################################################################
"""
More details in the code.
And for all the commandline junkies there is a commandline interface
that covers every option.
website: http://bellsouthpwp.net/m/e/mefjr75/
thank you for your time,
    M.E.Farmer



Relevant Pages

  • Re: Inconsistent results - why?
    ... Your HTML is 'tag soup', that is, the browser has not been given a DOCTYPE so it must guess how to interpret the markup. ... It also encounters a variety of invalid attributes and markup, so it will use 'quirksmode', which is used whenever the browser is utterly confused as to what the markup is supposed to do and does its best to display something. ... Because your markup is so full of errors that whatever various browsers may make of it is likely different. ... Learn more about HTML and CSS, ask such questions in a relevant new group. ...
    (comp.lang.javascript)
  • Re: Add-in to paste html in FP needed!
    ... | To save yourself some clicking, add the "Insert HTML Markup" button to your ... I usually use notepad anyway. ... | Jack Brewster - Microsoft FrontPage MVP ...
    (microsoft.public.frontpage.addins)
  • Re: How important is validation?
    ... you should design to the HTML ... browsers is a goal in itself. ... For old browsers, I only check my documents so that the content will remain accessible, viewable and links are functional in user agents without CSS support and without javascript support. ... It is known that 98% of all webpages out there on the web fail markup validation testing. ...
    (comp.infosystems.www.authoring.html)
  • Re: Deleting effect like icon-recycle bin
    ... > For HTML source code the appropriate parser is called 'soap parser'. ... The appropriate parser für HTML is an SGML parser as that is an SGML ... > It means that is it will skip all not known elements of markup'. ... > and furthermore it is valid under XHTML. ...
    (comp.lang.javascript)
  • Re: Specify Size on Pictures
    ... Are you checking HTML View to see it the value is in the code, instead of just looking at the image ... FrontPage Resources, WebCircle, MS KB Quick Links, etc. ... > before this download is completed. ... > To specify the image size in FP2000, I check the box at Picture Properties ...
    (microsoft.public.frontpage.client)

Loading