HTML to LaTeX RE pattern and sub

Discussion in 'Python' started by cepl@surfbest.net, Sep 23, 2005.

  1. Guest

    Hi,

    trying to make a small script which would translate wiki file into
    LaTeX and when trying to translate possible HTML elements into LaTeX I
    did this:

    def latexEnvironments(matchobj):
    print >>sys.stderr,str(matchobj.groups())
    inStr = matchobj.group(1)
    translDict = {'dl': ('\\begin{description}','\\end{description}'),
    'ol': ('\\begin{enumerate}','\\end{enumerate}'),
    'ul': ('\\begin{itemize}','\\end{itemize}'),
    'blockquote': ('\\begin{quote}','\\end{quote}'),
    'center': ('\\begin{center}','\\end{center}'),
    'li': ('\\item',''),
    'pre': ('\\begin{ttfamily}','\\end{ttfamily}')}
    if translDict.has_key(inStr):
    retTuple = translDict[inStr]
    else:
    retTuple = ('','')
    if matchobj.group(0) == '/':
    return retTuple[1]
    else:
    return retTuple[0]

    def latexHeadings(matchobj):
    print >>sys.stderr,str(matchobj.groups())
    inStr = matchobj.groups[1]
    translDict = {'h1': '\\section{}',
    'h2': '\\subsection{}',
    'h3': '\\subsubsection{}',
    'h4': '\\subsubsubsection{}',
    'h5': '\\paragraph{}'}
    if translDict.has_key(inStr) and (matchobj.groups[0] != '/'):
    return translDict[inStr]
    else:
    return ''

    def latexEmptyElements(matchobj):
    retString = ""
    print >>sys.stderr,str(matchobj.groups())
    inStr = matchobj.group(0)
    translDict = {'br//': '\\\\',
    'hr': '\\par{}\\hrulefill{}\\par{}'}
    if translDict.has_key(inStr):
    return translDict[inStr]
    else:
    return ''



    [... snip ...]

    # Remove superfluous HTML elements
    reEnvironments =
    re.compile(r'<(/?)(dl|ol|ul|address|blockquote|center|del\
    |ins|div|isindex|noscript|p|pre)>',re.IGNORE)
    reHeadings = re.compile(r'<(/?)(h1|h2|h3|h4|h5|h6)>',re.IGNORE)
    reEmpty = re.compile(r'<(hr|br)\s*/?>',re.IGNORE)
    body = reEnvironments.sub(latexEnvironments,body)
    body = reHeadings.sub(latexHeadings,body)
    body = reEmpty.sub(latexEmptyElements,body)

    The problem is that apparently RE never matches (and no function is
    thus called). Can anybody tell me what's wrong with my REs, please?

    Thanks for any help,

    Matej
    , Sep 23, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ramdas
    Replies:
    0
    Views:
    280
    Ramdas
    Mar 7, 2007
  2. Ben
    Replies:
    2
    Views:
    867
  3. Replies:
    2
    Views:
    363
    Legend
    Oct 17, 2007
  4. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    1,980
    Lawrence D'Oliveiro
    May 20, 2011
  5. Thomas
    Replies:
    0
    Views:
    148
    Thomas
    Nov 2, 2005
Loading...

Share This Page