Skip to content

Commit e65a9ec

Browse files
committed
DOP-1806: Abbreviate labels
1 parent 568d8b9 commit e65a9ec

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

snooty/postprocess.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,17 @@ def handle_refs(self, fileid_stack: FileIdStack, node: n.Node) -> None:
681681
)
682682
for title_node in cloned_title_nodes:
683683
deep_copy_position(node, title_node)
684+
685+
# Label abbreviation is underspecified. Good luck!
686+
if "~" in node.flag and cloned_title_nodes:
687+
node_to_abbreviate = cloned_title_nodes[0]
688+
if isinstance(node_to_abbreviate, n.Text):
689+
index = node_to_abbreviate.value.rfind(".")
690+
new_value = node_to_abbreviate.value[index + 1 :].strip()
691+
692+
if new_value:
693+
node_to_abbreviate.value = new_value
694+
684695
injection_candidate.children = cloned_title_nodes
685696

686697
def attempt_disambugation(

snooty/test_postprocess.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,43 @@ def test_same_page_target_resolution() -> None:
253253
)
254254

255255

256+
def test_abbreviated_link() -> None:
257+
with make_test(
258+
{
259+
Path(
260+
"source/index.txt"
261+
): """
262+
.. method:: db.collection.watch()
263+
264+
:method:`~db.collection.watch`
265+
""",
266+
}
267+
) as result:
268+
assert not [
269+
diagnostics for diagnostics in result.diagnostics.values() if diagnostics
270+
], "Should not raise any diagnostics"
271+
272+
page = result.pages[FileId("index.txt")]
273+
print(ast_to_testing_string(page.ast))
274+
check_ast_testing_string(
275+
page.ast,
276+
"""
277+
<root fileid="index.txt">
278+
<target domain="mongodb" name="method" html_id="mongodb-method-db.collection.watch">
279+
<directive_argument><literal><text>db.collection.watch()</text></literal></directive_argument>
280+
<target_identifier ids="['db.collection.watch']"><text>db.collection.watch()</text></target_identifier>
281+
</target>
282+
283+
<paragraph>
284+
<ref_role domain="mongodb" name="method" target="db.collection.watch" flag="~" fileid="['index', 'mongodb-method-db.collection.watch']">
285+
<literal><text>watch()</text></literal>
286+
</ref_role>
287+
</paragraph>
288+
</root>
289+
""",
290+
)
291+
292+
256293
def test_language_selector() -> None:
257294
with make_test(
258295
{

0 commit comments

Comments
 (0)