]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyx_1_6.py
- add entry to FORMATS file for Stefan's format change (Richards to 296 change is...
[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         fullcommand = document.body[i + 2]
363         document.body[i] = "\\begin_inset Index"
364         document.body[i + 1] = "status collapsed"
365         document.body[i + 2] = "\\begin_layout standard"
366         document.body.insert(i + 3, fullcommand[6:].strip('"'))
367         document.body.insert(i + 4, "\\end_layout")
368         i = i + 5
369
370
371 def revert_latexcommand_index(document):
372     "Revert from collapsable form toLatexCommand form."
373     i = 0
374     while True:
375         i = find_token(document.body, "\\begin_inset Index", i)
376         if i == -1:
377             return
378         j = find_end_of_inset(document.body, i)
379         del document.body[j - 1]
380         del document.body[j - 2] # \end_layout
381         document.body[i] =  "\\begin_inset CommandInset index"
382         document.body[i + 1] =  "LatexCommand index"
383         document.body[i + 3] = "name " + '"' + document.body[i + 3] + '"'
384         document.body.insert(i + 4, "")
385         del document.body[i + 2] # \begin_layout standard
386         i = i + 5
387
388
389 def revert_wraptable(document):
390     "Revert wrap table to wrap figure."
391     i = 0
392     while True:
393         i = find_token(document.body, "\\begin_inset Wrap table", i)
394         if i == -1:
395             return
396         document.body[i] = document.body[i].replace('\\begin_inset Wrap table', '\\begin_inset Wrap figure')
397         i = i + 1
398
399
400 def revert_vietnamese(document):
401     "Set language Vietnamese to English"
402     # Set document language from Vietnamese to English
403     i = 0
404     if document.language == "vietnamese":
405         document.language = "english"
406         i = find_token(document.header, "\\language", 0)
407         if i != -1:
408             document.header[i] = "\\language english"
409     j = 0
410     while True:
411         j = find_token(document.body, "\\lang vietnamese", j)
412         if j == -1:
413             return
414         document.body[j] = document.body[j].replace("\\lang vietnamese", "\\lang english")
415         j = j + 1
416
417
418 def revert_japanese(document):
419     "Set language japanese-plain to japanese"
420     # Set document language from japanese-plain to japanese
421     i = 0
422     if document.language == "japanese-plain":
423         document.language = "japanese"
424         i = find_token(document.header, "\\language", 0)
425         if i != -1:
426             document.header[i] = "\\language japanese"
427     j = 0
428     while True:
429         j = find_token(document.body, "\\lang japanese-plain", j)
430         if j == -1:
431             return
432         document.body[j] = document.body[j].replace("\\lang japanese-plain", "\\lang japanese")
433         j = j + 1
434
435
436 def revert_japanese_encoding(document):
437     "Set input encoding form EUC-JP-plain to EUC-JP etc."
438     # Set input encoding form EUC-JP-plain to EUC-JP etc.
439     i = 0
440     i = find_token(document.header, "\\inputencoding EUC-JP-plain", 0)
441     if i != -1:
442         document.header[i] = "\\inputencoding EUC-JP"
443     j = 0
444     j = find_token(document.header, "\\inputencoding JIS-plain", 0)
445     if j != -1:
446         document.header[j] = "\\inputencoding JIS"
447     k = 0
448     k = find_token(document.header, "\\inputencoding SJIS-plain", 0)
449     if k != -1: # convert to UTF8 since there is currently no SJIS encoding 
450         document.header[k] = "\\inputencoding UTF8"
451
452
453 def revert_inset_info(document):
454     'Replace info inset with its content'
455     i = 0
456     while 1:
457         i = find_token(document.body, '\\begin_inset Info', i)
458         if i == -1:
459             return
460         j = find_end_of_inset(document.body, i + 1)
461         if j == -1:
462             # should not happen
463             document.warning("Malformed LyX document: Could not find end of Info inset.")
464         type = 'unknown'
465         arg = ''
466         for k in range(i, j+1):
467             if document.body[k].startswith("arg"):
468                 arg = document.body[k][3:].strip().strip('"')
469             if document.body[k].startswith("type"):
470                 type = document.body[k][4:].strip().strip('"')
471         # I think there is a newline after \\end_inset, which should be removed.
472         if document.body[j + 1].strip() == "":
473             document.body[i : (j + 2)] = [type + ':' + arg]
474         else:
475             document.body[i : (j + 1)] = [type + ':' + arg]
476
477
478 def convert_pdf_options(document):
479     # Set the pdfusetitle tag, delete the pdf_store_options,
480     # set quotes for bookmarksopenlevel"
481     has_hr = get_value(document.header, "\\use_hyperref", 0, default = "0")
482     if has_hr == "1":
483         k = find_token(document.header, "\\use_hyperref", 0)
484         document.header.insert(k + 1, "\\pdf_pdfusetitle true")
485     k = find_token(document.header, "\\pdf_store_options", 0)
486     if k != -1:
487         del document.header[k]
488     i = find_token(document.header, "\\pdf_bookmarksopenlevel", k)
489     if i == -1: return
490     document.header[i] = document.header[i].replace('"', '')
491
492
493 def revert_pdf_options_2(document):
494     # reset the pdfusetitle tag, set quotes for bookmarksopenlevel"
495     k = find_token(document.header, "\\use_hyperref", 0)
496     i = find_token(document.header, "\\pdf_pdfusetitle", k)
497     if i != -1:
498         del document.header[i]
499     i = find_token(document.header, "\\pdf_bookmarksopenlevel", k)
500     if i == -1: return
501     values = document.header[i].split()
502     values[1] = ' "' + values[1] + '"'
503     document.header[i] = ''.join(values)
504
505
506 def convert_htmlurl(document):
507     'Convert "htmlurl" to "href" insets for docbook'
508     if document.backend != "docbook":
509       return
510     i = 0
511     while True:
512       i = find_token(document.body, "\\begin_inset CommandInset url", i)
513       if i == -1:
514         return
515       document.body[i] = "\\begin_inset CommandInset href"
516       document.body[i + 1] = "LatexCommand href"
517       i = i + 1
518
519
520 def convert_url(document):
521     'Convert url insets to url charstyles'
522     if document.backend == "docbook":
523       return
524     r = re.compile(r'target\s+"(.*)"')
525     didone = False
526     i = 0
527     while True:
528       i = find_token(document.body, "\\begin_inset CommandInset url", i)
529       if i == -1:
530         break
531       j = find_token(document.body, "target", i)
532       if j == -1:
533         document.warning("Malformed LyX document: Can't find target for url inset")
534         i = j
535         continue
536       m = r.match(document.body[j])
537       target = m.group(1)
538       k = find_token(document.body, "\\end_inset", j)
539       if k == -1:
540         document.warning("Malformed LyX document: Can't find end of url inset")
541         i = k
542         continue
543       newstuff = ["\\begin_inset Flex URL",
544         "status collapsed", "", 
545         "\\begin_layout Standard",
546         target,
547         "\\end_layout",
548         ""]
549       document.body[i:k] = newstuff
550       didone = True
551       i = k
552
553     #If we did one, we need to add URL to the modules
554     if didone:
555       i = find_token(document.header, "\\begin_modules", 0)
556       if i == -1:
557         #No modules yet included
558         i = find_token(document.header, "\\textclass", 0)
559         if i == -1:
560           document.warning("Malformed LyX document: No \\textclass!!")
561           return
562         modinfo = ["\\begin_modules", "URL", "\\end_modules"]
563         document.header[i + 1: i + 1] = modinfo
564         return
565       j = find_token(document.header, "\\end_modules", i)
566       if j == -1:
567         document.warning("Malformed LyX document: No \\end_modules.")
568         return
569       k = find_token(document.header, "URL", i)
570       if k != -1 and k < j:
571         return
572       document.header.insert(i + 1, "URL")
573
574
575 def revert_href(document):
576     'Reverts hyperlink insets (href) to url insets (url)'
577     i = 0
578     while True:
579       i = find_token(document.body, "\\begin_inset CommandInset href", i)
580       if i == -1:
581           return
582       document.body[i : i + 2] = \
583         ["\\begin_inset CommandInset url", "LatexCommand url"]
584       i = i + 2
585
586
587 def convert_include(document):
588   'Converts include insets to new format.'
589   i = 0
590   r = re.compile(r'\\begin_inset Include\s+\\([^{]+){([^}]*)}(?:\[(.*)\])?')
591   while True:
592     i = find_token(document.body, "\\begin_inset Include", i)
593     if i == -1:
594       return
595     line = document.body[i]
596     previewline = document.body[i + 1]
597     m = r.match(line)
598     if m == None:
599       document.warning("Unable to match line " + str(i) + " of body!")
600       i += 1
601       continue
602     cmd = m.group(1)
603     fn  = m.group(2)
604     opt = m.group(3)
605     insertion = ["\\begin_inset CommandInset include", 
606        "LatexCommand " + cmd, previewline,
607        "filename \"" + fn + "\""]
608     newlines = 2
609     if opt:
610       insertion.append("lstparams " + '"' + opt + '"')
611       newlines += 1
612     document.body[i : i + 2] = insertion
613     i += newlines
614
615
616 def revert_include(document):
617   'Reverts include insets to old format.'
618   i = 0
619   r1 = re.compile('LatexCommand (.+)')
620   r2 = re.compile('filename (.+)')
621   r3 = re.compile('options (.*)')
622   while True:
623     i = find_token(document.body, "\\begin_inset CommandInset include", i)
624     if i == -1:
625       return
626     previewline = document.body[i + 1]
627     m = r1.match(document.body[i + 2])
628     if m == None:
629       document.warning("Malformed LyX document: No LatexCommand line for `" +
630         document.body[i] + "' on line " + str(i) + ".")
631       i += 1
632       continue
633     cmd = m.group(1)
634     m = r2.match(document.body[i + 3])
635     if m == None:
636       document.warning("Malformed LyX document: No filename line for `" + \
637         document.body[i] + "' on line " + str(i) + ".")
638       i += 2
639       continue
640     fn = m.group(1)
641     options = ""
642     numlines = 4
643     if (cmd == "lstinputlisting"):
644       m = r3.match(document.body[i + 4])
645       if m != None:
646         options = m.group(1)
647         numlines = 5
648     newline = "\\begin_inset Include \\" + cmd + "{" + fn + "}"
649     if options:
650       newline += ("[" + options + "]")
651     insertion = [newline, previewline]
652     document.body[i : i + numlines] = insertion
653     i += 2
654
655
656 def revert_albanian(document):
657     "Set language Albanian to English"
658     # Set document language from Albanian to English
659     i = 0
660     if document.language == "albanian":
661         document.language = "english"
662         i = find_token(document.header, "\\language", 0)
663         if i != -1:
664             document.header[i] = "\\language english"
665     j = 0
666     while True:
667         j = find_token(document.body, "\\lang albanian", j)
668         if j == -1:
669             return
670         document.body[j] = document.body[j].replace("\\lang albanian", "\\lang english")
671         j = j + 1
672
673
674 def revert_lowersorbian(document):
675     "Set language lower Sorbian to English"
676     # Set document language from lower Sorbian to English
677     i = 0
678     if document.language == "lowersorbian":
679         document.language = "english"
680         i = find_token(document.header, "\\language", 0)
681         if i != -1:
682             document.header[i] = "\\language english"
683     j = 0
684     while True:
685         j = find_token(document.body, "\\lang lowersorbian", j)
686         if j == -1:
687             return
688         document.body[j] = document.body[j].replace("\\lang lowersorbian", "\\lang english")
689         j = j + 1
690
691
692 def revert_uppersorbian(document):
693     "Set language uppersorbian to usorbian as this was used in LyX 1.5"
694     # Set document language from uppersorbian to usorbian
695     i = 0
696     if document.language == "uppersorbian":
697         document.language = "usorbian"
698         i = find_token(document.header, "\\language", 0)
699         if i != -1:
700             document.header[i] = "\\language usorbian"
701     j = 0
702     while True:
703         j = find_token(document.body, "\\lang uppersorbian", j)
704         if j == -1:
705             return
706         document.body[j] = document.body[j].replace("\\lang uppersorbian", "\\lang usorbian")
707         j = j + 1
708
709
710 def convert_usorbian(document):
711     "Set language uppersorbian to usorbian as this was used in LyX 1.5"
712     # Set document language from uppersorbian to usorbian
713     i = 0
714     if document.language == "usorbian":
715         document.language = "uppersorbian"
716         i = find_token(document.header, "\\language", 0)
717         if i != -1:
718             document.header[i] = "\\language uppersorbian"
719     j = 0
720     while True:
721         j = find_token(document.body, "\\lang usorbian", j)
722         if j == -1:
723             return
724         document.body[j] = document.body[j].replace("\\lang usorbian", "\\lang uppersorbian")
725         j = j + 1
726
727
728 def revert_macro_optional_params(document):
729     "Convert macro definitions with optional parameters into ERTs"
730     # Stub to convert macro definitions with one or more optional parameters
731     # into uninterpreted ERT insets
732
733
734 def revert_hyperlinktype(document):
735     'Reverts hyperlink type'
736     i = 0
737     j = 0
738     while True:
739       i = find_token(document.body, "target", i)
740       if i == -1:
741           return
742       j = find_token(document.body, "type", i)
743       if j == -1:
744           return
745       if j == i + 1:
746           del document.body[j]
747       i = i + 1
748
749
750 ##
751 # Conversion hub
752 #
753
754 supported_versions = ["1.6.0","1.6"]
755 convert = [[277, [fix_wrong_tables]],
756            [278, [close_begin_deeper]],
757            [279, [long_charstyle_names]],
758            [280, [axe_show_label]],
759            [281, []],
760            [282, []],
761            [283, [convert_flex]],
762            [284, []],
763            [285, []],
764            [286, []],
765            [287, [convert_wrapfig_options]],
766            [288, [convert_inset_command]],
767            [289, [convert_latexcommand_index]],
768            [290, []],
769            [291, []],
770            [292, []],
771            [293, []],
772            [294, [convert_pdf_options]],
773            [295, [convert_htmlurl, convert_url]],
774            [296, [convert_include]],
775            [297, [convert_usorbian]],
776            [298, []],
777            [299, []]
778           ]
779
780 revert =  [[298, [revert_hyperlinktype]],
781            [297, [revert_macro_optional_params]],
782            [296, [revert_albanian, revert_lowersorbian, revert_uppersorbian]],
783            [295, [revert_include]],
784            [294, [revert_href]],
785            [293, [revert_pdf_options_2]],
786            [292, [revert_inset_info]],
787            [291, [revert_japanese, revert_japanese_encoding]],
788            [290, [revert_vietnamese]],
789            [289, [revert_wraptable]],
790            [288, [revert_latexcommand_index]],
791            [287, [revert_inset_command]],
792            [286, [revert_wrapfig_options]],
793            [285, [revert_pdf_options]],
794            [284, [remove_inzip_options]],
795            [283, []],
796            [282, [revert_flex]],
797            [281, []],
798            [280, [revert_begin_modules]],
799            [279, [revert_show_label]],
800            [278, [revert_long_charstyle_names]],
801            [277, []],
802            [276, []]
803           ]
804
805
806 if __name__ == "__main__":
807     pass