Beispiel #1
0
    def change_text(widget):
        html = markup.convert(widget.get_text(widget.get_start_iter(),
                              widget.get_end_iter()), 'xhtml',
                              append_whitespace=True)

        html_editor.load_html(html)
        html_editor.highlight(search_text)
Beispiel #2
0
    def get_export_string(self, format):
        if self.export_all_days:
            export_days = self.journal.days
        else:
            start, end = sorted([self.start_date, self.end_date])
            export_days = self.journal.get_days_in_date_range((start, end))

        selected_categories = self.exported_categories
        logging.debug('Selected Categories for Export: %s' % selected_categories)
        export_text = self.is_text_exported

        markup_strings_for_each_day = []
        for day in export_days:
            default_export_date_format = '%A, %x'
            # probably no one needs to configure this as i18n already exists
            #date_format = self.journal.config.read('exportDateFormat',
            #                                       default_export_date_format)
            date_format = default_export_date_format
            date_string = dates.format_date(date_format, day.date)
            day_markup = markup.get_markup_for_day(day, with_text=export_text,
                                            categories=selected_categories,
                                            date=date_string)
            markup_strings_for_each_day.append(day_markup)

        markup_string = ''.join(markup_strings_for_each_day)

        options = {'toc': 0}

        return markup.convert(markup_string, format, options=options)
Beispiel #3
0
 def on_help_menu_item_activate(self, widget):
     temp_dir = self.journal.dirs.temp_dir
     utils.write_file(info.help_text, os.path.join(temp_dir, 'source.txt'))
     headers = [_('RedNotebook Documentation'), info.version, '']
     options = {'toc': 1,}
     html = markup.convert(info.help_text, 'xhtml', headers, options)
     utils.show_html_in_browser(html, os.path.join(temp_dir, 'help.html'))
    def change_text(widget):
        html = markup.convert(
            widget.get_text(widget.get_start_iter(), widget.get_end_iter()),
            'xhtml', '/tmp')

        html_editor.load_html(html)
        html_editor.highlight(search_text)
Beispiel #5
0
    def change_text(widget):
        html = markup.convert(widget.get_text(widget.get_start_iter(),
                                              widget.get_end_iter()),
                              'xhtml',
                              append_whitespace=True)

        html_editor.load_html(html)
        html_editor.highlight(search_text)
Beispiel #6
0
 def convert(self, text, target, headers=None, options=None):
     options = options or {}
     options['font'] = self.config.read('previewFont')
     return markup.convert(text,
                           target,
                           self.dirs.data_dir,
                           headers=headers,
                           options=options)
def test_images_latex():
    vals = [('[""/image"".png?50]', '\includegraphics[width=50px]{"/image".png}'),
            ('[""/image"".jpg]', '\includegraphics{"/image".jpg}'),
            ('[""file:///image"".png?10]', '\includegraphics[width=10px]{"/image".png}'),
            ('[""file:///image"".jpg]', '\includegraphics{"/image".jpg}'),
           ]
    for markup, expected in vals:
        latex = convert(markup, 'tex', '/tmp')
        assert expected in latex
Beispiel #8
0
def test_images_latex():
    vals = [
        ('[""/image"".png?50]', '\includegraphics[width=50px]{"/image".png}'),
        ('[""/image"".jpg]', '\includegraphics{"/image".jpg}'),
        ('[""file:///image"".png?10]', '\includegraphics[width=10px]{"/image".png}'),
        ('[""file:///image"".jpg]', '\includegraphics{"/image".jpg}'),
    ]
    for markup, expected in vals:
        latex = convert(markup, 'tex', '/tmp')
        assert expected in latex
Beispiel #9
0
def test_images():
    vals = [
        ('[""/image"".png?50]', '<img align="middle" width="50" src="/image.png" border="0" alt=""/>'),
        ('[""/image"".jpg]', '<img align="middle" src="/image.jpg" border="0" alt=""/>'),
        ('[""file:///image"".png?10]', '<img align="middle" width="10" src="file:///image.png" border="0" alt=""/>'),
        ('[""file:///image"".jpg]', '<img align="middle" ' 'src="file:///image.jpg" border="0" ' 'alt=""/>'),
    ]
    for markup, expected in vals:
        html = convert(markup, "xhtml", "/tmp")
        location = re.search(r"(<img.*?>)", html).group(1)
        assert location == expected
