lyx2lyx: Use correct check for emty lines while converting Begin/EndFrontmatter

* Coversion now tries not to pollute the result with emty lines
* stripped some trailing spaces
This commit is contained in:
Kornel Benko 2018-07-31 13:44:48 +02:00
parent d70468a3b2
commit 7f3fd5a809

View File

@ -64,22 +64,30 @@ def removeFrontMatterStyles(document):
document.warning("Malformed LyX document: Can't find end of layout at line %d" % i) document.warning("Malformed LyX document: Can't find end of layout at line %d" % i)
i += 1 i += 1
continue continue
if document.body[j] == '': while i > 0 and document.body[i-1].strip() == '':
i -= 1
while document.body[j+1].strip() == '':
j = j + 1 j = j + 1
del document.body[i:j+1] document.body[i:j+1] = ['']
def addFrontMatterStyles(document): def addFrontMatterStyles(document):
" Use styles Begin/EndFrontmatter for elsarticle" " Use styles Begin/EndFrontmatter for elsarticle"
def insertFrontmatter(prefix, line): def insertFrontmatter(prefix, line):
document.body[line:line] = ['\\begin_layout ' + prefix + 'Frontmatter', above = line
while above > 0 and document.body[above-1].strip() == '':
above -= 1
below = line
while document.body[below].strip() == '':
below += 1
document.body[above:below] = ['', '\\begin_layout ' + prefix + 'Frontmatter',
'\\begin_inset Note Note', '\\begin_inset Note Note',
'status open', '', 'status open', '',
'\\begin_layout Plain Layout', '\\begin_layout Plain Layout',
'Keep this empty!', 'Keep this empty!',
'\\end_layout', '', '\\end_layout', '',
'\\end_inset', '', '', '\\end_inset', '', '',
'\\end_layout'] '\\end_layout', '']
if document.textclass == "elsarticle": if document.textclass == "elsarticle":
layouts = ['Title', 'Title footnote', 'Author', 'Author footnote', layouts = ['Title', 'Title footnote', 'Author', 'Author footnote',
@ -101,13 +109,9 @@ def addFrontMatterStyles(document):
first = i first = i
if last == -1 or last <= k: if last == -1 or last <= k:
last = k+1 last = k+1
i = k i = k+1
if first == -1: if first == -1:
return return
if first > 0 and document.body[first-1] == '':
first -= 1
if document.body[last] == '':
last = last + 1
insertFrontmatter('End', last) insertFrontmatter('End', last)
insertFrontmatter('Begin', first) insertFrontmatter('Begin', first)