From: Günter Milde Date: Thu, 17 Jan 2019 23:20:19 +0000 (+0100) Subject: Improve a warning in lyx2lyx. X-Git-Tag: lyx-2.4.0dev-acb2ca7b~2666 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a925d2508555ccfb67db1e2efde415aa0a34400e;p=features.git Improve a warning in lyx2lyx. If get_containing_layout() finds a layout without name, it will return an empty string as layoutname. Calling functions can thus differentiate between missing \begin_layout and missing layoutname and give a more specific response or warning. --- diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py index a2f37bc8d4..fd029d557b 100644 --- a/lib/lyx2lyx/lyx_2_3.py +++ b/lib/lyx2lyx/lyx_2_3.py @@ -1837,6 +1837,9 @@ def convert_dashligatures(document): document.warning("Malformed LyX document: " "Can't find layout at line %d" % i) continue + if not layoutname: + document.warning("Malformed LyX document: " + "Missing layout name on line %d"%start) if layoutname == "LyX-Code": i = end continue diff --git a/lib/lyx2lyx/parser_tools.py b/lib/lyx2lyx/parser_tools.py index c53dbfa1ab..12d6aa6be0 100644 --- a/lib/lyx2lyx/parser_tools.py +++ b/lib/lyx2lyx/parser_tools.py @@ -639,12 +639,15 @@ def get_containing_inset(lines, i): def get_containing_layout(lines, i): ''' - Finds out what kind of layout line i is within. Returns a - list containing what follows \begin_layout on the line - on which the layout begins, plus the starting and ending line - and the start of the paragraph (after all params). I.e, returns: + Find out what kind of layout line `i` is within. + Return a tuple (layoutname, layoutstart, layoutend, startofcontent) - Returns False on any kind of error. + containing + * layout style/name, + * start line number, + * end line number, and + * number of first paragraph line (after all params). + Return `False` on any kind of error. ''' j = i while True: @@ -659,10 +662,13 @@ def get_containing_layout(lines, i): if endlay < i: return False - lay = get_value(lines, "\\begin_layout", stlay) - if lay == "": - # shouldn't happen - return False + layoutname = get_value(lines, "\\begin_layout", stlay) + if layoutname == "": # layout style missing + # TODO: What shall we do in this case? + pass + # layoutname == "Standard" # use same fallback as the LyX parser: + # raise ValueError("Missing layout name on line %d"%stlay) # diagnosis + # return False # generic error response par_params = ["\\noindent", "\\indent", "\\indent-toggle", "\\leftindent", "\\start_of_appendix", "\\paragraph_spacing", "\\align", "\\labelwidthstring"] @@ -671,7 +677,7 @@ def get_containing_layout(lines, i): stpar += 1 if lines[stpar].split(' ', 1)[0] not in par_params: break - return (lay, stlay, endlay, stpar) + return (layoutname, stlay, endlay, stpar) def count_pars_in_inset(lines, i):