From 205feb0704d7a7c28a5161738c5fafe4ded34499 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Mon, 29 Mar 2010 17:01:41 +0000 Subject: [PATCH] Introduce a proper form of the put_cmd_in_ert function. Even if this doesn't get used in 2.0, we'll at least have it for later. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33915 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/lyx_2_0.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 97f1c507b2..2bcd4b7719 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -90,6 +90,8 @@ def read_unicodesymbols(): unicode_reps = read_unicodesymbols() +# DO NOT USE THIS ROUTINE ANY MORE. Better yet, replace the uses that +# have been made of it with uses of put_cmd_in_ert. def old_put_cmd_in_ert(string): for rep in unicode_reps: string = string.replace(rep[1], rep[0].replace('\\\\', '\\')) @@ -99,6 +101,40 @@ def old_put_cmd_in_ert(string): return string +# This routine wraps some content in an ERT inset. It returns a +# LIST of strings. This is how lyx2lyx works: with a list of strings, +# each representing a line of a LyX file. Embedded newlines confuse +# lyx2lyx very much. +# For this same reason, we expect as input a LIST of strings, not +# something with embedded newlines. That said, if any of your strings +# do have embedded newlines, the string will eventually get split on +# them and you'll get a list back. +# +# A call to this routine will often go something like this: +# i = find_token('\\begin_inset FunkyInset', ...) +# ... +# j = find_end_of_inset(document.body, i) +# content = ...extract content from insets +# ert = put_cmd_in_ert(content) +# document.body[i:j] = ert +# Now, before we continue, we need to reset i appropriately. Normally, +# this would be: +# i += len(ert) +# That puts us right after the ERT we just inserted. +def put_cmd_in_ert(strlist): + ret = ["\\begin_inset ERT", "status collapsed", "\\begin_layout Plain Layout\n"] + # Despite the warnings just given, it will be faster for us to work + # with a single string internally. That way, we only go through the + # unicode_reps loop once. + s = "\n".join(strlist) + for rep in unicode_reps: + s = s.replace(rep[1], rep[0].replace('\\\\', '\\')) + s = s.replace('\\', "\\backslash\n") + ret += s.splitlines() + ret += ["\\end_layout", "\\end_inset"] + return ret + + def lyx2latex(document, lines): 'Convert some LyX stuff into corresponding LaTeX stuff, as best we can.' # clean up multiline stuff -- 2.39.2