How to use ansi2html - 10 common examples

To help you get started, we’ve selected a few ansi2html examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ralphbean / ansi2html / ansi2html / style.py View on Github external
Rule('.ansi5', text_decoration='blink'),
        Rule('.ansi6', text_decoration='blink'),
        Rule('.ansi8', visibility='hidden'),
        Rule('.ansi9', text_decoration='line-through'),
        ]

    # set palette
    pal = SCHEME[scheme]
    for _index in range(8):
        css.append(Rule('.ansi3%s' % _index, color=pal[_index]))
        css.append(Rule('.inv3%s' % _index, background_color=pal[_index]))
    for _index in range(8):
        css.append(Rule('.ansi4%s' % _index, background_color=pal[_index]))
        css.append(Rule('.inv4%s' % _index, color=pal[_index]))
    for _index in range(8):
        css.append(Rule('.ansi9%s' % _index, color=intensify(pal[_index], dark_bg)))
        css.append(Rule('.inv9%s' % _index, background_color=intensify(pal[_index], dark_bg)))
    for _index in range(8):
        css.append(Rule('.ansi10%s' % _index, background_color=intensify(pal[_index], dark_bg)))
        css.append(Rule('.inv10%s' % _index, color=intensify(pal[_index], dark_bg)))

    # set palette colors in 256 color encoding
    pal = SCHEME[scheme]
    for _index in range(len(pal)):
        css.append(Rule('.ansi38-%s' % _index, color=pal[_index]))
        css.append(Rule('.inv38-%s' % _index, background_color=pal[_index]))
    for _index in range(len(pal)):
        css.append(Rule('.ansi48-%s' % _index, background_color=pal[_index]))
        css.append(Rule('.inv48-%s' % _index, color=pal[_index]))

    # css.append("/* Define the explicit color codes (obnoxious) */\n\n")
