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.
document.warning("Malformed LyX document: "
"Can't find layout at line %d" % i)
continue
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
if layoutname == "LyX-Code":
i = end
continue
def get_containing_layout(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)
(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.
if endlay < i:
return False
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"]
par_params = ["\\noindent", "\\indent", "\\indent-toggle", "\\leftindent",
"\\start_of_appendix", "\\paragraph_spacing", "\\align",
"\\labelwidthstring"]
stpar += 1
if lines[stpar].split(' ', 1)[0] not in par_params:
break
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):
def count_pars_in_inset(lines, i):