Next / Previous / Contents / Shipman's homepage

10.4. class Htmler: State machine for HTML markup

An instance of this class is a small state machine that keeps track of double-quote and underbar characters. Each call to its .convert() method converts one character of an English name into HTML.

Here is the formal interface:

xnomo3.py
# - - - - -   c l a s s   H t m l e r

class Htmler(object):
    '''State machine for HTML markup.

      Exports:
        Htmler():
          [ return a new Htmler instance with quote and italic states
            off ]
        .quotes:
          [ if self is between quotes -> True
            else -> False ]
        .italics:
          [ if self is between underbars -> True
            else -> False ]
        .convert(c, cssClass):
          [ if c is a double-quote ->
              if self.quotes ->
                self.quotes  :=  False
                return a right double-quote
              else ->
                self.quotes  :=  True
                return a left double-quote
            else if c is an underbar ->
              if self.italics ->
                if cssClass is None ->
                  self.italics  :=  False
                  return "</i>"
                else ->
                  self.italics  :=  False
                  return "</span>
              else ->
                if cssClass is None ->
                  self.italics  :=  True
                  return "<i>"
                else ->
                  self.italics  :=  False
                  return "<span class='(cssClass)'>"
            else -> return c ]
    '''