Skip to content

Commit 9745304

Browse files
authored
fix copyable passed option in literalinclude and add test (#442)
1 parent 4c75cd8 commit 9745304

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

snooty/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def _locate_text(text: str) -> int:
847847
span = (line,)
848848
language = options["language"] if "language" in options else ""
849849
caption = options["caption"] if "caption" in options else None
850-
copyable = "copyable" not in options or options["copyable"] == "True"
850+
copyable = "copyable" not in options or options["copyable"] != False
851851
selected_content = "\n".join(lines)
852852
linenos = "linenos" in options
853853
lineno_start = (

snooty/test_parser.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,33 @@ def test_literalinclude() -> None:
953953
</root>""",
954954
)
955955

956+
# Test a literally-included code block with copyable option specified
957+
page, diagnostics = parse_rst(
958+
parser,
959+
path,
960+
"""
961+
.. literalinclude:: /test_parser/includes/sample_code.js
962+
:language: json
963+
:copyable: true
964+
:emphasize-lines: 5
965+
""",
966+
)
967+
page.finish(diagnostics)
968+
assert diagnostics == []
969+
check_ast_testing_string(
970+
page.ast,
971+
"""<root fileid="test.rst">
972+
<directive name="literalinclude" language="json" emphasize-lines="5" copyable="True">
973+
<text>/test_parser/includes/sample_code.js</text>
974+
<code lang="json" emphasize_lines="[(5, 5)]" copyable="True">var str = "sample code";
975+
var i = 0;
976+
for (i = 0; i &lt; 10; i++) {
977+
str += i;
978+
}</code>
979+
</directive>
980+
</root>""",
981+
)
982+
956983
# Test a literally-included code block with fully specified options
957984
page, diagnostics = parse_rst(
958985
parser,

0 commit comments

Comments
 (0)