summaryrefslogtreecommitdiff
path: root/pygments/formatters
diff options
context:
space:
mode:
authorMaximilian Hils <github@maximilianhils.com>2022-01-31 21:59:04 +0100
committerGitHub <noreply@github.com>2022-01-31 21:59:04 +0100
commitb1edee0c8f736276a86e30d8edaed1f581e009d0 (patch)
tree70a48355522a0030396547b40553acb5bc2ac9b3 /pygments/formatters
parent405b9e4936f54a6cc6e67f5c47df0b9ae7aaca7f (diff)
downloadpygments-git-b1edee0c8f736276a86e30d8edaed1f581e009d0.tar.gz
When using the HTML formatter with `linespans=foo`, `linenos=inline`, and `anchorlinenos=True`, (#2026)
the generated anchor links should be `#foo-42` and not `#-42`.
Diffstat (limited to 'pygments/formatters')
-rw-r--r--pygments/formatters/html.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index b9633fd6..e1043b67 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -667,7 +667,7 @@ class HtmlFormatter(Formatter):
mw = len(str(lncount + fl - 1))
sp = self.linenospecial
st = self.linenostep
- la = self.lineanchors
+ anchor_name = self.lineanchors or self.linespans
aln = self.anchorlinenos
nocls = self.noclasses
@@ -680,7 +680,7 @@ class HtmlFormatter(Formatter):
if print_line:
line = '%*d' % (mw, i)
if aln:
- line = '<a href="#%s-%d">%s</a>' % (la, i, line)
+ line = '<a href="#%s-%d">%s</a>' % (anchor_name, i, line)
else:
line = ' ' * mw
@@ -729,7 +729,7 @@ class HtmlFormatter(Formatter):
st = self.linenostep
num = self.linenostart
mw = len(str(len(inner_lines) + num - 1))
- la = self.lineanchors
+ anchor_name = self.lineanchors or self.linespans
aln = self.anchorlinenos
nocls = self.noclasses
@@ -759,7 +759,7 @@ class HtmlFormatter(Formatter):
linenos = line
if aln:
- yield 1, ('<a href="#%s-%d">%s</a>' % (la, num, linenos) +
+ yield 1, ('<a href="#%s-%d">%s</a>' % (anchor_name, num, linenos) +
inner_line)
else:
yield 1, linenos + inner_line