Exemplo n.º 1
0
    def get_tokens_unprocessed(self, text):
        hslexer = HaskellLexer(**self.options)

        style = self.options.get('litstyle')
        if style is None:
            style = (text.lstrip()[0:1] in '%\\') and 'latex' or 'bird'

        code = ''
        insertions = []
        if style == 'bird':
            # bird-style
            for match in line_re.finditer(text):
                line = match.group()
                m = bird_re.match(line)
                if m:
                    insertions.append(
                        (len(code), [(0, Comment.Special, m.group(1))]))
                    code += m.group(2)
                else:
                    insertions.append((len(code), [(0, Text, line)]))
        else:
            # latex-style
            from pygments.lexers.text import TexLexer
            lxlexer = TexLexer(**self.options)

            codelines = 0
            latex = ''
            for match in line_re.finditer(text):
                line = match.group()
                if codelines:
                    if line.lstrip().startswith('\\end{code}'):
                        codelines = 0
                        latex += line
                    else:
                        code += line
                elif line.lstrip().startswith('\\begin{code}'):
                    codelines = 1
                    latex += line
                    insertions.append(
                        (len(code),
                         list(lxlexer.get_tokens_unprocessed(latex))))
                    latex = ''
                else:
                    latex += line
            insertions.append(
                (len(code), list(lxlexer.get_tokens_unprocessed(latex))))
        for item in do_insertions(insertions,
                                  hslexer.get_tokens_unprocessed(code)):
            yield item
Exemplo n.º 2
0
    def get_tokens_unprocessed(self, text):
        hslexer = HaskellLexer(**self.options)

        style = self.options.get('litstyle')
        if style is None:
            style = (text.lstrip()[0:1] in '%\\') and 'latex' or 'bird'

        code = ''
        insertions = []
        if style == 'bird':
            # bird-style
            for match in line_re.finditer(text):
                line = match.group()
                m = bird_re.match(line)
                if m:
                    insertions.append((len(code),
                                       [(0, Comment.Special, m.group(1))]))
                    code += m.group(2)
                else:
                    insertions.append((len(code), [(0, Text, line)]))
        else:
            # latex-style
            from pygments.lexers.text import TexLexer
            lxlexer = TexLexer(**self.options)

            codelines = 0
            latex = ''
            for match in line_re.finditer(text):
                line = match.group()
                if codelines:
                    if line.lstrip().startswith('\\end{code}'):
                        codelines = 0
                        latex += line
                    else:
                        code += line
                elif line.lstrip().startswith('\\begin{code}'):
                    codelines = 1
                    latex += line
                    insertions.append((len(code),
                                       list(lxlexer.get_tokens_unprocessed(latex))))
                    latex = ''
                else:
                    latex += line
            insertions.append((len(code),
                               list(lxlexer.get_tokens_unprocessed(latex))))
        for item in do_insertions(insertions, hslexer.get_tokens_unprocessed(code)):
            yield item
    def open_file(self):
        self.current_index = self.ui.comboBox.currentIndex()
        if self.current_index == -1:
            return
        if self.current_index == 0:
            self.ui.previousBtn.setDisabled(True)
        else:
            self.ui.previousBtn.setDisabled(False)

        if self.current_index == len(self.labels) - 1:
            self.ui.nextBtn.setDisabled(True)
        else:
            self.ui.nextBtn.setDisabled(False)

        self.ui.statementWebView.setHtml(
            highlight(self.json_data[self.current_index]['statement'],
                      TexLexer(), HtmlFormatter(full=True, style="native")))
        self.ui.solutionWebView.setHtml(
            highlight(self.json_data[self.current_index]['code'],
                      Python3Lexer(), HtmlFormatter(full=True,
                                                    style="native")))
        self.ui.solutionWebView.page.toHtml(self.callable)