# Uncomment only what you need to import, please.
-from parser_tools import find_end_of#, find_token, find_tokens, \
+from parser_tools import find_end_of, find_token_backwards#,
+# find_token, find_tokens, \
# find_token_exact, find_end_of_inset, find_end_of_layout, \
-# find_token_backwards, is_in_inset, get_value, get_quoted_value, \
+# is_in_inset, get_value, get_quoted_value, \
# del_token, check_token, get_option_value, get_bool_value
from parser_tools import find_token, find_end_of_inset, get_value, \
- get_bool_value
+ get_bool_value, get_containing_layout
from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert
# get_ert, lyx2latex, \
"\\end_layout", ""]
+def revert_quotes(document):
+ " Revert Quote Insets in verbatim or Hebrew context to plain quotes "
+
+ # First handle verbatim insets
+ i = 0
+ j = 0
+ while i < len(document.body):
+ words = document.body[i].split()
+ if len(words) > 1 and words[0] == "\\begin_inset" and \
+ ( words[1] in ["ERT", "listings"] or words[2] == "URL" ):
+ j = find_end_of_inset(document.body, i)
+ if j == -1:
+ document.warning("Malformed LyX document: Can't find end of " + words[1] + " inset at line " + str(i))
+ i += 1
+ continue
+ while True:
+ k = find_token(document.body, '\\begin_inset Quotes', i, j)
+ if k == -1:
+ i += 1
+ break
+ l = find_end_of_inset(document.body, k)
+ if l == -1:
+ document.warning("Malformed LyX document: Can't find end of Quote inset at line " + str(k))
+ i = k
+ continue
+ replace = "\""
+ if document.body[k].endswith("s"):
+ replace = "'"
+ document.body[k:l+1] = [replace]
+ else:
+ i += 1
+ continue
+
+ # Now handle Hebrew
+ i = 0
+ j = 0
+ while True:
+ k = find_token(document.body, '\\begin_inset Quotes', i, j)
+ if k == -1:
+ return
+ l = find_end_of_inset(document.body, k)
+ if l == -1:
+ document.warning("Malformed LyX document: Can't find end of Quote inset at line " + str(k))
+ i = k
+ continue
+ hebrew = False
+ parent = get_containing_layout(document.body, k)
+ ql = find_token_backwards(document.body, "\\lang", k)
+ if ql == -1 or ql < parent[1]:
+ hebrew = document.language == "hebrew"
+ elif document.body[ql] == "\\lang hebrew":
+ hebrew = True
+ if hebrew:
+ replace = "\""
+ if document.body[k].endswith("s"):
+ replace = "'"
+ document.body[k:l+1] = [replace]
+ i += 1
+
+
+
##
# Conversion hub
#
[514, []],
[515, []],
[516, [convert_inputenc]],
+ [517, []]
]
revert = [
- [516, []],
+ [516, [revert_quotes]],
+ [515, []],
[514, [revert_urdu, revert_syriac]],
[513, [revert_amharic, revert_asturian, revert_kannada, revert_khmer]],
[512, [revert_bosnian, revert_friulan, revert_macedonian, revert_piedmontese, revert_romansh]],