github ralphbean / ansi2html / ansi2html / style.py View on Github external
pal = SCHEME[scheme]
    for _index in range(len(pal)):
        css.append(Rule('.ansi38-%s' % _index, color=pal[_index]))
        css.append(Rule('.inv38-%s' % _index, background_color=pal[_index]))
    for _index in range(len(pal)):
        css.append(Rule('.ansi48-%s' % _index, background_color=pal[_index]))
        css.append(Rule('.inv48-%s' % _index, color=pal[_index]))

    # css.append("/* Define the explicit color codes (obnoxious) */\n\n")

    for green in range(0, 6):
        for red in range(0, 6):
            for blue in range(0, 6):
                css.append(Rule(".ansi38-%s" % index(red, green, blue),
                                color=color(red, green, blue)))
                css.append(Rule(".inv38-%s" % index(red, green, blue),
                                background=color(red, green, blue)))
                css.append(Rule(".ansi48-%s" % index(red, green, blue),
                                background=color(red, green, blue)))
                css.append(Rule(".inv48-%s" % index(red, green, blue),
                                color=color(red, green, blue)))

    for grey in range(0, 24):
        css.append(Rule('.ansi38-%s' % index2(grey), color=level(grey)))
        css.append(Rule('.inv38-%s' % index2(grey), background=level(grey)))
        css.append(Rule('.ansi48-%s' % index2(grey), background=level(grey)))
        css.append(Rule('.inv48-%s' % index2(grey), color=level(grey)))

    return css
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_conversion(self):
        for input_filename, expected_output_filename in (
                ("ansicolor.txt", "ansicolor.html"),
                ("ansicolor_eix.txt", "ansicolor_eix.html"),
                ):
            with open(join(_here, input_filename), "rb") as input:
                test_data = "".join(read_to_unicode(input))

            with open(join(_here, expected_output_filename), "rb") as output:
                expected_data = [e.rstrip('\n') for e in read_to_unicode(output)]

            html = Ansi2HTMLConverter().convert(test_data, ensure_trailing_newline=True).split("\n")
            if html and html[-1] == '':
                html = html[:-1]

            self.assertEqual(
                '\n'.join(html),
                '\n'.join(expected_data))
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_unicode(self):
        """ Ensure that the converter returns unicode(py2)/str(py3) objs. """

        with open(join(_here, "ansicolor.txt"), "rb") as input:
            test_data = "".join(read_to_unicode(input))

        html = Ansi2HTMLConverter().convert(test_data).split("\n")

        for chunk in html:
            assert isinstance(chunk, six.text_type)
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_conversion(self):
        for input_filename, expected_output_filename in (
                ("ansicolor.txt", "ansicolor.html"),
                ("ansicolor_eix.txt", "ansicolor_eix.html"),
                ):
            with open(join(_here, input_filename), "rb") as input:
                test_data = "".join(read_to_unicode(input))

            with open(join(_here, expected_output_filename), "rb") as output:
                expected_data = [e.rstrip('\n') for e in read_to_unicode(output)]

            html = Ansi2HTMLConverter().convert(test_data, ensure_trailing_newline=True).split("\n")
            if html and html[-1] == '':
                html = html[:-1]

            self.assertEqual(
                '\n'.join(html),
                '\n'.join(expected_data))
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_scheme(self):  # covers issue 36, too
        sample = '\x1b[33mYELLOW/BROWN'
        # ansi2html scheme is brown #aa5500
        html = Ansi2HTMLConverter(inline=True).convert(sample, full=False, ensure_trailing_newline=False)
        expected = six.u('<span style="color: #aa5500">YELLOW/BROWN</span>')
        self.assertEqual(expected, html)

        # xterm scheme is yellow #cdcd00
        html = Ansi2HTMLConverter(inline=True, scheme='xterm').convert(sample, full=False, ensure_trailing_newline=False)
        expected = six.u('<span style="color: #cdcd00">YELLOW/BROWN</span>')
        self.assertEqual(expected, html)
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_partial(self):
        rainbow = '\x1b[1m\x1b[40m\x1b[31mr\x1b[32ma\x1b[33mi\x1b[34mn\x1b[35mb\x1b[36mo\x1b[37mw\x1b[0m\n'

        html = Ansi2HTMLConverter().convert(rainbow, full=False).strip()
        expected = (six.u('<span class="ansi1"></span>') +
                    six.u('<span class="ansi1 ansi40"></span>') +
                    six.u('<span class="ansi1 ansi31 ansi40">r</span>') +
                    six.u('<span class="ansi1 ansi32 ansi40">a</span>') +
                    six.u('<span class="ansi1 ansi33 ansi40">i</span>') +
                    six.u('<span class="ansi1 ansi34 ansi40">n</span>') +
                    six.u('<span class="ansi1 ansi35 ansi40">b</span>') +
                    six.u('<span class="ansi1 ansi36 ansi40">o</span>') +
                    six.u('<span class="ansi1 ansi37 ansi40">w</span>'))
        self.assertEqual(expected, html)
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_no_markup_lines(self):
        test = "  wat  \n "
        expected = test
        html = Ansi2HTMLConverter().convert(test, full=False)
        self.assertEqual(expected, html)
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_hidden_text(self):
        sample = '\x1b[%dmHIDDEN\x1b[%dmVISIBLE\x1b[0m' % (ANSI_VISIBILITY_OFF, ANSI_VISIBILITY_ON)

        html = Ansi2HTMLConverter(inline=True).convert(sample, full=False)
        expected = six.u('<span style="visibility: hidden">HIDDEN</span>VISIBLE')

        self.assertEqual(expected, html)
github ralphbean / ansi2html / tests / test_ansi2html.py View on Github external
def test_latex_linkify(self):
        ansi = 'http://python.org/'
        target = '\\url{%s}' % ansi
        latex = Ansi2HTMLConverter(latex=True, inline=True, linkify=True).convert(ansi)
        assert(target in latex)