Financial agents monitor transactions and support continuous accounting across connected global finance operations . Teams review exceptions before reports are finalized.
diff --git a/backlink_intelligence/placement.py b/backlink_intelligence/placement.py
index b10d29a..29474c4 100644
--- a/backlink_intelligence/placement.py
+++ b/backlink_intelligence/placement.py
@@ -184,6 +184,7 @@ def _rewrite_candidate(
stripped = sentence.rstrip()
terminal = stripped[-1] if stripped and stripped[-1] in ".!?" else "."
sentence_body = stripped[:-1] if stripped and stripped[-1] in ".!?" else stripped
+ sentence_body = sentence_body.rstrip()
placed_anchor = _fallback_anchor_case(anchor)
linked_phrase = _anchor_with_article(placed_anchor)
diff --git a/tests/test_placement.py b/tests/test_placement.py
index 1d4e09d..19c6ad1 100644
--- a/tests/test_placement.py
+++ b/tests/test_placement.py
@@ -245,6 +245,19 @@ def test_generated_rewrite_is_deterministic(self):
second = rank_placements(source, target, "ai in finance course", "https://t.com", top_n=1)[0]
self.assertEqual(first.to_dict(), second.to_dict())
+ def test_rewrite_normalizes_space_before_terminal_punctuation(self):
+ source = parse_page(
+ """ Financial agents monitor transactions and support continuous accounting across connected global finance operations . Teams review exceptions before reports are finalized.
Study financial agents, continuous accounting, and transaction monitoring.
""", + requested_url="https://t.com", final_url="https://t.com", status_code=200, + ) + item = rank_placements(source, target, "ai in finance course", "https://t.com", top_n=1)[0] + self.assertNotIn(" ,", item.after_text) + self.assertIn("operations, one of the practical applications", item.after_text) + if __name__ == "__main__":