[LyX/master] revert_mintedlangs: consider grouping when splitting options
Juergen Spitzmueller <[email protected]> Tue, 04 Aug 2026 04:51:12 +0000
| Newsgroups | gmane.editors.lyx.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 441fe44742204083011b449a058df79ea6d5cde8 Author: Juergen Spitzmueller <[email protected]> Date: Tue Aug 4 06:50:22 2026 +0200 revert_mintedlangs: consider grouping when splitting options Thanks to Pavel and Claude --- lib/lyx2lyx/lyx_2_6.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/lyx2lyx/lyx_2_6.py b/lib/lyx2lyx/lyx_2_6.py index f88d3f011b..9c2eb4c634 100644 --- a/lib/lyx2lyx/lyx_2_6.py +++ b/lib/lyx2lyx/lyx_2_6.py @@ -181,6 +181,36 @@ def revert_xref_defs(document, prfx, form, counter, alias): ) +def split_respecting_groups(s): + """ + Split a comma-separated string on top-level commas only, + ignoring commas that are inside a group + ("a, {b, c}, d" => ['a', '{b, c}', 'd']). + Also strips whitespace from each resulting item. + """ + items = [] + depth = 0 + current = [] + + for char in s: + if char == '{': + depth += 1 + current.append(char) + elif char == '}': + depth -= 1 + current.append(char) + elif char == ',' and depth == 0: + items.append(''.join(current).strip()) + current = [] + else: + current.append(char) + + # add the last item + if current: + items.append(''.join(current).strip()) + + return items + ############################################################################### ### @@ -1526,7 +1556,7 @@ def revert_mintedlangs(document): if k == -1: continue lp = get_quoted_value(document.body, "lstparams", k) - lps = lp.split(",") + lps = split_respecting_groups(lp) lps_res = [] for l in lps: if "language=" in l: -- lyx-cvs mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-cvs