Beispiel #10
0
 def convert(self, text, target, headers=None, options=None, use_gtk_theme=False):
     options = options or {}
     options["font"] = self.config.read("previewFont")
     if use_gtk_theme:
         bgcolor, fgcolor = utils.get_gtk_colors(
             self.frame.day_text_field.day_text_view
         )
         options["bgcolor"] = bgcolor
         options["fgcolor"] = fgcolor
     return markup.convert(
         text, target, self.dirs.data_dir, headers=headers, options=options
     )
Beispiel #11
0
def write_documentation(dir):
    '''
    Write the documenation as html to a directory
    Include the original markup as "source.txt"
    '''
    from rednotebook.util import utils
    from rednotebook.util import markup

    utils.write_file(help_text, os.path.join(dir, 'source.txt'))
    headers = [_('RedNotebook Documentation'), version, '']
    options = {'toc': 1,}
    html = markup.convert(help_text, 'xhtml', headers, options)
    utils.write_file(html, os.path.join(dir, 'help.html'))
Beispiel #12
0
def write_documentation(dir):
    """
    Write the documenation as html to a directory
    Include the original markup as "source.txt"
    """
    from rednotebook.util import filesystem
    from rednotebook.util import markup

    filesystem.write_file(os.path.join(dir, "source.txt"), help_text)
    headers = [_("RedNotebook Documentation"), version, ""]
    options = {"toc": 1}
    html = markup.convert(help_text, "xhtml", headers, options)
    filesystem.write_file(os.path.join(dir, "help.html"), html)
Beispiel #13
0
def write_documentation(dir):
    '''
    Write the documenation as html to a directory
    Include the original markup as "source.txt"
    '''
    from rednotebook.util import filesystem
    from rednotebook.util import markup

    filesystem.write_file(os.path.join(dir, 'source.txt'), help_text)
    headers = [_('RedNotebook Documentation'), version, '']
    options = {
        'toc': 1,
    }
    html = markup.convert(help_text, 'xhtml', headers, options)
    filesystem.write_file(os.path.join(dir, 'help.html'), html)
Beispiel #14
0
def test_images():
    vals = [
        ('[""/image"".png?50]',
         '<img align="middle" width="50" src="/image.png" border="0" alt=""/>'),
        ('[""/image"".jpg]',
         '<img align="middle" src="/image.jpg" border="0" alt=""/>'),
        ('[""file:///image"".png?10]',
         '<img align="middle" width="10" src="file:///image.png" border="0" alt=""/>'),
        ('[""file:///image"".jpg]', '<img align="middle" '
                                    'src="file:///image.jpg" border="0" '
                                    'alt=""/>'),
    ]
    for markup, expected in vals:
        html = convert(markup, 'xhtml', '/tmp')
        location = re.search(r'(<img.*?>)', html).group(1)
        assert location == expected
Beispiel #15
0
    def get_export_string(self, format):
        if self.export_selected_text and self.selected_text:
            markup_string = self.selected_text
        else:
            if self.export_all_days:
                export_days = self.journal.days
            else:
                export_days = self.journal.get_days_in_date_range(*self.page2.get_date_range())

            selected_categories = self.exported_categories
            logging.debug('Selected Categories for Inclusion: %s' % selected_categories)

            # Save selected date format
            date_format = self.page3.date_format.get_value()
            self.journal.config['exportDateFormat'] = date_format

            markup_strings_for_each_day = []
            for day in export_days:
                include_day = True
                if self.is_filtered:
                    include_day = False
                    catagory_pairs = day.get_category_content_pairs()
                    for category in selected_categories:
                        if category in catagory_pairs:
                            include_day = True
                if include_day:
                    date_string = dates.format_date(date_format, day.date)
                    day_markup = markup.get_markup_for_day(day, with_text=self.page3.is_text_included(),
                                                           with_tags=self.page3.is_tags_included(),
                                                           categories=selected_categories,
                                                           date=date_string)
                    markup_strings_for_each_day.append(day_markup)

            markup_string = ''.join(markup_strings_for_each_day)

        return markup.convert(markup_string, format, self.journal.dirs.data_dir,
                              options={'toc': 0})
