]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyx_1_6.py
Correct conversion of math insets inside Index
[lyx.git] / lib / lyx2lyx / lyx_1_6.py
1 # This file is part of lyx2lyx
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007 José Matos <jamatos@lyx.org>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 """ Convert files to the file format generated by lyx 1.6"""
20
21 import re
22 import unicodedata
23 import sys, os
24
25 from parser_tools import find_token, find_end_of, find_tokens, get_value
26
27 ####################################################################
28 # Private helper functions
29
30 def find_end_of_inset(lines, i):
31     " Find end of inset, where lines[i] is included."
32     return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
33
34
35 ####################################################################
36
37 def fix_wrong_tables(document):
38     i = 0
39     while True:
40         i = find_token(document.body, "\\begin_inset Tabular", i)
41         if i == -1:
42             return
43         j = find_end_of_inset(document.body, i + 1)
44         if j == -1:
45             document.warning("Malformed LyX document: Could not find end of tabular.")
46             continue
47
48         m = i + 1
49         nrows = int(document.body[i+1].split('"')[3])
50         ncols = int(document.body[i+1].split('"')[5])
51
52         for l in range(nrows):
53             prev_multicolumn = 0
54             for k in range(ncols):
55                 m = find_token(document.body, '<cell', m)
56
57                 if document.body[m].find('multicolumn') != -1:
58                     multicol_cont = int(document.body[m].split('"')[1])
59
60                     if multicol_cont == 2 and (k == 0 or prev_multicolumn == 0):
61                         document.body[m] = document.body[m][:5] + document.body[m][21:]
62                         prev_multicolumn = 0
63                     else:
64                         prev_multicolumn = multicol_cont
65                 else:
66                     prev_multicolumn = 0
67
68         i = j + 1
69
70
71 def close_begin_deeper(document):
72     i = 0
73     depth = 0
74     while True:
75         i = find_tokens(document.body, ["\\begin_deeper", "\\end_deeper"], i)
76
77         if i == -1:
78             break
79
80         if document.body[i][:13] == "\\begin_deeper":
81             depth += 1
82         else:
83             depth -= 1
84
85         i += 1
86
87     document.body[-2:-2] = ['\\end_deeper' for i in range(depth)]
88
89
90 def long_charstyle_names(document):
91     i = 0
92     while True:
93         i = find_token(document.body, "\\begin_inset CharStyle", i)
94         if i == -1:
95             return
96         document.body[i] = document.body[i].replace("CharStyle ", "CharStyle CharStyle:")
97         i += 1
98
99 def revert_long_charstyle_names(document):
100     i = 0
101     while True:
102         i = find_token(document.body, "\\begin_inset CharStyle", i)
103         if i == -1:
104             return
105         document.body[i] = document.body[i].replace("CharStyle CharStyle:", "CharStyle")
106         i += 1
107
108
109 def axe_show_label(document):
110     i = 0
111     while True:
112         i = find_token(document.body, "\\begin_inset CharStyle", i)
113         if i == -1:
114             return
115         if document.body[i + 1].find("show_label") != -1:
116             if document.body[i + 1].find("true") != -1:
117                 document.body[i + 1] = "status open"
118                 del document.body[ i + 2]
119             else:
120                 if document.body[i + 1].find("false") != -1:
121                     document.body[i + 1] = "status collapsed"
122                     del document.body[ i + 2]
123                 else:
124                     document.warning("Malformed LyX document: show_label neither false nor true.")
125         else:
126             document.warning("Malformed LyX document: show_label missing in CharStyle.")
127             
128         i += 1
129
130
131 def revert_show_label(document):
132     i = 0
133     while True:
134         i = find_token(document.body, "\\begin_inset CharStyle", i)
135         if i == -1:
136             return
137         if document.body[i + 1].find("status open") != -1:
138             document.body.insert(i + 1, "show_label true")
139         else:
140             if document.body[i + 1].find("status collapsed") != -1:
141                 document.body.insert(i + 1, "show_label false")
142             else:
143                 document.warning("Malformed LyX document: no legal status line in CharStyle.")
144         i += 1
145
146 def revert_begin_modules(document):
147     i = 0
148     while True:
149         i = find_token(document.header, "\\begin_modules", i)
150         if i == -1:
151             return
152         j = find_end_of(document.header, i, "\\begin_modules", "\\end_modules")
153         if j == -1:
154             # this should not happen
155             break
156         document.header[i : j + 1] = []
157
158 def convert_flex(document):
159     "Convert CharStyle to Flex"
160     i = 0
161     while True:
162         i = find_token(document.body, "\\begin_inset CharStyle", i)
163         if i == -1:
164             return
165         document.body[i] = document.body[i].replace('\\begin_inset CharStyle', '\\begin_inset Flex')
166
167 def revert_flex(document):
168     "Convert Flex to CharStyle"
169     i = 0
170     while True:
171         i = find_token(document.body, "\\begin_inset Flex", i)
172         if i == -1:
173             return
174         document.body[i] = document.body[i].replace('\\begin_inset Flex', '\\begin_inset CharStyle')
175
176
177 #  Discard PDF options for hyperref
178 def revert_pdf_options(document):
179         "Revert PDF options for hyperref."
180         i = 0
181         i = find_token(document.header, "\\use_hyperref", i)
182         if i != -1:
183             del document.header[i]
184         i = find_token(document.header, "\\pdf_store_options", i)
185         if i != -1:
186             del document.header[i]
187         i = find_token(document.header, "\\pdf_title", 0)
188         if i != -1:
189             del document.header[i]
190         i = find_token(document.header, "\\pdf_author", 0)
191         if i != -1:
192             del document.header[i]
193         i = find_token(document.header, "\\pdf_subject", 0)
194         if i != -1:
195             del document.header[i]
196         i = find_token(document.header, "\\pdf_keywords", 0)
197         if i != -1:
198             del document.header[i]
199         i = find_token(document.header, "\\pdf_bookmarks", 0)
200         if i != -1:
201             del document.header[i]
202         i = find_token(document.header, "\\pdf_bookmarksnumbered", i)
203         if i != -1:
204             del document.header[i]
205         i = find_token(document.header, "\\pdf_bookmarksopen", i)
206         if i != -1:
207             del document.header[i]
208         i = find_token(document.header, "\\pdf_bookmarksopenlevel", i)
209         if i != -1:
210             del document.header[i]
211         i = find_token(document.header, "\\pdf_breaklinks", i)
212         if i != -1:
213             del document.header[i]
214         i = find_token(document.header, "\\pdf_pdfborder", i)
215         if i != -1:
216             del document.header[i]
217         i = find_token(document.header, "\\pdf_colorlinks", i)
218         if i != -1:
219             del document.header[i]
220         i = find_token(document.header, "\\pdf_backref", i)
221         if i != -1:
222             del document.header[i]
223         i = find_token(document.header, "\\pdf_pagebackref", i)
224         if i != -1:
225             del document.header[i]
226         i = find_token(document.header, "\\pdf_pagemode", 0)
227         if i != -1:
228             del document.header[i]
229         i = find_token(document.header, "\\pdf_quoted_options", 0)
230         if i != -1:
231             del document.header[i]
232
233
234 def remove_inzip_options(document):
235     "Remove inzipName and embed options from the Graphics inset"
236     i = 0
237     while 1:
238         i = find_token(document.body, "\\begin_inset Graphics", i)
239         if i == -1:
240             return
241         j = find_end_of_inset(document.body, i + 1)
242         if j == -1:
243             # should not happen
244             document.warning("Malformed LyX document: Could not find end of graphics inset.")
245         # If there's a inzip param, just remove that
246         k = find_token(document.body, "\tinzipName", i + 1, j)
247         if k != -1:
248             del document.body[k]
249             # embed option must follow the inzipName option
250             del document.body[k+1]
251         i = i + 1
252
253
254 def convert_inset_command(document):
255     """
256         Convert:
257             \begin_inset LatexCommand cmd 
258         to 
259             \begin_inset CommandInset InsetType
260             LatexCommand cmd
261     """
262     i = 0
263     while 1:
264         i = find_token(document.body, "\\begin_inset LatexCommand", i)
265         if i == -1:
266             return
267         line = document.body[i]
268         r = re.compile(r'\\begin_inset LatexCommand (.*)$')
269         m = r.match(line)
270         cmdName = m.group(1)
271         insetName = ""
272         #this is adapted from factory.cpp
273         if cmdName[0:4].lower() == "cite":
274             insetName = "citation"
275         elif cmdName == "url" or cmdName == "htmlurl":
276             insetName = "url"
277         elif cmdName[-3:] == "ref":
278             insetName = "ref"
279         elif cmdName == "tableofcontents":
280             insetName = "toc"
281         elif cmdName == "printnomenclature":
282             insetName = "nomencl_print"
283         elif cmdName == "printindex":
284             insetName = "index_print"
285         else:
286             insetName = cmdName
287         insertion = ["\\begin_inset CommandInset " + insetName, "LatexCommand " + cmdName]
288         document.body[i : i+1] = insertion
289
290
291 def revert_inset_command(document):
292     """
293         Convert:
294             \begin_inset CommandInset InsetType
295             LatexCommand cmd
296         to 
297             \begin_inset LatexCommand cmd 
298         Some insets may end up being converted to insets earlier versions of LyX
299         will not be able to recognize. Not sure what to do about that.
300     """
301     i = 0
302     while 1:
303         i = find_token(document.body, "\\begin_inset CommandInset", i)
304         if i == -1:
305             return
306         nextline = document.body[i+1]
307         r = re.compile(r'LatexCommand\s+(.*)$')
308         m = r.match(nextline)
309         if not m:
310             document.warning("Malformed LyX document: Missing LatexCommand in " + document.body[i] + ".")
311             continue
312         cmdName = m.group(1)
313         insertion = ["\\begin_inset LatexCommand " + cmdName]
314         document.body[i : i+2] = insertion
315
316
317 def convert_wrapfig_options(document):
318     "Convert optional options for wrap floats (wrapfig)."
319     # adds the tokens "lines", "placement", and "overhang"
320     i = 0
321     while True:
322         i = find_token(document.body, "\\begin_inset Wrap figure", i)
323         if i == -1:
324             return
325         document.body.insert(i + 1, "lines 0")
326         j = find_token(document.body, "placement", i)
327         # placement can be already set or not; if not, set it
328         if j == i+2:
329             document.body.insert(i + 3, "overhang 0col%")
330         else:
331            document.body.insert(i + 2, "placement o")
332            document.body.insert(i + 3, "overhang 0col%")
333         i = i + 1
334
335
336 def revert_wrapfig_options(document):
337     "Revert optional options for wrap floats (wrapfig)."
338     i = 0
339     while True:
340         i = find_token(document.body, "lines", i)
341         if i == -1:
342             return
343         j = find_token(document.body, "overhang", i+1)
344         if j != i + 2 and j != -1:
345             document.warning("Malformed LyX document: Couldn't find overhang parameter of wrap float.")
346         if j == -1:
347             return
348         del document.body[i]
349         del document.body[j-1]
350         i = i + 1
351
352
353 def convert_latexcommand_index(document):
354     "Convert from LatexCommand form to collapsable form."
355     i = 0 
356     while True:
357         i = find_token(document.body, "\\begin_inset CommandInset index", i)
358         if i == -1:
359             return
360         if document.body[i + 1] != "LatexCommand index": # Might also be index_print
361             return
362         fullcontent = document.body[i + 2][6:].strip('"')
363         document.body[i:i + 2] = ["\\begin_inset Index",
364           "status collapsed",
365           "\\begin_layout standard"]
366         # Put here the conversions needed from LaTeX string
367         # to LyXText:
368         # Math:
369         r = re.compile('^(.*?)(\$.*?\$)(.*)')
370         g = fullcontent
371         while r.match(g):
372           m = r.match(g)
373           s = m.group(1)
374           f = m.group(2).replace('\\\\', '\\')
375           g = m.group(3)
376           if s:
377             document.body.insert(i + 3, s)
378             i += 1
379           document.body.insert(i + 3, "\\begin_inset Formula " + f)
380           document.body.insert(i + 4, "\\end_inset")
381           i += 2
382         document.body.insert(i + 3, g)
383         document.body[i + 4] = "\\end_layout"
384         i = i + 5
385
386
387 def revert_latexcommand_index(document):
388     "Revert from collapsable form toLatexCommand form."
389     i = 0
390     while True:
391         i = find_token(document.body, "\\begin_inset Index", i)
392         if i == -1:
393             return
394         j = find_end_of_inset(document.body, i)
395         del document.body[j - 1]
396         del document.body[j - 2] # \end_layout
397         document.body[i] =  "\\begin_inset CommandInset index"
398         document.body[i + 1] =  "LatexCommand index"
399         document.body[i + 3] = "name " + '"' + document.body[i + 3] + '"'
400         document.body.insert(i + 4, "")
401         del document.body[i + 2] # \begin_layout standard
402         i = i + 5
403
404
405 def revert_wraptable(document):
406     "Revert wrap table to wrap figure."
407     i = 0
408     while True:
409         i = find_token(document.body, "\\begin_inset Wrap table", i)
410         if i == -1:
411             return
412         document.body[i] = document.body[i].replace('\\begin_inset Wrap table', '\\begin_inset Wrap figure')
413         i = i + 1
414
415
416 def revert_vietnamese(document):
417     "Set language Vietnamese to English"
418     # Set document language from Vietnamese to English
419     i = 0
420     if document.language == "vietnamese":
421         document.language = "english"
422         i = find_token(document.header, "\\language", 0)
423         if i != -1:
424             document.header[i] = "\\language english"
425     j = 0
426     while True:
427         j = find_token(document.body, "\\lang vietnamese", j)
428         if j == -1:
429             return
430         document.body[j] = document.body[j].replace("\\lang vietnamese", "\\lang english")
431         j = j + 1
432
433
434 def revert_japanese(document):
435     "Set language japanese-plain to japanese"
436     # Set document language from japanese-plain to japanese
437     i = 0
438     if document.language == "japanese-plain":
439         document.language = "japanese"
440         i = find_token(document.header, "\\language", 0)
441         if i != -1:
442             document.header[i] = "\\language japanese"
443     j = 0
444     while True:
445         j = find_token(document.body, "\\lang japanese-plain", j)
446         if j == -1:
447             return
448         document.body[j] = document.body[j].replace("\\lang japanese-plain", "\\lang japanese")
449         j = j + 1
450
451
452 def revert_japanese_encoding(document):
453     "Set input encoding form EUC-JP-plain to EUC-JP etc."
454     # Set input encoding form EUC-JP-plain to EUC-JP etc.
455     i = 0
456     i = find_token(document.header, "\\inputencoding EUC-JP-plain", 0)
457     if i != -1:
458         document.header[i] = "\\inputencoding EUC-JP"
459     j = 0
460     j = find_token(document.header, "\\inputencoding JIS-plain", 0)
461     if j != -1:
462         document.header[j] = "\\inputencoding JIS"
463     k = 0
464     k = find_token(document.header, "\\inputencoding SJIS-plain", 0)
465     if k != -1: # convert to UTF8 since there is currently no SJIS encoding 
466         document.header[k] = "\\inputencoding UTF8"
467
468
469 def revert_inset_info(document):
470     'Replace info inset with its content'
471     i = 0
472     while 1:
473         i = find_token(document.body, '\\begin_inset Info', i)
474         if i == -1:
475             return
476         j = find_end_of_inset(document.body, i + 1)
477         if j == -1:
478             # should not happen
479             document.warning("Malformed LyX document: Could not find end of Info inset.")
480         type = 'unknown'
481         arg = ''
482         for k in range(i, j+1):
483             if document.body[k].startswith("arg"):
484                 arg = document.body[k][3:].strip().strip('"')
485             if document.body[k].startswith("type"):
486                 type = document.body[k][4:].strip().strip('"')
487         # I think there is a newline after \\end_inset, which should be removed.
488         if document.body[j + 1].strip() == "":
489             document.body[i : (j + 2)] = [type + ':' + arg]
490         else:
491             document.body[i : (j + 1)] = [type + ':' + arg]
492
493
494 def convert_pdf_options(document):
495     # Set the pdfusetitle tag, delete the pdf_store_options,
496     # set quotes for bookmarksopenlevel"
497     has_hr = get_value(document.header, "\\use_hyperref", 0, default = "0")
498     if has_hr == "1":
499         k = find_token(document.header, "\\use_hyperref", 0)
500         document.header.insert(k + 1, "\\pdf_pdfusetitle true")
501     k = find_token(document.header, "\\pdf_store_options", 0)
502     if k != -1:
503         del document.header[k]
504     i = find_token(document.header, "\\pdf_bookmarksopenlevel", k)
505     if i == -1: return
506     document.header[i] = document.header[i].replace('"', '')
507
508
509 def revert_pdf_options_2(document):
510     # reset the pdfusetitle tag, set quotes for bookmarksopenlevel"
511     k = find_token(document.header, "\\use_hyperref", 0)
512     i = find_token(document.header, "\\pdf_pdfusetitle", k)
513     if i != -1:
514         del document.header[i]
515     i = find_token(document.header, "\\pdf_bookmarksopenlevel", k)
516     if i == -1: return
517     values = document.header[i].split()
518     values[1] = ' "' + values[1] + '"'
519     document.header[i] = ''.join(values)
520
521
522 def convert_htmlurl(document):
523     'Convert "htmlurl" to "href" insets for docbook'
524     if document.backend != "docbook":
525       return
526     i = 0
527     while True:
528       i = find_token(document.body, "\\begin_inset CommandInset url", i)
529       if i == -1:
530         return
531       document.body[i] = "\\begin_inset CommandInset href"
532       document.body[i + 1] = "LatexCommand href"
533       i = i + 1
534
535
536 def convert_url(document):
537     'Convert url insets to url charstyles'
538     if document.backend == "docbook":
539       return
540     i = 0
541     while True:
542       i = find_token(document.body, "\\begin_inset CommandInset url", i)
543       if i == -1:
544         break
545       n = find_token(document.body, "name", i)
546       if n == i + 2:
547         # place the URL name in typewriter before the new URL insert
548         # grab the name 'bla' from the e.g. the line 'name "bla"',
549         # therefore start with the 6th character
550         name = document.body[n][6:-1]
551         newname = [name + " "]
552         document.body[i:i] = newname
553         i = i + 1
554       j = find_token(document.body, "target", i)
555       if j == -1:
556         document.warning("Malformed LyX document: Can't find target for url inset")
557         i = j
558         continue
559       target = document.body[j][8:-1]
560       k = find_token(document.body, "\\end_inset", j)
561       if k == -1:
562         document.warning("Malformed LyX document: Can't find end of url inset")
563         i = k
564         continue
565       newstuff = ["\\begin_inset Flex URL",
566         "status collapsed", "", 
567         "\\begin_layout Standard",
568         "",
569         target,
570         "\\end_layout",
571         ""]
572       document.body[i:k] = newstuff
573       i = k
574
575
576 def revert_href(document):
577     'Reverts hyperlink insets (href) to url insets (url)'
578     i = 0
579     while True:
580       i = find_token(document.body, "\\begin_inset CommandInset href", i)
581       if i == -1:
582           return
583       document.body[i : i + 2] = \
584         ["\\begin_inset CommandInset url", "LatexCommand url"]
585       i = i + 2
586
587
588 def convert_include(document):
589   'Converts include insets to new format.'
590   i = 0
591   r = re.compile(r'\\begin_inset Include\s+\\([^{]+){([^}]*)}(?:\[(.*)\])?')
592   while True:
593     i = find_token(document.body, "\\begin_inset Include", i)
594     if i == -1:
595       return
596     line = document.body[i]
597     previewline = document.body[i + 1]
598     m = r.match(line)
599     if m == None:
600       document.warning("Unable to match line " + str(i) + " of body!")
601       i += 1
602       continue
603     cmd = m.group(1)
604     fn  = m.group(2)
605     opt = m.group(3)
606     insertion = ["\\begin_inset CommandInset include", 
607        "LatexCommand " + cmd, previewline,
608        "filename \"" + fn + "\""]
609     newlines = 2
610     if opt:
611       insertion.append("lstparams " + '"' + opt + '"')
612       newlines += 1
613     document.body[i : i + 2] = insertion
614     i += newlines
615
616
617 def revert_include(document):
618   'Reverts include insets to old format.'
619   i = 0
620   r1 = re.compile('LatexCommand (.+)')
621   r2 = re.compile('filename (.+)')
622   r3 = re.compile('options (.*)')
623   while True:
624     i = find_token(document.body, "\\begin_inset CommandInset include", i)
625     if i == -1:
626       return
627     previewline = document.body[i + 1]
628     m = r1.match(document.body[i + 2])
629     if m == None:
630       document.warning("Malformed LyX document: No LatexCommand line for `" +
631         document.body[i] + "' on line " + str(i) + ".")
632       i += 1
633       continue
634     cmd = m.group(1)
635     m = r2.match(document.body[i + 3])
636     if m == None:
637       document.warning("Malformed LyX document: No filename line for `" + \
638         document.body[i] + "' on line " + str(i) + ".")
639       i += 2
640       continue
641     fn = m.group(1)
642     options = ""
643     numlines = 4
644     if (cmd == "lstinputlisting"):
645       m = r3.match(document.body[i + 4])
646       if m != None:
647         options = m.group(1)
648         numlines = 5
649     newline = "\\begin_inset Include \\" + cmd + "{" + fn + "}"
650     if options:
651       newline += ("[" + options + "]")
652     insertion = [newline, previewline]
653     document.body[i : i + numlines] = insertion
654     i += 2
655
656
657 def revert_albanian(document):
658     "Set language Albanian to English"
659     # Set document language from Albanian to English
660     i = 0
661     if document.language == "albanian":
662         document.language = "english"
663         i = find_token(document.header, "\\language", 0)
664         if i != -1:
665             document.header[i] = "\\language english"
666     j = 0
667     while True:
668         j = find_token(document.body, "\\lang albanian", j)
669         if j == -1:
670             return
671         document.body[j] = document.body[j].replace("\\lang albanian", "\\lang english")
672         j = j + 1
673
674
675 def revert_lowersorbian(document):
676     "Set language lower Sorbian to English"
677     # Set document language from lower Sorbian to English
678     i = 0
679     if document.language == "lowersorbian":
680         document.language = "english"
681         i = find_token(document.header, "\\language", 0)
682         if i != -1:
683             document.header[i] = "\\language english"
684     j = 0
685     while True:
686         j = find_token(document.body, "\\lang lowersorbian", j)
687         if j == -1:
688             return
689         document.body[j] = document.body[j].replace("\\lang lowersorbian", "\\lang english")
690         j = j + 1
691
692
693 def revert_uppersorbian(document):
694     "Set language uppersorbian to usorbian as this was used in LyX 1.5"
695     # Set document language from uppersorbian to usorbian
696     i = 0
697     if document.language == "uppersorbian":
698         document.language = "usorbian"
699         i = find_token(document.header, "\\language", 0)
700         if i != -1:
701             document.header[i] = "\\language usorbian"
702     j = 0
703     while True:
704         j = find_token(document.body, "\\lang uppersorbian", j)
705         if j == -1:
706             return
707         document.body[j] = document.body[j].replace("\\lang uppersorbian", "\\lang usorbian")
708         j = j + 1
709
710
711 def convert_usorbian(document):
712     "Set language uppersorbian to usorbian as this was used in LyX 1.5"
713     # Set document language from uppersorbian to usorbian
714     i = 0
715     if document.language == "usorbian":
716         document.language = "uppersorbian"
717         i = find_token(document.header, "\\language", 0)
718         if i != -1:
719             document.header[i] = "\\language uppersorbian"
720     j = 0
721     while True:
722         j = find_token(document.body, "\\lang usorbian", j)
723         if j == -1:
724             return
725         document.body[j] = document.body[j].replace("\\lang usorbian", "\\lang uppersorbian")
726         j = j + 1
727
728
729 def revert_macro_optional_params(document):
730     "Convert macro definitions with optional parameters into ERTs"
731     # Stub to convert macro definitions with one or more optional parameters
732     # into uninterpreted ERT insets
733
734
735 def revert_hyperlinktype(document):
736     'Reverts hyperlink type'
737     i = 0
738     j = 0
739     while True:
740       i = find_token(document.body, "target", i)
741       if i == -1:
742           return
743       j = find_token(document.body, "type", i)
744       if j == -1:
745           return
746       if j == i + 1:
747           del document.body[j]
748       i = i + 1
749
750
751 ##
752 # Conversion hub
753 #
754
755 supported_versions = ["1.6.0","1.6"]
756 convert = [[277, [fix_wrong_tables]],
757            [278, [close_begin_deeper]],
758            [279, [long_charstyle_names]],
759            [280, [axe_show_label]],
760            [281, []],
761            [282, []],
762            [283, [convert_flex]],
763            [284, []],
764            [285, []],
765            [286, []],
766            [287, [convert_wrapfig_options]],
767            [288, [convert_inset_command]],
768            [289, [convert_latexcommand_index]],
769            [290, []],
770            [291, []],
771            [292, []],
772            [293, []],
773            [294, [convert_pdf_options]],
774            [295, [convert_htmlurl, convert_url]],
775            [296, [convert_include]],
776            [297, [convert_usorbian]],
777            [298, []],
778            [299, []]
779           ]
780
781 revert =  [[298, [revert_hyperlinktype]],
782            [297, [revert_macro_optional_params]],
783            [296, [revert_albanian, revert_lowersorbian, revert_uppersorbian]],
784            [295, [revert_include]],
785            [294, [revert_href]],
786            [293, [revert_pdf_options_2]],
787            [292, [revert_inset_info]],
788            [291, [revert_japanese, revert_japanese_encoding]],
789            [290, [revert_vietnamese]],
790            [289, [revert_wraptable]],
791            [288, [revert_latexcommand_index]],
792            [287, [revert_inset_command]],
793            [286, [revert_wrapfig_options]],
794            [285, [revert_pdf_options]],
795            [284, [remove_inzip_options]],
796            [283, []],
797            [282, [revert_flex]],
798            [281, []],
799            [280, [revert_begin_modules]],
800            [279, [revert_show_label]],
801            [278, [revert_long_charstyle_names]],
802            [277, []],
803            [276, []]
804           ]
805
806
807 if __name__ == "__main__":
808     pass