Skip to content

Commit

Permalink
Fix Nesting Bug in Parsing rich to sphinx Syntax (#58)
Browse files Browse the repository at this point in the history
* Fix Nesting Bug in Parsing ``rich`` to ``sphinx`` Syntax

* Add chango fragment for PR #58

---------

Co-authored-by: Bibo-Joshi <[email protected]>
  • Loading branch information
Bibo-Joshi and Bibo-Joshi authored Jan 10, 2025
1 parent d88f7c8 commit c7338f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/unreleased/0058.VAr8EJ6caZfdNxfAJA2PBs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix Nesting Bug in Parsing ``rich`` to ``sphinx`` Syntax (`#58 <https://github.com/Bibo-Joshi/chango/pull/58>`_)
12 changes: 7 additions & 5 deletions docs/auxil/rich_to_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,24 @@ def _render_rst_text(cls, plain_text: str, spans: list[Span], offset: int = 0) -
if span in parsed_spans:
continue

span_text = plain_text[span.start : span.end]
span_start = span.start - offset
span_end = span.end - offset
span_text = plain_text[span_start:span_end]
nested_spans = [
s
for s in sorted_spans
if s.start >= span.start and s.end <= span.end and s != span
if s.start >= span_start and s.end <= span_end and s != span
]
parsed_spans.extend(nested_spans)

if nested_spans:
span_text = cls._render_rst_text(
plain_text=span_text, spans=nested_spans, offset=span.start
plain_text=span_text, spans=nested_spans, offset=span_start
)

insert = cls.process_rich_span(span_text, span.style)
rst_text += plain_text[last_offset : span.start] + insert
last_offset = span.start - offset + (span.end - span.start)
rst_text += plain_text[last_offset:span_start] + insert
last_offset = span_start + (span.end - span.start)

rst_text += plain_text[last_offset:]
return rst_text
Expand Down

0 comments on commit c7338f2

Please sign in to comment.