Beispiel #16
0
    def get_export_string(self, format):
        if self.export_all_days:
            export_days = self.journal.days
        else:
            export_days = self.journal.get_days_in_date_range(*self.page2.get_date_range())

        selected_categories = self.exported_categories
        logging.debug('Selected Categories for Export: %s' % selected_categories)
        export_text = self.is_text_exported

        markup_strings_for_each_day = []
        for day in export_days:
            # Save selected date format
            date_format = self.page3.date_format.get_value()
            self.journal.config['exportDateFormat'] = date_format
            date_string = dates.format_date(date_format, day.date)
            day_markup = markup.get_markup_for_day(day, with_text=export_text,
                                            categories=selected_categories,
                                            date=date_string)
            markup_strings_for_each_day.append(day_markup)

        markup_string = ''.join(markup_strings_for_each_day)

        return markup.convert(markup_string, format, options={'toc': 0})
Beispiel #17
0
 def process(markup):
     html_document = convert(markup, 'xhtml', tmp_path)
     return html_document.split('\n')
        instance and highlighted, when the html is loaded.

        Trying to highlight text while the page is still being loaded
        does not work.
        '''
        if self.search_text:
            self.highlight(self.search_text)
        else:
            self.webview.set_highlight_text_matches(False)


if __name__ == '__main__':
    logging.getLogger('').setLevel(logging.DEBUG)
    sys.path.insert(0, os.path.abspath("./../../"))
    text = 'PDF export works 1 www.heise.de $\\sum i^2$'
    html = markup.convert(text, 'xhtml', '/tmp')

    win = gtk.Window()
    win.connect("destroy", lambda w: gtk.main_quit())
    win.set_default_size(600, 400)

    vbox = gtk.VBox()

    def test_export():
        pdf_file = '/tmp/export-test.pdf'
        print_pdf(html, pdf_file)
        #os.system("evince " + pdf_file)

    button = gtk.Button("Export")
    button.connect('clicked', lambda button: test_export())
    vbox.pack_start(button, False, False)
Beispiel #19
0
                all_data = element.data + all_data
        return all_data

    def _get_last_occurence_of_tag(self, tag):
        for element in reversed(self.stack):
            if type(element) == Tag and element.name == tag:
                return element

    def _get_last_tag(self):
        for element in reversed(self.stack):
            if type(element) == Tag:
                return element


if __name__ == '__main__':
    parser = T2THtmlParser()

    parser.feed(html)

    print
    text = parser.markup

    print text

    import sys, os
    dir = os.path.join(os.path.dirname(__file__), '../../')
    sys.path.insert(0, dir)
    from rednotebook.util import markup

    print markup.convert(text, 'xhtml')
Beispiel #20
0
        instance and highlighted, when the html is loaded.
        
        Trying to highlight text while the page is still being loaded
        does not work.
        '''
        if self.search_text:
            self.highlight(self.search_text)
        else:
            self.webview.set_highlight_text_matches(False)
    
if __name__ == '__main__':
    logging.get_logger('').set_level(logging.DEBUG)
    sys.path.insert(0, os.path.abspath("./../../"))
    from rednotebook.util import markup
    text = 'PDF export works 1 www.heise.de'
    html = markup.convert(text, 'xhtml')
    
    win = gtk.Window()
    win.connect("destroy", lambda w: gtk.main_quit())
    win.set_default_size(600,400)
    
    vbox = gtk.VBox()
    
    def test_export():
        pdf_file = '/tmp/export-test.pdf'
        print_pdf(html, pdf_file)
        #os.system("evince " + pdf_file)
    
    button = gtk.Button("Export")
    button.connect('clicked', lambda button: test_export())
    vbox.pack_start(button, False, False)
