Skip to content

Commit

Permalink
Correctly apply both emphasize and classes to the same lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
nyergler committed Apr 11, 2014
1 parent 9ab91da commit 29484ce
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
8 changes: 8 additions & 0 deletions NEWS.txt
@@ -1,6 +1,14 @@
News
====

0.2
---

*Release date: UNRELEASED*

* ``line-classes`` and ``emphasize-lines`` work correctly when applied
to the same line.

0.1
---

Expand Down
11 changes: 7 additions & 4 deletions src/classycode/directives.py
Expand Up @@ -54,11 +54,14 @@ def run(self):
)

if self.options.get('line-classes'):
hl_lines.update(
parselinenos(
self.options['line-classes'],
),
line_classes = parselinenos(
self.options['line-classes'],
)
for line in line_classes:
if line in hl_lines:
hl_lines[line] = '%s %s' % (hl_lines[line], line_classes[line])
else:
hl_lines[line] = line_classes[line]

result[0].setdefault('highlight_args', {})['hl_lines'] = hl_lines

Expand Down
27 changes: 27 additions & 0 deletions src/classycode/tests/test_directives.py
Expand Up @@ -223,3 +223,30 @@ def test_mix_emphasize_lines_and_classes(self):
2: 'two',
},
)

def test_emphasize_lines_and_classes_same_line(self):

with patch.object(self.app.env, 'note_dependency'):
document = make_document(
'testing',
"""\
Title
-----
.. literalinclude:: /test.py
:emphasize-lines: 2
:line-classes: 2(two)
Additional Text
""",
env=self.app.env,
)

codeblock = document.traverse(nodes.literal_block)[0]

self.assertEqual(
codeblock['highlight_args']['hl_lines'],
{2: 'hll two',
},
)

0 comments on commit 29484ce

Please sign in to comment.