X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Flyx2lyx%2Flyx_0_10.py;h=13602ac917eb241922e051aa9d20155e97869207;hb=c37500050d267177ace194ba8a95f67c6b0f15c2;hp=cc5187700422a6dc47d4394bd2e4420df2cf952e;hpb=695bfd88ed8f02e35c4a31664ed5a2b9f135cf72;p=lyx.git diff --git a/lib/lyx2lyx/lyx_0_10.py b/lib/lyx2lyx/lyx_0_10.py index cc51877004..13602ac917 100644 --- a/lib/lyx2lyx/lyx_0_10.py +++ b/lib/lyx2lyx/lyx_0_10.py @@ -14,7 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """ Convert files to the file format generated by lyx 0.10""" @@ -32,18 +32,17 @@ def regularise_header(document): def find_next_space(line, j): """ Return position of next space or backslash, which one comes - first, starting from position k, if not existing return last - position in line.""" - l = line.find(' ', j) - if l == -1: - l = len(line) - k = line.find('\\', j) - if k == -1: - k = len(line) + first, starting from position j, if none exists returns last + position in line (+1).""" + space_pos = line.find(' ', j) + if space_pos == -1: + space_pos = len(line) - if k < l: - return k - return l + bksl_pos = line.find('\\', j) + if bksl_pos == -1: + bksl_pos = len(line) + + return min(space_pos, bksl_pos) def regularise_body(document): @@ -65,36 +64,38 @@ def regularise_body(document): while i < len(document.body): line = document.body[i] j = 0 - tmp = [] + new_block = [] while j < len(line): k = line.find('\\', j) if k == -1: - tmp += [line[j:]] + new_block += [line[j:]] break if k != j: - tmp += [line[j: k]] + #document.warning("j=%d\tk=%d\t#%s#%s#" % (j,k,line,line[j: k])) + new_block += [line[j: k]] j = k k = find_next_space(line, j+1) - # These tokens take the rest of the line token = line[j+1:k] + # These tokens take the rest of the line if token in getline_tokens: - tmp += [line[j:]] + #document.warning("getline_token:%s\tj=%d\t\t#%s#%s#" % (token,j,line,line[j:])) + new_block += [line[j:]] break # These tokens take no arguments if token in noargs_tokens: - tmp += [line[j:k]] + new_block += [line[j:k]] j = k continue # These tokens take one argument if token in onearg_tokens: k = find_next_space(line, k + 1) - tmp += [line[j:k]] + new_block += [line[j:k]] j = k continue @@ -104,28 +105,30 @@ def regularise_body(document): inset = line[k+1: l] if inset == "Latex": - tmp += [line[j:l]] + new_block += [line[j:l]] j = l continue - if inset in ["LatexCommand", "LatexDel"]: - tmp += [line[j:]] + if inset in ["LatexCommand", "LatexDel", "Label", "Figure", + "Formula"]: + new_block += [line[j:]] break if inset == "Quotes": l = find_next_space(line, l + 1) - tmp += [line[j:l]] + new_block += [line[j:l]] j = l continue + document.warning("unkown inset %s" % inset) assert(False) # We are inside a latex inset, pass the text verbatim - tmp += [line[j:]] + new_block += [line[j:]] break - document.body[i: i+1] = tmp - i += len(tmp) + document.body[i: i+1] = new_block + i += len(new_block) supported_versions = ["0.10.%d" % i for i in range(8)] + ["0.10"]