Skip to content

Commit

Permalink
fix off-by-one error introduced in CatalaLang#86
Browse files Browse the repository at this point in the history
  • Loading branch information
rprimet committed Feb 16, 2024
1 parent 7e2f359 commit 7920e70
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/catleg/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ def _article_skeleton(raw_article_json, breadcrumbs: bool = True):

parts = []
if breadcrumbs:
for i, toc_entry in enumerate(article_json["context"]["titresTM"], start=1):
texts = article_json["context"]["titreTxt"]
texts_in_force = [item for item in texts if item["etat"] == "VIGUEUR"]
# Pick the title of the first text currently in force,
# or the last item from the candidates list
crumbs = [texts_in_force[0] if texts_in_force else texts[-1]] + article_json[
"context"
]["titresTM"]
for i, toc_entry in enumerate(crumbs, start=1):
parts.append(f"{'#' * i} {toc_entry['titre']}")

# level: code (1) + length of section hierarchy + article (1)
Expand Down

0 comments on commit 7920e70

Please sign in to comment.