mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-06 01:15:24 +00:00
* parser_tools.py (find_tokens_exact): new, extract tokens with
exact match * parser_tools.py (find_token2): rename to find_token_exact and make it work for tokens with spaces * lyx_1_4.py (revert_box, convert_collapsable, revert_bibtopic, convert_float): use find_token(s)_exact instead of find_token(s). This does not match "FloatList" when "Float" is searched (bug 2245) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@13412 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f45c21fea7
commit
141058b7fb
@ -20,7 +20,7 @@
|
|||||||
import string
|
import string
|
||||||
import re
|
import re
|
||||||
from parser_tools import find_token, find_end_of_inset, get_value,\
|
from parser_tools import find_token, find_end_of_inset, get_value,\
|
||||||
find_token2, del_token
|
find_token_exact, del_token
|
||||||
|
|
||||||
def change_insetgraphics(file):
|
def change_insetgraphics(file):
|
||||||
lines = file.body
|
lines = file.body
|
||||||
@ -38,16 +38,16 @@ def change_insetgraphics(file):
|
|||||||
if get_value(lines, "rotateOrigin", i, j) == "leftBaseline":
|
if get_value(lines, "rotateOrigin", i, j) == "leftBaseline":
|
||||||
j = del_token(lines, "rotateOrigin", i, j)
|
j = del_token(lines, "rotateOrigin", i, j)
|
||||||
|
|
||||||
k = find_token2(lines, "rotate", i, j)
|
k = find_token_exact(lines, "rotate", i, j)
|
||||||
if k != -1:
|
if k != -1:
|
||||||
del lines[k]
|
del lines[k]
|
||||||
j = j-1
|
j = j-1
|
||||||
else:
|
else:
|
||||||
j = del_token(lines, "rotateAngle", i, j)
|
j = del_token(lines, "rotateAngle", i, j)
|
||||||
|
|
||||||
k = find_token2(lines, "size_type", i, j)
|
k = find_token_exact(lines, "size_type", i, j)
|
||||||
if k == -1:
|
if k == -1:
|
||||||
k = find_token2(lines, "size_kind", i, j)
|
k = find_token_exact(lines, "size_kind", i, j)
|
||||||
if k != -1:
|
if k != -1:
|
||||||
size_type = string.split(lines[k])[1]
|
size_type = string.split(lines[k])[1]
|
||||||
del lines[k]
|
del lines[k]
|
||||||
@ -64,9 +64,9 @@ def change_insetgraphics(file):
|
|||||||
else:
|
else:
|
||||||
j = del_token(lines, "scale", i, j)
|
j = del_token(lines, "scale", i, j)
|
||||||
|
|
||||||
k = find_token2(lines, "lyxsize_type", i, j)
|
k = find_token_exact(lines, "lyxsize_type", i, j)
|
||||||
if k == -1:
|
if k == -1:
|
||||||
k = find_token2(lines, "lyxsize_kind", i, j)
|
k = find_token_exact(lines, "lyxsize_kind", i, j)
|
||||||
if k != -1:
|
if k != -1:
|
||||||
lyxsize_type = string.split(lines[k])[1]
|
lyxsize_type = string.split(lines[k])[1]
|
||||||
del lines[k]
|
del lines[k]
|
||||||
|
@ -23,8 +23,8 @@ from os import access, F_OK
|
|||||||
import os.path
|
import os.path
|
||||||
from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \
|
from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \
|
||||||
get_paragraph, get_value, del_token, is_nonempty_line,\
|
get_paragraph, get_value, del_token, is_nonempty_line,\
|
||||||
find_tokens, find_end_of, find_token2, find_re,\
|
find_tokens, find_end_of, find_token_exact, find_tokens_exact,\
|
||||||
get_layout
|
find_re, get_layout
|
||||||
from sys import stdin
|
from sys import stdin
|
||||||
from string import replace, split, find, strip, join
|
from string import replace, split, find, strip, join
|
||||||
|
|
||||||
@ -827,7 +827,7 @@ def revert_box(file):
|
|||||||
def convert_collapsable(file):
|
def convert_collapsable(file):
|
||||||
i = 0
|
i = 0
|
||||||
while 1:
|
while 1:
|
||||||
i = find_tokens(file.body, ["\\begin_inset Box",
|
i = find_tokens_exact(file.body, ["\\begin_inset Box",
|
||||||
"\\begin_inset Branch",
|
"\\begin_inset Branch",
|
||||||
"\\begin_inset CharStyle",
|
"\\begin_inset CharStyle",
|
||||||
"\\begin_inset Float",
|
"\\begin_inset Float",
|
||||||
@ -861,7 +861,7 @@ def convert_collapsable(file):
|
|||||||
def revert_collapsable(file):
|
def revert_collapsable(file):
|
||||||
i = 0
|
i = 0
|
||||||
while 1:
|
while 1:
|
||||||
i = find_tokens(file.body, ["\\begin_inset Box",
|
i = find_tokens_exact(file.body, ["\\begin_inset Box",
|
||||||
"\\begin_inset Branch",
|
"\\begin_inset Branch",
|
||||||
"\\begin_inset CharStyle",
|
"\\begin_inset CharStyle",
|
||||||
"\\begin_inset Float",
|
"\\begin_inset Float",
|
||||||
@ -1752,7 +1752,7 @@ def revert_bibtopic(file):
|
|||||||
def convert_float(file):
|
def convert_float(file):
|
||||||
i = 0
|
i = 0
|
||||||
while 1:
|
while 1:
|
||||||
i = find_token(file.body, '\\begin_inset Float', i)
|
i = find_token_exact(file.body, '\\begin_inset Float', i)
|
||||||
if i == -1:
|
if i == -1:
|
||||||
return
|
return
|
||||||
# Seach for a line starting 'wide'
|
# Seach for a line starting 'wide'
|
||||||
@ -1773,7 +1773,7 @@ def convert_float(file):
|
|||||||
def revert_float(file):
|
def revert_float(file):
|
||||||
i = 0
|
i = 0
|
||||||
while 1:
|
while 1:
|
||||||
i = find_token(file.body, '\\begin_inset Float', i)
|
i = find_token_exact(file.body, '\\begin_inset Float', i)
|
||||||
if i == -1:
|
if i == -1:
|
||||||
return
|
return
|
||||||
j = find_end_of_inset(file.body, i)
|
j = find_end_of_inset(file.body, i)
|
||||||
@ -1799,7 +1799,7 @@ def convert_graphics(file):
|
|||||||
if i == -1:
|
if i == -1:
|
||||||
return
|
return
|
||||||
|
|
||||||
j = find_token2(file.body, "filename", i)
|
j = find_token_exact(file.body, "filename", i)
|
||||||
if j == -1:
|
if j == -1:
|
||||||
return
|
return
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
@ -37,27 +37,43 @@ def find_token(lines, token, start, end = 0):
|
|||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
def find_token2(lines, token, start, end = 0):
|
def find_token_exact(lines, token, start, end = 0):
|
||||||
if end == 0:
|
if end == 0:
|
||||||
end = len(lines)
|
end = len(lines)
|
||||||
for i in xrange(start, end):
|
for i in xrange(start, end):
|
||||||
x = string.split(lines[i])
|
x = string.split(lines[i])
|
||||||
if len(x) > 0 and x[0] == token:
|
y = string.split(token)
|
||||||
return i
|
if len(x) < len(y):
|
||||||
|
continue
|
||||||
|
if x[:len(y)] == y:
|
||||||
|
return i
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
def find_tokens(lines, tokens, start, end = 0):
|
def find_tokens(lines, tokens, start, end = 0):
|
||||||
if end == 0:
|
if end == 0:
|
||||||
end = len(lines)
|
end = len(lines)
|
||||||
for i in xrange(start, end):
|
for i in range(start, end):
|
||||||
line = lines[i]
|
|
||||||
for token in tokens:
|
for token in tokens:
|
||||||
if line[:len(token)] == token:
|
if lines[i][:len(token)] == token:
|
||||||
return i
|
return i
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
def find_tokens_exact(lines, tokens, start, end = 0):
|
||||||
|
if end == 0:
|
||||||
|
end = len(lines)
|
||||||
|
for i in range(start, end):
|
||||||
|
for token in tokens:
|
||||||
|
x = string.split(lines[i])
|
||||||
|
y = string.split(token)
|
||||||
|
if len(x) < len(y):
|
||||||
|
continue
|
||||||
|
if x[:len(y)] == y:
|
||||||
|
return i
|
||||||
|
return -1
|
||||||
|
|
||||||
|
|
||||||
def find_re(lines, rexp, start, end = 0):
|
def find_re(lines, rexp, start, end = 0):
|
||||||
if end == 0:
|
if end == 0:
|
||||||
end = len(lines)
|
end = len(lines)
|
||||||
@ -86,7 +102,7 @@ def find_tokens_backwards(lines, tokens, start):
|
|||||||
|
|
||||||
|
|
||||||
def get_value(lines, token, start, end = 0):
|
def get_value(lines, token, start, end = 0):
|
||||||
i = find_token2(lines, token, start, end)
|
i = find_token_exact(lines, token, start, end)
|
||||||
if i == -1:
|
if i == -1:
|
||||||
return ""
|
return ""
|
||||||
if len(string.split(lines[i])) > 1:
|
if len(string.split(lines[i])) > 1:
|
||||||
@ -103,7 +119,7 @@ def get_layout(line, default_layout):
|
|||||||
|
|
||||||
|
|
||||||
def del_token(lines, token, i, j):
|
def del_token(lines, token, i, j):
|
||||||
k = find_token2(lines, token, i, j)
|
k = find_token_exact(lines, token, i, j)
|
||||||
if k == -1:
|
if k == -1:
|
||||||
return j
|
return j
|
||||||
else:
|
else:
|
||||||
|
@ -37,6 +37,9 @@ What's new
|
|||||||
|
|
||||||
- Import fixed width table columns correctly in tex2lyx (bug 2290).
|
- Import fixed width table columns correctly in tex2lyx (bug 2290).
|
||||||
|
|
||||||
|
- Convert old LyX documents with a float list at the end correctly in
|
||||||
|
lyx2lyx (bug 2245).
|
||||||
|
|
||||||
* User Interface:
|
* User Interface:
|
||||||
|
|
||||||
- Convert line endings for external copy/paste on OS X (bug 1955).
|
- Convert line endings for external copy/paste on OS X (bug 1955).
|
||||||
|
Loading…
Reference in New Issue
Block a user