# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from parser_tools import get_value, check_token, find_token,\
- find_tokens, find_end_of, find_end_of_inset
+ find_tokens, find_end_of
import os.path
import gzip
import sys
default_debug_level = 2
+####################################################################
+# Private helper functions
+
+def find_end_of_inset(lines, i):
+ return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+# End of helper functions
+####################################################################
+
+
# Regular expressions used
format_re = re.compile(r"(\d)[\.,]?(\d\d)")
fileformat = re.compile(r"\\lyxformat\s*(\S*)")
except:
self.input = open(input)
else:
+ self.dir = ''
self.input = sys.stdin
import re
import string
-from parser_tools import find_token, find_token_backwards, find_re, get_layout
+from parser_tools import find_token, find_token_backwards, find_re
+####################################################################
+# Private helper functions
+
+def get_layout(line, default_layout):
+ tokens = string.split(line)
+ if len(tokens) > 1:
+ return tokens[1]
+ return default_layout
+
+
+####################################################################
math_env = ["\\[","\\begin{eqnarray*}","\\begin{eqnarray}","\\begin{equation}"]
import string
import re
-from parser_tools import find_token, find_token_backwards, get_next_paragraph,\
- find_tokens, find_end_of_inset, find_re, \
- is_nonempty_line, get_paragraph, find_nonempty_line, \
- get_value, get_tabular_lines, check_token, get_layout
+from parser_tools import find_token, find_token_backwards, \
+ find_tokens, find_tokens_backwards, find_beginning_of, find_end_of, find_re, \
+ is_nonempty_line, find_nonempty_line, \
+ get_value, check_token
+
+####################################################################
+# Private helper functions
+
+def get_layout(line, default_layout):
+ tokens = string.split(line)
+ if len(tokens) > 1:
+ return tokens[1]
+ return default_layout
+
+
+# Finds the paragraph that contains line i.
+def get_paragraph(lines, i, format):
+ begin_layout = "\\layout"
+
+ while i != -1:
+ i = find_tokens_backwards(lines, ["\\end_inset", begin_layout], i)
+ if i == -1: return -1
+ if check_token(lines[i], begin_layout):
+ return i
+ i = find_beginning_of_inset(lines, i)
+ return -1
+
+
+# Finds the paragraph after the paragraph that contains line i.
+def get_next_paragraph(lines, i, format):
+ tokens = ["\\begin_inset", "\\layout", "\\end_float", "\\the_end"]
+
+ while i != -1:
+ i = find_tokens(lines, tokens, i)
+ if not check_token(lines[i], "\\begin_inset"):
+ return i
+ i = find_end_of_inset(lines, i)
+ return -1
+
+
+def find_beginning_of_inset(lines, i):
+ return find_beginning_of(lines, i, "\\begin_inset", "\\end_inset")
+
+
+# Finds the matching \end_inset
+def find_end_of_inset(lines, i):
+ return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+
+def find_end_of_tabular(lines, i):
+ return find_end_of(lines, i, "<lyxtabular", "</lyxtabular")
+
+
+def get_tabular_lines(lines, i):
+ result = []
+ i = i+1
+ j = find_end_of_tabular(lines, i)
+ if j == -1:
+ return []
+
+ while i <= j:
+ if check_token(lines[i], "\\begin_inset"):
+ i = find_end_of_inset(lines, i)+1
+ else:
+ result.append(i)
+ i = i+1
+ return result
+
+# End of helper functions
+####################################################################
+
floats = {
"footnote": ["\\begin_inset Foot",
import string
import re
-from parser_tools import find_token, find_end_of_inset, get_value,\
+from parser_tools import find_token, find_end_of, get_value,\
find_token_exact, del_token
+####################################################################
+# Private helper functions
+
+def find_end_of_inset(lines, i):
+ "Finds the matching \end_inset"
+ return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+# End of helper functions
+####################################################################
+
+
def change_insetgraphics(file):
lines = file.body
i = 0
import re
from os import access, F_OK
import os.path
-from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \
- get_paragraph, get_value, del_token, is_nonempty_line,\
- find_tokens, find_end_of, find_token_exact, find_tokens_exact,\
- find_re, get_layout
+from parser_tools import check_token, find_token, \
+ get_value, del_token, is_nonempty_line, \
+ find_tokens, find_end_of, find_beginning_of, find_token_exact, find_tokens_exact, \
+ find_re, find_tokens_backwards
from sys import stdin
from string import replace, split, find, strip, join
from lyx_0_12 import update_latexaccents
+####################################################################
+# Private helper functions
+
+def get_layout(line, default_layout):
+ tokens = split(line)
+ if len(tokens) > 1:
+ return tokens[1]
+ return default_layout
+
+
+def get_paragraph(lines, i, format):
+ "Finds the paragraph that contains line i."
+
+ if format < 225:
+ begin_layout = "\\layout"
+ else:
+ begin_layout = "\\begin_layout"
+ while i != -1:
+ i = find_tokens_backwards(lines, ["\\end_inset", begin_layout], i)
+ if i == -1: return -1
+ if check_token(lines[i], begin_layout):
+ return i
+ i = find_beginning_of_inset(lines, i)
+ return -1
+
+
+def find_beginning_of_inset(lines, i):
+ return find_beginning_of(lines, i, "\\begin_inset", "\\end_inset")
+
+
+def get_next_paragraph(lines, i, format):
+ "Finds the paragraph after the paragraph that contains line i."
+
+ if format < 225:
+ tokens = ["\\begin_inset", "\\layout", "\\end_float", "\\the_end"]
+ elif format < 236:
+ tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_document"]
+ else:
+ tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_body", "\\end_document"]
+ while i != -1:
+ i = find_tokens(lines, tokens, i)
+ if not check_token(lines[i], "\\begin_inset"):
+ return i
+ i = find_end_of_inset(lines, i)
+ return -1
+
+
+def find_end_of_inset(lines, i):
+ "Finds the matching \end_inset"
+ return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+# End of helper functions
+####################################################################
+
+
##
# Remove \color default
#
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import re
-from parser_tools import find_token, find_token_exact, find_tokens, find_end_of_inset, get_value
+from parser_tools import find_token, find_token_exact, find_tokens, find_end_of, get_value
from string import replace
+####################################################################
+# Private helper functions
+
+def find_end_of_inset(lines, i):
+ return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+# End of helper functions
+####################################################################
+
+
##
# Notes: Framed/Shaded
#
return ""
-def get_layout(line, default_layout):
- tokens = string.split(line)
- if len(tokens) > 1:
- return tokens[1]
- return default_layout
-
-
def del_token(lines, token, start, end):
k = find_token_exact(lines, token, start, end)
if k == -1:
return end - 1
-# Finds the paragraph that contains line i.
-def get_paragraph(lines, i, format):
- if format < 225:
- begin_layout = "\\layout"
- else:
- begin_layout = "\\begin_layout"
- while i != -1:
- i = find_tokens_backwards(lines, ["\\end_inset", begin_layout], i)
- if i == -1: return -1
- if check_token(lines[i], begin_layout):
- return i
- i = find_beginning_of_inset(lines, i)
- return -1
-
-
-# Finds the paragraph after the paragraph that contains line i.
-def get_next_paragraph(lines, i, format):
- if format < 225:
- tokens = ["\\begin_inset", "\\layout", "\\end_float", "\\the_end"]
- elif format < 236:
- tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_document"]
- else:
- tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_body", "\\end_document"]
- while i != -1:
- i = find_tokens(lines, tokens, i)
- if not check_token(lines[i], "\\begin_inset"):
- return i
- i = find_end_of_inset(lines, i)
- return -1
-
-
def find_end_of(lines, i, start_token, end_token):
count = 1
n = len(lines)
return -1
-# Finds the matching \end_inset
-def find_end_of_inset(lines, i):
- return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
-
-
-# Finds the matching \end_inset
-def find_beginning_of_inset(lines, i):
- return find_beginning_of(lines, i, "\\begin_inset", "\\end_inset")
-
-
-def find_end_of_tabular(lines, i):
- return find_end_of(lines, i, "<lyxtabular", "</lyxtabular")
-
-
-def get_tabular_lines(lines, i):
- result = []
- i = i+1
- j = find_end_of_tabular(lines, i)
- if j == -1:
- return []
-
- while i <= j:
- if check_token(lines[i], "\\begin_inset"):
- i = find_end_of_inset(lines, i)+1
- else:
- result.append(i)
- i = i+1
- return result
-
-
def is_nonempty_line(line):
return line != " "*len(line)