Example #1
0
    def convert2beamer_full(self):
        """
        convert to LaTeX beamer
        @return the text in LaTeX format
        """
        state = w2bstate()
        result = [''] #start with one empty line as line 0
        codebuffer = []
        autotemplatebuffer = []
        autotemplate=[]

        nowikimode = False
        codemode = False
        autotemplatemode = False

        for line in self.lines:
            (line, nowikimode) = self.get_nowikimode(line, nowikimode)
            if nowikimode:
                result.append(line)
            else:
                (line, _codemode) = self.get_codemode(line, codemode)
                if _codemode and not codemode: #code mode was turned on
                    codebuffer = []
                elif not _codemode and codemode: #code mode was turned off
                    expand_code_segment(result, codebuffer, state)
                codemode = _codemode

                if codemode:
                    codebuffer.append(line)
                else:
                    (line, _autotemplatemode) = self.get_autotemplatemode(line, autotemplatemode)
                    if _autotemplatemode and not autotemplatemode: #autotemplate mode was turned on
                        autotemplatebuffer = []
                    elif not _autotemplatemode and autotemplatemode: #autotemplate mode was turned off
                        self.expand_autotemplate_opening(result, autotemplatebuffer, state, autotemplate)
                    autotemplatemode = _autotemplatemode

                    if autotemplatemode:
                        autotemplatebuffer.append(line)
                    else:
                        state.current_line = len(result)
                        result.append(transform(line, state))

        result.append(transform("", state))   # close open environments

        if state.frame_opened:
            result.append(self.get_frame_closing(state))
        if state.autotemplate_opened:
            result.append(self.get_autotemplate_closing())

        #insert defverbs somewhere at the beginning
        expand_code_defverbs(result, state)

        return result
Example #2
0
    def convert2(self,lines, report=False, transform=lambda x, y, z: x):
        """
        convert to LaTeX book
        @param lines a list of lines
        @param report if True, messages are emitted to sys.stderr;
        if it is callable, it is invoked with the same messages
        @param transform a function to transform lines; its profile
        requires 3 parameters: a text to transform, a reference to
        the automatons's state, and a reference to a feedback (?) device;
        it returns the transformed string, and affects its other parameters
        as a side effect
        """
        self.state = w2bstate()
        result = [''] #start with one empty line as line 0
        codebuffer = []

        nowikimode = False
        codemode = False

        for line in lines:
            (line, nowikimode) = wikiParser.get_nowikimode(line, nowikimode)
            if nowikimode:
                result.append(line)
            else:
                (line, _codemode) = wikiParser.get_codemode(line, codemode)
                if _codemode and not codemode: #code mode was turned on
                    codebuffer = []
                elif not _codemode and codemode: #code mode was turned off
                    expand_code_segment(result, codebuffer, self.state)
                codemode = _codemode

                if codemode:
                    codebuffer.append(line)
                else:
                    self.state.current_line = len(result)
                    result.append(transform(line, self.state, report))

        result.append(transform("", self.state, report))   # close open environments

        #insert defverbs somewhere at the beginning
        expand_code_defverbs(result, self.state)
        return result
Example #3
0
    string = transform_tables(string, state, report)
    string = transform_sourceCode(string, state, report)
    string = transform_h4_to_subsubsec(string, state)
    string = transform_h3_to_subsec(string, state)
    string = transform_h2_to_sec(string, state)
    string = transform_h1_to_chap(string, state)

    string = transform_itemenums(string, state)
    string = transform_commentLines(string, state)

    return string

if __name__=="__main__":
    #test for source code snippets
    text="""\
essai de ponctuation : ; ? ! « azert »
<source lang="php" line>
<?php
    $v = "string";    // sample initialization
?>
html text
<?
    echo $v;         // end of php code
?>
&amp;lt;/source&gt;
"""
    import w2bstate
    state=w2bstate.w2bstate()
    for l in text.split("\n"):
        print transform_sourceCode(l, state)