Beispiel #21
0
        Trying to highlight text while the page is still being loaded
        does not work.
        """
        if self.search_text:
            self.highlight(self.search_text)
        else:
            self.webview.set_highlight_text_matches(False)


if __name__ == "__main__":
    logging.get_logger("").set_level(logging.DEBUG)
    sys.path.insert(0, os.path.abspath("./../../"))
    from rednotebook.util import markup

    text = "PDF export works 1 www.heise.de"
    html = markup.convert(text, "xhtml")

    win = gtk.Window()
    win.connect("destroy", lambda w: gtk.main_quit())
    win.set_default_size(600, 400)

    vbox = gtk.VBox()

    def test_export():
        pdf_file = "/tmp/export-test.pdf"
        print_pdf(html, pdf_file)
        # os.system("evince " + pdf_file)

    button = gtk.Button("Export")
    button.connect("clicked", lambda button: test_export())
    vbox.pack_start(button, False, False)
    def change_text(widget):
        html = markup.convert(widget.get_text(widget.get_start_iter(),
                              widget.get_end_iter()), 'xhtml', '/tmp')

        html_editor.load_html(html)
        html_editor.highlight(search_text)
Beispiel #23
0
        Trying to highlight text while the page is still being loaded
        does not work.
        '''
        if self.search_text:
            self.highlight(self.search_text)
        else:
            self.webview.set_highlight_text_matches(False)


if __name__ == '__main__':
    logging.get_logger('').set_level(logging.DEBUG)
    sys.path.insert(0, os.path.abspath("./../../"))
    from rednotebook.util import markup
    text = 'PDF export works 1 www.heise.de'
    html = markup.convert(text, 'xhtml')

    win = gtk.Window()
    win.connect("destroy", lambda w: gtk.main_quit())
    win.set_default_size(600, 400)

    vbox = gtk.VBox()

    def test_export():
        pdf_file = '/tmp/export-test.pdf'
        print_pdf(html, pdf_file)
        #os.system("evince " + pdf_file)

    button = gtk.Button("Export")
    button.connect('clicked', lambda button: test_export())
    vbox.pack_start(button, False, False)
 def convert(self, text, target, headers=None, options=None):
     options = options or {}
     options['font'] = self.config.read('previewFont', 'Ubuntu, sans-serif')
     return markup.convert(text, target, self.dirs.data_dir, headers=headers, options=options)
Beispiel #25
0
                all_data = element.data + all_data
        return all_data

    def _get_last_occurence_of_tag(self, tag):
        for element in reversed(self.stack):
            if type(element) == Tag and element.name == tag:
                return element

    def _get_last_tag(self):
        for element in reversed(self.stack):
            if type(element) == Tag:
                return element


if __name__ == '__main__':
    parser = T2THtmlParser()

    parser.feed(html)

    print
    text = parser.markup

    print text

    import sys, os
    dir = os.path.join(os.path.dirname(__file__), '../../')
    sys.path.insert(0, dir)
    from rednotebook.util import markup

    print markup.convert(text, 'xhtml')
Beispiel #26
0
 def process(markup):
     html_document = convert(markup, "xhtml", tmp_path)
     return html_document.split("\n")
Beispiel #27
0
        instance and highlighted, when the html is loaded.

        Trying to highlight text while the page is still being loaded
        does not work.
        '''
        if self.search_text:
            self.highlight(self.search_text)
        else:
            self.webview.set_highlight_text_matches(False)


if __name__ == '__main__':
    logging.getLogger('').setLevel(logging.DEBUG)
    sys.path.insert(0, os.path.abspath("./../../"))
    text = 'PDF export works 1 www.heise.de $\\sum i^2$'
    html = markup.convert(text, 'xhtml', '/tmp')

    win = gtk.Window()
    win.connect("destroy", lambda w: gtk.main_quit())
    win.set_default_size(600, 400)

    vbox = gtk.VBox()

    def test_export():
        pdf_file = '/tmp/export-test.pdf'
        print_pdf(html, pdf_file)
        #os.system("evince " + pdf_file)

    button = gtk.Button("Export")
    button.connect('clicked', lambda button: test_export())
    vbox.pack_start(button, False, False)