as before this is prototype because pymailgui is oriented toward plain text todaythis parser is intended as temporary workaround until html viewer/editor widget solution is found because of thatthis is at best first cut which has not been polished to any significant extent robustly parsing html in its entirety is task well beyond the scope of this and book when this parser fails to render good plain text (and it will!)users can still view and cut-and-paste the properly formatted text from the web browser this is also preview html parsing is not covered until of this bookso you'll have to take this on faith until we refer back to it in that later unfortunatelythis feature was added to pymailgui late in the book projectand avoiding this forward reference didn' seem to justify omitting the improvement altogether for more details on html parsingstay tuned for (or flip head to in shortthe class here provides handler methods that receive callbacks from an html parseras tags and their content is recognizedwe use this model here to save text we're interested in along the way besides the parser classwe could also use python' html entities module to map more entity types than are hardcoded here--another tool we will meet in despite its limitationsthis example serves as rough guide to help get you startedand any result it produces is certainly an improvement upon the prior edition' display and quoting of raw html example - pp \internet\email\pymailgui\html text py ""###############################################################*verypreliminary html-to-text extractorfor text to be quoted in replies and forwardsand displayed in the main text display component only used when the main text part is html ( no alternative or other text parts to showwe also need to know if this is html or notbut findmaintext already returns the main text' content type this is mostly provided as first cutto help get you started on more complete solution it hasn' been polishedbecause any result is better than displaying raw htmland it' probably better idea to migrate to an html viewer/editor widget in the future anyhow as ispymailgui is still plain-text biased if (reallywhenthis parser fails to render wellusers can instead view and cut-and-paste from the web browser popped up to display the html see for more on html parsing ###############################################################""from html parser import htmlparser python std lib parser (sax-like modelclass parser(htmlparser)def __init__(self)subclass parserdefine callback methods text assumed to be strany encoding ok pymailgui implementation