diff options
71 files changed, 1223 insertions, 129 deletions
@@ -56,7 +56,7 @@ Other contributors, listed alphabetically, are: * Sven Efftinge -- Xtend lexer * Artem Egorkine -- terminal256 formatter * Matthew Fernandez -- CAmkES lexer -* Paweł Fertyk -- GDScript lexer +* Paweł Fertyk -- GDScript lexer, HTML formatter improvements * Michael Ficarra -- CPSA lexer * James H. Fisher -- PostScript lexer * William S. Fulton -- SWIG lexer diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py index c5ae774d..c3100967 100644 --- a/pygments/formatters/html.py +++ b/pygments/formatters/html.py @@ -65,9 +65,6 @@ generated by Pygments <https://pygments.org/> Copyright 2006-2019 by the Pygments team. Licensed under the BSD license, see LICENSE for details. */ -td.linenos { background-color: #f0f0f0; padding-right: 10px; } -span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; } -pre { line-height: 125%%; } %(styledefs)s ''' @@ -208,9 +205,10 @@ class HtmlFormatter(Formatter): `cssfile` exists. `noclasses` - If set to true, token ``<span>`` tags will not use CSS classes, but - inline styles. This is not recommended for larger pieces of code since - it increases output size by quite a bit (default: ``False``). + If set to true, token ``<span>`` tags (as well as line number elements) + will not use CSS classes, but inline styles. This is not recommended + for larger pieces of code since it increases output size by quite a bit + (default: ``False``). `classprefix` Since the token types use relatively short class names, they may clash @@ -438,7 +436,7 @@ class HtmlFormatter(Formatter): self.lineseparator = options.get('lineseparator', u'\n') self.lineanchors = options.get('lineanchors', '') self.linespans = options.get('linespans', '') - self.anchorlinenos = options.get('anchorlinenos', False) + self.anchorlinenos = get_bool_opt(options, 'anchorlinenos', False) self.hl_lines = set() for lineno in get_list_opt(options, 'hl_lines', []): try: @@ -495,6 +493,66 @@ class HtmlFormatter(Formatter): highlighting style. ``arg`` can be a string or list of selectors to insert before the token type classes. """ + style_lines = [] + + style_lines.extend(self.get_linenos_style_defs()) + style_lines.extend(self.get_background_style_defs(arg)) + style_lines.extend(self.get_token_style_defs(arg)) + + return '\n'.join(style_lines) + + def get_token_style_defs(self, arg=None): + prefix = self.get_css_prefix(arg) + + styles = [ + (level, ttype, cls, style) + for cls, (style, ttype, level) in self.class2style.items() + if cls and style + ] + styles.sort() + + lines = [ + '%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:]) + for (level, ttype, cls, style) in styles + ] + + return lines + + def get_background_style_defs(self, arg=None): + prefix = self.get_css_prefix(arg) + bg_color = self.style.background_color + hl_color = self.style.highlight_color + + lines = [] + + if arg and not self.nobackground and bg_color is not None: + text_style = '' + if Text in self.ttype2class: + text_style = ' ' + self.class2style[self.ttype2class[Text]][0] + lines.insert( + 0, '%s{ background: %s;%s }' % ( + prefix(''), bg_color, text_style + ) + ) + if hl_color is not None: + lines.insert( + 0, '%s { background-color: %s }' % (prefix('hll'), hl_color) + ) + + return lines + + def get_linenos_style_defs(self): + lines = [ + 'pre { %s }' % self._pre_style, + 'td.linenos pre { %s }' % self._linenos_style, + 'span.linenos { %s }' % self._linenos_style, + 'td.linenos pre.special { %s }' % self._linenos_special_style, + 'span.linenos.special { %s }' % self._linenos_special_style, + ] + + return lines + + def get_css_prefix(self, arg): if arg is None: arg = ('cssclass' in self.options and '.'+self.cssclass or '') if isinstance(arg, str): @@ -510,23 +568,25 @@ class HtmlFormatter(Formatter): tmp.append((arg and arg + ' ' or '') + cls) return ', '.join(tmp) - styles = [(level, ttype, cls, style) - for cls, (style, ttype, level) in self.class2style.items() - if cls and style] - styles.sort() - lines = ['%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:]) - for (level, ttype, cls, style) in styles] - if arg and not self.nobackground and \ - self.style.background_color is not None: - text_style = '' - if Text in self.ttype2class: - text_style = ' ' + self.class2style[self.ttype2class[Text]][0] - lines.insert(0, '%s { background: %s;%s }' % - (prefix(''), self.style.background_color, text_style)) - if self.style.highlight_color is not None: - lines.insert(0, '%s.hll { background-color: %s }' % - (prefix(''), self.style.highlight_color)) - return '\n'.join(lines) + return prefix + + @property + def _pre_style(self): + return 'line-height: 125%; margin: 0;' + + @property + def _linenos_style(self): + return 'color: %s; background-color: %s; padding: 0 5px 0 5px;' % ( + self.style.line_number_color, + self.style.line_number_background_color + ) + + @property + def _linenos_special_style(self): + return 'color: %s; background-color: %s; padding: 0 5px 0 5px;' % ( + self.style.line_number_special_color, + self.style.line_number_special_background_color + ) def _decodeifneeded(self, value): if isinstance(value, bytes): @@ -592,88 +652,79 @@ class HtmlFormatter(Formatter): la = self.lineanchors aln = self.anchorlinenos nocls = self.noclasses - if sp: - lines = [] - - for i in range(fl, fl+lncount): - if i % st == 0: - if i % sp == 0: - if aln: - lines.append('<a href="#%s-%d" class="special">%*d</a>' % - (la, i, mw, i)) - else: - lines.append('<span class="special">%*d</span>' % (mw, i)) - else: - if aln: - lines.append('<a href="#%s-%d">%*d</a>' % (la, i, mw, i)) - else: - lines.append('%*d' % (mw, i)) + + lines = [] + + for i in range(fl, fl+lncount): + print_line = i % st == 0 + special_line = sp and i % sp == 0 + + if print_line: + line = '%*d' % (mw, i) + if aln: + line = '<a href="#%s-%d">%s</a>' % (la, i, line) + else: + line = ' ' * mw + + if nocls: + if special_line: + style = ' style="%s"' % self._linenos_special_style else: - lines.append('') - ls = '\n'.join(lines) - else: - lines = [] - for i in range(fl, fl+lncount): - if i % st == 0: - if aln: - lines.append('<a href="#%s-%d">%*d</a>' % (la, i, mw, i)) - else: - lines.append('%*d' % (mw, i)) + style = ' style="%s"' % self._linenos_style + else: + if special_line: + style = ' class="special"' else: - lines.append('') - ls = '\n'.join(lines) + style = '' + + line = '<pre%s>%s</pre>' % (style, line) + + lines.append(line) + + ls = '\n'.join(lines) # in case you wonder about the seemingly redundant <div> here: since the # content in the other cell also is wrapped in a div, some browsers in # some configurations seem to mess up the formatting... - if nocls: - yield 0, ('<table class="%stable">' % self.cssclass + - '<tr><td><div class="linenodiv" ' - 'style="background-color: #f0f0f0; padding-right: 10px">' - '<pre style="line-height: 125%">' + - ls + '</pre></div></td><td class="code">') - else: - yield 0, ('<table class="%stable">' % self.cssclass + - '<tr><td class="linenos"><div class="linenodiv"><pre>' + - ls + '</pre></div></td><td class="code">') + yield 0, ( + '<table class="%stable">' % self.cssclass + + '<tr><td class="linenos"><div class="linenodiv">' + + ls + '</div></td><td class="code">' + ) yield 0, dummyoutfile.getvalue() yield 0, '</td></tr></table>' def _wrap_inlinelinenos(self, inner): # need a list of lines since we need the width of a single number :( - lines = list(inner) + inner_lines = list(inner) sp = self.linenospecial st = self.linenostep num = self.linenostart - mw = len(str(len(lines) + num - 1)) + mw = len(str(len(inner_lines) + num - 1)) + nocls = self.noclasses - if self.noclasses: - if sp: - for t, line in lines: - if num % sp == 0: - style = 'background-color: #ffffc0; padding: 0 5px 0 5px' - else: - style = 'background-color: #f0f0f0; padding: 0 5px 0 5px' - yield 1, '<span style="%s">%*s </span>' % ( - style, mw, (num % st and ' ' or num)) + line - num += 1 + for _, inner_line in inner_lines: + print_line = num % st == 0 + special_line = sp and num % sp == 0 + + if print_line: + line = '%*d' % (mw, num) else: - for t, line in lines: - yield 1, ('<span style="background-color: #f0f0f0; ' - 'padding: 0 5px 0 5px">%*s </span>' % ( - mw, (num % st and ' ' or num)) + line) - num += 1 - elif sp: - for t, line in lines: - yield 1, '<span class="lineno%s">%*s </span>' % ( - num % sp == 0 and ' special' or '', mw, - (num % st and ' ' or num)) + line - num += 1 - else: - for t, line in lines: - yield 1, '<span class="lineno">%*s </span>' % ( - mw, (num % st and ' ' or num)) + line - num += 1 + line = ' ' * mw + + if nocls: + if special_line: + style = ' style="%s"' % self._linenos_special_style + else: + style = ' style="%s"' % self._linenos_style + else: + if special_line: + style = ' class="linenos special"' + else: + style = ' class="linenos"' + + yield 1, '<span%s>%s</span>' % (style, line) + inner_line + num += 1 def _wrap_lineanchors(self, inner): s = self.lineanchors @@ -716,7 +767,7 @@ class HtmlFormatter(Formatter): if self.prestyles: style.append(self.prestyles) if self.noclasses: - style.append('line-height: 125%') + style.append(self._pre_style) style = '; '.join(style) if self.filename: diff --git a/pygments/style.py b/pygments/style.py index 8f50feb1..b2bc9879 100644 --- a/pygments/style.py +++ b/pygments/style.py @@ -176,5 +176,17 @@ class Style(metaclass=StyleMeta): #: highlight background color highlight_color = '#ffffcc' + #: line number font color + line_number_color = '#000000' + + #: line number background color + line_number_background_color = '#f0f0f0' + + #: special line number font color + line_number_special_color = '#000000' + + #: special line number background color + line_number_special_background_color = '#ffffc0' + #: Style definitions for individual token types. styles = {} diff --git a/pygments/styles/solarized.py b/pygments/styles/solarized.py index 7d4b113d..ac94a984 100644 --- a/pygments/styles/solarized.py +++ b/pygments/styles/solarized.py @@ -118,6 +118,8 @@ class SolarizedDarkStyle(Style): styles = make_style(DARK_COLORS) background_color = DARK_COLORS['base03'] highlight_color = DARK_COLORS['base02'] + line_number_color = DARK_COLORS['base01'] + line_number_background_color = DARK_COLORS['base02'] class SolarizedLightStyle(SolarizedDarkStyle): @@ -128,3 +130,5 @@ class SolarizedLightStyle(SolarizedDarkStyle): styles = make_style(LIGHT_COLORS) background_color = LIGHT_COLORS['base03'] highlight_color = LIGHT_COLORS['base02'] + line_number_color = LIGHT_COLORS['base01'] + line_number_background_color = LIGHT_COLORS['base02'] diff --git a/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_0_anchor.html b/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_0_anchor.html new file mode 100644 index 00000000..78b7675e --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_0_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos">1</span><span class="c1"># a</span> + <span class="linenos">2</span><span class="c1"># b</span> + <span class="linenos">3</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_0_noanchor.html b/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_0_noanchor.html new file mode 100644 index 00000000..78b7675e --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_0_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos">1</span><span class="c1"># a</span> + <span class="linenos">2</span><span class="c1"># b</span> + <span class="linenos">3</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_3_anchor.html b/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_3_anchor.html new file mode 100644 index 00000000..a133f7a8 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_3_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos">1</span><span class="c1"># a</span> + <span class="linenos">2</span><span class="c1"># b</span> + <span class="linenos special">3</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_3_noanchor.html b/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_3_noanchor.html new file mode 100644 index 00000000..a133f7a8 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_1_start_1_special_3_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos">1</span><span class="c1"># a</span> + <span class="linenos">2</span><span class="c1"># b</span> + <span class="linenos special">3</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_0_anchor.html b/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_0_anchor.html new file mode 100644 index 00000000..e4000c6e --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_0_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> 8</span><span class="c1"># a</span> + <span class="linenos"> 9</span><span class="c1"># b</span> + <span class="linenos">10</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_0_noanchor.html b/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_0_noanchor.html new file mode 100644 index 00000000..e4000c6e --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_0_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> 8</span><span class="c1"># a</span> + <span class="linenos"> 9</span><span class="c1"># b</span> + <span class="linenos">10</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_3_anchor.html b/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_3_anchor.html new file mode 100644 index 00000000..bcbd693c --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_3_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> 8</span><span class="c1"># a</span> + <span class="linenos special"> 9</span><span class="c1"># b</span> + <span class="linenos">10</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_3_noanchor.html b/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_3_noanchor.html new file mode 100644 index 00000000..bcbd693c --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_1_start_8_special_3_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> 8</span><span class="c1"># a</span> + <span class="linenos special"> 9</span><span class="c1"># b</span> + <span class="linenos">10</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_0_anchor.html b/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_0_anchor.html new file mode 100644 index 00000000..56275271 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_0_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> </span><span class="c1"># a</span> + <span class="linenos">2</span><span class="c1"># b</span> + <span class="linenos"> </span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_0_noanchor.html b/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_0_noanchor.html new file mode 100644 index 00000000..56275271 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_0_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> </span><span class="c1"># a</span> + <span class="linenos">2</span><span class="c1"># b</span> + <span class="linenos"> </span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_3_anchor.html b/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_3_anchor.html new file mode 100644 index 00000000..9f10418b --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_3_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> </span><span class="c1"># a</span> + <span class="linenos">2</span><span class="c1"># b</span> + <span class="linenos special"> </span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_3_noanchor.html b/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_3_noanchor.html new file mode 100644 index 00000000..9f10418b --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_2_start_1_special_3_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> </span><span class="c1"># a</span> + <span class="linenos">2</span><span class="c1"># b</span> + <span class="linenos special"> </span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_0_anchor.html b/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_0_anchor.html new file mode 100644 index 00000000..490d7484 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_0_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> 8</span><span class="c1"># a</span> + <span class="linenos"> </span><span class="c1"># b</span> + <span class="linenos">10</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_0_noanchor.html b/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_0_noanchor.html new file mode 100644 index 00000000..490d7484 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_0_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> 8</span><span class="c1"># a</span> + <span class="linenos"> </span><span class="c1"># b</span> + <span class="linenos">10</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_3_anchor.html b/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_3_anchor.html new file mode 100644 index 00000000..d6b50fbb --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_3_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> 8</span><span class="c1"># a</span> + <span class="linenos special"> </span><span class="c1"># b</span> + <span class="linenos">10</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_3_noanchor.html b/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_3_noanchor.html new file mode 100644 index 00000000..d6b50fbb --- /dev/null +++ b/tests/html_linenos_expected_output/inline_cls_step_2_start_8_special_3_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight"> + <pre> + <span></span> + <span class="linenos"> 8</span><span class="c1"># a</span> + <span class="linenos special"> </span><span class="c1"># b</span> + <span class="linenos">10</span><span class="c1"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_0_anchor.html b/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_0_anchor.html new file mode 100644 index 00000000..6bbdf29c --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_0_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">1</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">3</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_0_noanchor.html b/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_0_noanchor.html new file mode 100644 index 00000000..6bbdf29c --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_0_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">1</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">3</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_3_anchor.html b/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_3_anchor.html new file mode 100644 index 00000000..33b6330f --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_3_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">1</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;">3</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_3_noanchor.html b/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_3_noanchor.html new file mode 100644 index 00000000..33b6330f --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_1_start_1_special_3_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">1</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;">3</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_0_anchor.html b/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_0_anchor.html new file mode 100644 index 00000000..2692b73d --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_0_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 9</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_0_noanchor.html b/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_0_noanchor.html new file mode 100644 index 00000000..2692b73d --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_0_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 9</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_3_anchor.html b/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_3_anchor.html new file mode 100644 index 00000000..c1a67b5c --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_3_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> 9</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_3_noanchor.html b/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_3_noanchor.html new file mode 100644 index 00000000..c1a67b5c --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_1_start_8_special_3_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> 9</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_0_anchor.html b/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_0_anchor.html new file mode 100644 index 00000000..1a9e833a --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_0_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_0_noanchor.html b/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_0_noanchor.html new file mode 100644 index 00000000..1a9e833a --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_0_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_3_anchor.html b/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_3_anchor.html new file mode 100644 index 00000000..cd89d205 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_3_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_3_noanchor.html b/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_3_noanchor.html new file mode 100644 index 00000000..cd89d205 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_2_start_1_special_3_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_0_anchor.html b/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_0_anchor.html new file mode 100644 index 00000000..8f078e42 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_0_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_0_noanchor.html b/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_0_noanchor.html new file mode 100644 index 00000000..8f078e42 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_0_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_3_anchor.html b/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_3_anchor.html new file mode 100644 index 00000000..7d0ecdd8 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_3_anchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_3_noanchor.html b/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_3_noanchor.html new file mode 100644 index 00000000..7d0ecdd8 --- /dev/null +++ b/tests/html_linenos_expected_output/inline_nocls_step_2_start_8_special_3_noanchor.html @@ -0,0 +1,8 @@ +<div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</span><span style="color: #408080; font-style: italic"># a</span> + <span style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> </span><span style="color: #408080; font-style: italic"># b</span> + <span style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</span><span style="color: #408080; font-style: italic"># c</span> + </pre> +</div> diff --git a/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_0_anchor.html b/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_0_anchor.html new file mode 100644 index 00000000..a34780d8 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_0_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre><a href="#-1">1</a></pre> + <pre><a href="#-2">2</a></pre> + <pre><a href="#-3">3</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_0_noanchor.html b/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_0_noanchor.html new file mode 100644 index 00000000..04037b2c --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_0_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre>1</pre> + <pre>2</pre> + <pre>3</pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_3_anchor.html b/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_3_anchor.html new file mode 100644 index 00000000..c6f89066 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_3_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre><a href="#-1">1</a></pre> + <pre><a href="#-2">2</a></pre> + <pre class="special"><a href="#-3">3</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_3_noanchor.html b/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_3_noanchor.html new file mode 100644 index 00000000..464b1b32 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_1_start_1_special_3_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre>1</pre> + <pre>2</pre> + <pre class="special">3</pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_0_anchor.html b/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_0_anchor.html new file mode 100644 index 00000000..0eacbbaf --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_0_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre><a href="#-8"> 8</a></pre> + <pre><a href="#-9"> 9</a></pre> + <pre><a href="#-10">10</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_0_noanchor.html b/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_0_noanchor.html new file mode 100644 index 00000000..c274351c --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_0_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre> 8</pre> + <pre> 9</pre> + <pre>10</pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_3_anchor.html b/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_3_anchor.html new file mode 100644 index 00000000..95521c15 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_3_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre><a href="#-8"> 8</a></pre> + <pre class="special"><a href="#-9"> 9</a></pre> + <pre><a href="#-10">10</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_3_noanchor.html b/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_3_noanchor.html new file mode 100644 index 00000000..07601811 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_1_start_8_special_3_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre> 8</pre> + <pre class="special"> 9</pre> + <pre>10</pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_0_anchor.html b/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_0_anchor.html new file mode 100644 index 00000000..566d4bcc --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_0_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre> </pre> + <pre><a href="#-2">2</a></pre> + <pre> </pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_0_noanchor.html b/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_0_noanchor.html new file mode 100644 index 00000000..b19d9af6 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_0_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre> </pre> + <pre>2</pre> + <pre> </pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_3_anchor.html b/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_3_anchor.html new file mode 100644 index 00000000..921c13c9 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_3_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre> </pre> + <pre><a href="#-2">2</a></pre> + <pre class="special"> </pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_3_noanchor.html b/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_3_noanchor.html new file mode 100644 index 00000000..dd177c14 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_2_start_1_special_3_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre> </pre> + <pre>2</pre> + <pre class="special"> </pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_0_anchor.html b/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_0_anchor.html new file mode 100644 index 00000000..a3091766 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_0_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre><a href="#-8"> 8</a></pre> + <pre> </pre> + <pre><a href="#-10">10</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_0_noanchor.html b/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_0_noanchor.html new file mode 100644 index 00000000..cfc968ff --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_0_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre> 8</pre> + <pre> </pre> + <pre>10</pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_3_anchor.html b/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_3_anchor.html new file mode 100644 index 00000000..1b30e6d7 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_3_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre><a href="#-8"> 8</a></pre> + <pre class="special"> </pre> + <pre><a href="#-10">10</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_3_noanchor.html b/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_3_noanchor.html new file mode 100644 index 00000000..2a5ebde0 --- /dev/null +++ b/tests/html_linenos_expected_output/table_cls_step_2_start_8_special_3_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre> 8</pre> + <pre class="special"> </pre> + <pre>10</pre> + </div> + </td> + <td class="code"> + <div class="highlight"> + <pre> + <span></span> + <span class="c1"># a</span> + <span class="c1"># b</span> + <span class="c1"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_0_anchor.html b/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_0_anchor.html new file mode 100644 index 00000000..86ce85ea --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_0_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-1">1</a></pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-2">2</a></pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-3">3</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_0_noanchor.html b/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_0_noanchor.html new file mode 100644 index 00000000..c32f2745 --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_0_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">1</pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">3</pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_3_anchor.html b/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_3_anchor.html new file mode 100644 index 00000000..1d17cad9 --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_3_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-1">1</a></pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-2">2</a></pre> + <pre style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"><a href="#-3">3</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_3_noanchor.html b/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_3_noanchor.html new file mode 100644 index 00000000..7b3bc29c --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_1_start_1_special_3_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">1</pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</pre> + <pre style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;">3</pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_0_anchor.html b/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_0_anchor.html new file mode 100644 index 00000000..c61cb280 --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_0_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-8"> 8</a></pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-9"> 9</a></pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-10">10</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_0_noanchor.html b/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_0_noanchor.html new file mode 100644 index 00000000..af07ebb1 --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_0_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 9</pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_3_anchor.html b/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_3_anchor.html new file mode 100644 index 00000000..122283b6 --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_3_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-8"> 8</a></pre> + <pre style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"><a href="#-9"> 9</a></pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-10">10</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_3_noanchor.html b/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_3_noanchor.html new file mode 100644 index 00000000..f50cdcdd --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_1_start_8_special_3_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</pre> + <pre style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> 9</pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_0_anchor.html b/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_0_anchor.html new file mode 100644 index 00000000..6ed8c005 --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_0_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-2">2</a></pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_0_noanchor.html b/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_0_noanchor.html new file mode 100644 index 00000000..dba1249b --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_0_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_3_anchor.html b/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_3_anchor.html new file mode 100644 index 00000000..69bf7428 --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_3_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-2">2</a></pre> + <pre style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> </pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_3_noanchor.html b/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_3_noanchor.html new file mode 100644 index 00000000..87660afb --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_2_start_1_special_3_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">2</pre> + <pre style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> </pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_0_anchor.html b/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_0_anchor.html new file mode 100644 index 00000000..ac7570f3 --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_0_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-8"> 8</a></pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-10">10</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_0_noanchor.html b/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_0_noanchor.html new file mode 100644 index 00000000..035aa795 --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_0_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> </pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_3_anchor.html b/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_3_anchor.html new file mode 100644 index 00000000..0ed43dbd --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_3_anchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-8"> 8</a></pre> + <pre style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> </pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"><a href="#-10">10</a></pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_3_noanchor.html b/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_3_noanchor.html new file mode 100644 index 00000000..13e38705 --- /dev/null +++ b/tests/html_linenos_expected_output/table_nocls_step_2_start_8_special_3_noanchor.html @@ -0,0 +1,21 @@ +<table class="highlighttable"> + <tr> + <td class="linenos"> + <div class="linenodiv"> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;"> 8</pre> + <pre style="color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px;"> </pre> + <pre style="color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px;">10</pre> + </div> + </td> + <td class="code"> + <div class="highlight" style="background: #f8f8f8"> + <pre style="line-height: 125%; margin: 0;"> + <span></span> + <span style="color: #408080; font-style: italic"># a</span> + <span style="color: #408080; font-style: italic"># b</span> + <span style="color: #408080; font-style: italic"># c</span> + </pre> + </div> + </td> + </tr> +</table> diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index b9b07c3c..e11c666d 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -200,8 +200,9 @@ def test_H_opt(): def test_S_opt(): o = check_success('-S', 'default', '-f', 'html', '-O', 'linenos=1') lines = o.splitlines() - for line in lines: - # every line is for a token class + for line in lines[5:]: + # every line is for a token class, except for the first 5 lines, + # which define styles for `pre` and line numbers parts = line.split() assert parts[0].startswith('.') assert parts[1] == '{' diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py index 83b08e1f..75986db5 100644 --- a/tests/test_html_formatter.py +++ b/tests/test_html_formatter.py @@ -11,14 +11,15 @@ import io import os import re import tempfile -from os import path from io import StringIO +from os import path -from pytest import raises +import pytest -from pygments.lexers import PythonLexer from pygments.formatters import HtmlFormatter, NullFormatter from pygments.formatters.html import escape_html +from pygments.lexers import PythonLexer +from pygments.style import Style TESTDIR = path.dirname(path.abspath(__file__)) TESTFILE = path.join(TESTDIR, 'test_html_formatter.py') @@ -94,24 +95,6 @@ def test_all_options(): check(optdict) -def test_linenos(): - optdict = dict(linenos=True) - outfile = StringIO() - fmt = HtmlFormatter(**optdict) - fmt.format(tokensource, outfile) - html = outfile.getvalue() - assert re.search(r"<pre>\s+1\s+2\s+3", html) - - -def test_linenos_with_startnum(): - optdict = dict(linenos=True, linenostart=5) - outfile = StringIO() - fmt = HtmlFormatter(**optdict) - fmt.format(tokensource, outfile) - html = outfile.getvalue() - assert re.search(r"<pre>\s+5\s+6\s+7", html) - - def test_lineanchors(): optdict = dict(lineanchors="foo") outfile = StringIO() @@ -157,19 +140,77 @@ def test_valid_output(): os.unlink(pathname) -def test_get_style_defs(): - fmt = HtmlFormatter() - sd = fmt.get_style_defs() - assert sd.startswith('.') - - fmt = HtmlFormatter(cssclass='foo') - sd = fmt.get_style_defs() - assert sd.startswith('.foo') - sd = fmt.get_style_defs('.bar') - assert sd.startswith('.bar') - sd = fmt.get_style_defs(['.bar', '.baz']) - fl = sd.splitlines()[0] - assert '.bar' in fl and '.baz' in fl +def test_get_style_defs_contains_pre_style(): + style_defs = HtmlFormatter().get_style_defs().splitlines() + assert style_defs[0] == 'pre { line-height: 125%; margin: 0; }' + + +def test_get_style_defs_contains_default_line_numbers_styles(): + style_defs = HtmlFormatter().get_style_defs().splitlines() + + assert style_defs[1] == ( + 'td.linenos pre ' + '{ color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }' + ) + assert style_defs[2] == ( + 'span.linenos ' + '{ color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }' + ) + + +def test_get_style_defs_contains_style_specific_line_numbers_styles(): + class TestStyle(Style): + line_number_color = '#ff0000' + line_number_background_color = '#0000ff' + line_number_special_color = '#00ff00' + line_number_special_background_color = '#ffffff' + + style_defs = HtmlFormatter(style=TestStyle).get_style_defs().splitlines() + + assert style_defs[1] == ( + 'td.linenos pre ' + '{ color: #ff0000; background-color: #0000ff; padding: 0 5px 0 5px; }' + ) + assert style_defs[2] == ( + 'span.linenos ' + '{ color: #ff0000; background-color: #0000ff; padding: 0 5px 0 5px; }' + ) + assert style_defs[3] == ( + 'td.linenos pre.special ' + '{ color: #00ff00; background-color: #ffffff; padding: 0 5px 0 5px; }' + ) + assert style_defs[4] == ( + 'span.linenos.special ' + '{ color: #00ff00; background-color: #ffffff; padding: 0 5px 0 5px; }' + ) + + +@pytest.mark.parametrize( + "formatter_kwargs, style_defs_args, assert_starts_with, assert_contains", + [ + [{}, [], ".", []], + [{"cssclass": "foo"}, [], ".foo .", []], + [{"cssclass": "foo"}, [".bar"], ".bar .", []], + [{"cssclass": "foo"}, [[".bar", ".baz"]], ".ba", [".bar .", ".baz ."]], + ] +) +def test_get_token_style_defs_uses_css_prefix( + formatter_kwargs, style_defs_args, assert_starts_with, assert_contains +): + formatter = HtmlFormatter(**formatter_kwargs) + + for line in formatter.get_token_style_defs(*style_defs_args): + assert line.startswith(assert_starts_with) + for s in assert_contains: + assert s in line + + +def test_get_background_style_defs_uses_multiple_css_prefixes(): + formatter = HtmlFormatter() + + lines = formatter.get_background_style_defs([".foo", ".bar"]) + assert lines[0].startswith(".foo .hll, .bar .hll {") + assert lines[1].startswith(".foo , .bar {") def test_unicode_options(): @@ -187,7 +228,9 @@ def test_ctags(): import ctags except ImportError: # we can't check without the ctags module, but at least check the exception - assert raises(RuntimeError, HtmlFormatter, tagsfile='support/tags') + assert pytest.raises( + RuntimeError, HtmlFormatter, tagsfile='support/tags' + ) else: # this tagfile says that test_ctags() is on line 165, even if it isn't # anymore in the actual source diff --git a/tests/test_html_formatter_linenos_elements.py b/tests/test_html_formatter_linenos_elements.py new file mode 100644 index 00000000..c7431bcf --- /dev/null +++ b/tests/test_html_formatter_linenos_elements.py @@ -0,0 +1,55 @@ +import os +from io import StringIO + +import pytest + +from pygments.formatters import HtmlFormatter +from pygments.lexers import PythonLexer + + +TESTDIR = os.path.dirname(os.path.abspath(__file__)) +EXPECTED_OUTPUT_DIR = os.path.join(TESTDIR, "html_linenos_expected_output") +CODE = list(PythonLexer().get_tokens("# a\n# b\n# c")) + + +def single_line(text): + return "".join(l.strip() for l in text.splitlines()) + + +# Note: option `anchorlinenos` is currently ignored for `linenos=inline` +@pytest.mark.parametrize("linenos", ["inline", "table"]) +@pytest.mark.parametrize("noclasses", ["False", "True"]) +@pytest.mark.parametrize("linenostep", ["1", "2"]) +@pytest.mark.parametrize("linenostart", ["1", "8"]) +@pytest.mark.parametrize("linenospecial", ["0", "3"]) +@pytest.mark.parametrize("anchorlinenos", ["False", "True"]) +def test_linenos_elements( + linenos, noclasses, linenostep, linenostart, linenospecial, anchorlinenos +): + options = dict( + linenos=linenos, + noclasses=noclasses, + linenostep=linenostep, + linenostart=linenostart, + linenospecial=linenospecial, + anchorlinenos=anchorlinenos, + ) + + output = StringIO() + fmt = HtmlFormatter(**options) + fmt.format(CODE, output) + html = output.getvalue() + + filename_parts = [] + filename_parts.append(linenos) + filename_parts.append("nocls" if noclasses == "True" else "cls") + filename_parts.append("step_" + linenostep) + filename_parts.append("start_" + linenostart) + filename_parts.append("special_" + linenospecial) + filename_parts.append("anchor" if anchorlinenos == "True" else "noanchor") + expected_html_filename = "_".join(filename_parts) + ".html" + + with open(os.path.join(EXPECTED_OUTPUT_DIR, expected_html_filename)) as f: + expected_html = f.read() + + assert single_line(html) == single_line(expected_html) |