More work on 5006.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25539 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2008-07-10 16:24:19 +00:00
parent 24a94f7254
commit 82152ac435

View File

@ -250,8 +250,7 @@ def latex2lyx(data):
if pos == -1: if pos == -1:
break break
nextpos = pos + len(rep[0]) nextpos = pos + len(rep[0])
nextchar = data[nextpos - 1 : nextpos] if nextpos < len(data) and data[nextpos].isalpha():
if nextchar.isalpha():
# not the end of that command # not the end of that command
pos = nextpos pos = nextpos
continue continue
@ -997,38 +996,40 @@ def revert_latexcommand_index(document):
j = find_end_of_inset(document.body, i + 1) j = find_end_of_inset(document.body, i + 1)
if j == -1: if j == -1:
return return
del document.body[j - 1]
del document.body[j - 2] # \end_layout
document.body[i] = "\\begin_inset CommandInset index"
document.body[i + 1] = "LatexCommand index"
# clean up multiline stuff # clean up multiline stuff
content = "" content = ""
ert_end = 0 ert_end = 0
for k in range(i + 3, j - 2): reps = read_unicodesymbols()
line = document.body[k]
for curline in range(i + 3, j - 2): # can skip last couple lines
line = document.body[curline]
if line.startswith("\\begin_inset ERT"): if line.startswith("\\begin_inset ERT"):
ert_end = find_end_of_inset(document.body, k + 1) # We don't want to replace things inside ERT, so figure out
line = line[16:] # where the end of the inset is.
if line.startswith("\\begin_inset Formula"): ert_end = find_end_of_inset(document.body, curline + 1)
line = line[20:] continue
if line.startswith("\\begin_layout Standard"): elif line.startswith("\\begin_inset Formula"):
line = line[22:] line = line[20:]
if line.startswith("\\begin_layout Plain Layout"): elif line.isspace() or \
line = line[26:] line.startswith("\\begin_layout Standard") or \
if line.startswith("\\end_layout"): line.startswith("\\begin_layout Plain Layout") or \
line = line[11:] line.startswith("\\end_layout") or \
if line.startswith("\\end_inset"): line.startswith("\\end_inset") or \
line = line[10:] line.startswith("\\lang") or \
if line.startswith("status collapsed"): line.startswith("status collapsed") or \
line = line[16:] line.startswith("status open"):
if line.startswith("status open"): #skip all that stuff
line = line[11:] continue
# a lossless reversion is not possible # a lossless reversion is not possible
# try at least to handle some common insets and settings # try at least to handle some common insets and settings
# do not replace inside ERTs # do not replace inside ERTs
if ert_end < k: if ert_end >= curline:
line = line.replace(r'\backslash', r'\\')
else:
# Do the LyX text --> LaTeX conversion # Do the LyX text --> LaTeX conversion
for rep in replacements: for rep in reps:
line = line.replace(rep[1], rep[0]) line = line.replace(rep[1], rep[0])
line = line.replace(r'\backslash', r'\textbackslash{}') line = line.replace(r'\backslash', r'\textbackslash{}')
line = line.replace(r'\series bold', r'\bfseries{}').replace(r'\series default', r'\mdseries{}') line = line.replace(r'\series bold', r'\bfseries{}').replace(r'\series default', r'\mdseries{}')
@ -1040,15 +1041,14 @@ def revert_latexcommand_index(document):
line = line.replace(r'\family sans', r'\sffamily{}').replace(r'\family default', r'\normalfont{}') line = line.replace(r'\family sans', r'\sffamily{}').replace(r'\family default', r'\normalfont{}')
line = line.replace(r'\family typewriter', r'\ttfamily{}').replace(r'\family roman', r'\rmfamily{}') line = line.replace(r'\family typewriter', r'\ttfamily{}').replace(r'\family roman', r'\rmfamily{}')
line = line.replace(r'\InsetSpace ', r'').replace(r'\SpecialChar ', r'') line = line.replace(r'\InsetSpace ', r'').replace(r'\SpecialChar ', r'')
else: content += line;
line = line.replace(r'\backslash', r'\\')
content = content + line; # end of curline loop
document.body[i + 3] = "name " + '"' + content + '"' # escape quotes
for k in range(i + 4, j - 2): content = content.replace('"', r'\"')
del document.body[i + 4] document.body[i:j] = ["\\begin_inset CommandInset index", "LatexCommand index",
document.body.insert(i + 4, "") "name " + '"' + content + '"', ""]
del document.body[i + 2] # \begin_layout standard i += 5
i = i + 5
def revert_wraptable(document): def revert_wraptable(document):