mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Fix up the put_cmd_in_ert routine so that it accepts either a list
or a string as input, and does the right thing either way. Previously, when it saw a string "test" it would convert it to "t\ne\ns\nt", since it was quite happy to call join() on the string. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34785 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
8d18af0309
commit
87a93a35e6
@ -108,34 +108,41 @@ def old_put_cmd_in_ert(string):
|
|||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
# This routine wraps some content in an ERT inset. It returns a
|
# This routine wraps some content in an ERT inset.
|
||||||
# LIST of strings. This is how lyx2lyx works: with a list of strings,
|
#
|
||||||
# each representing a line of a LyX file. Embedded newlines confuse
|
# NOTE: The function accepts either a single string or a LIST of strings as
|
||||||
|
# argument. But it returns a LIST of strings, split on \n, so that it does
|
||||||
|
# not have embedded newlines.
|
||||||
|
#
|
||||||
|
# This is how lyx2lyx represents a LyX document: as a list of strings,
|
||||||
|
# each representing a line of a LyX file. Embedded newlines confuse
|
||||||
# lyx2lyx very much.
|
# 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:
|
# A call to this routine will often go something like this:
|
||||||
# i = find_token('\\begin_inset FunkyInset', ...)
|
# i = find_token('\\begin_inset FunkyInset', ...)
|
||||||
# ...
|
# ...
|
||||||
# j = find_end_of_inset(document.body, i)
|
# j = find_end_of_inset(document.body, i)
|
||||||
# content = ...extract content from insets
|
# content = ...extract content from insets
|
||||||
|
# # that could be as simple as:
|
||||||
|
# # content = lyx2latex(document[i:j+1])
|
||||||
# ert = put_cmd_in_ert(content)
|
# ert = put_cmd_in_ert(content)
|
||||||
# document.body[i:j] = ert
|
# document.body[i:j] = ert
|
||||||
# Now, before we continue, we need to reset i appropriately. Normally,
|
# Now, before we continue, we need to reset i appropriately. Normally,
|
||||||
# this would be:
|
# this would be:
|
||||||
# i += len(ert)
|
# i += len(ert)
|
||||||
# That puts us right after the ERT we just inserted.
|
# That puts us right after the ERT we just inserted.
|
||||||
def put_cmd_in_ert(strlist):
|
#
|
||||||
|
def put_cmd_in_ert(arg):
|
||||||
ret = ["\\begin_inset ERT", "status collapsed", "\\begin_layout Plain Layout", ""]
|
ret = ["\\begin_inset ERT", "status collapsed", "\\begin_layout Plain Layout", ""]
|
||||||
# Despite the warnings just given, it will be faster for us to work
|
# 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
|
# with a single string internally. That way, we only go through the
|
||||||
# unicode_reps loop once.
|
# unicode_reps loop once.
|
||||||
s = "\n".join(strlist)
|
if type(arg) is list:
|
||||||
|
s = "\n".join(arg)
|
||||||
|
else:
|
||||||
|
s = arg
|
||||||
for rep in unicode_reps:
|
for rep in unicode_reps:
|
||||||
s = s.replace(rep[1], rep[0].replace('\\\\', '\\'))
|
s = s.replace(rep[1], rep[0].replace('\\\\', '\\'))
|
||||||
s = s.replace('\\', "\\backslash\n")
|
s = s.replace('\\', "\\backslash\n")
|
||||||
ret += s.splitlines()
|
ret += s.splitlines()
|
||||||
ret += ["\\end_layout", "\\end_inset"]
|
ret += ["\\end_layout", "\\end_inset"]
|
||||||
|
Loading…
Reference in New Issue
Block a user