lyx_mirror/lib/lyx2lyx/lyx_2_4.py
Juergen Spitzmueller e0a5babde7 Add literal param to InsetInclude
This is used by lstinput

File format change.

Fixes: #10544.
2018-02-23 08:58:16 +01:00

106 lines
3.3 KiB
Python

# -*- coding: utf-8 -*-
# This file is part of lyx2lyx
# Copyright (C) 2018 The LyX team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" Convert files to the file format generated by lyx 2.4"""
import re, string
import unicodedata
import sys, os
# Uncomment only what you need to import, please.
from parser_tools import (find_end_of_inset, find_token)
# del_token, del_value, del_complete_lines,
# find_complete_lines, find_end_of, find_end_of_layout,
# find_re, find_substring, find_token_backwards,
# get_containing_inset, get_containing_layout, get_bool_value, get_value,
# get_quoted_value, is_in_inset, set_bool_value
# find_tokens, find_token_exact, check_token, get_option_value
#from lyx2lyx_tools import (add_to_preamble, put_cmd_in_ert, revert_font_attrs,
# insert_to_preamble, latex_length)
# get_ert, lyx2latex, lyx2verbatim, length_in_bp, convert_info_insets
# revert_flex_inset, hex2ratio, str2bool
####################################################################
# Private helper functions
###############################################################################
###
### Conversion and reversion routines
###
###############################################################################
def convert_lst_literalparam(document):
" Add param literal to include inset "
i = 0
while True:
i = find_token(document.body, '\\begin_inset CommandInset include', i)
if i == -1:
break
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: Can't find end of command inset at line %d" % i)
i += 1
continue
while i < j and document.body[i].strip() != '':
i += 1
document.body.insert(i, "literal \"true\"")
def revert_lst_literalparam(document):
" Remove param literal from include inset "
i = 0
while True:
i = find_token(document.body, '\\begin_inset CommandInset include', i)
if i == -1:
break
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: Can't find end of include inset at line %d" % i)
i += 1
continue
k = find_token(document.body, 'literal', i, j)
if k == -1:
i += 1
continue
del document.body[k]
##
# Conversion hub
#
supported_versions = ["2.4.0", "2.4"]
convert = [
[545, [convert_lst_literalparam]]
]
revert = [
[544, [revert_lst_literalparam]]
]
if __name__ == "__main__":
pass