From 68ef5f207c922a3bfd211ccebee0ee9d83b0ba61 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 5 Nov 2010 14:59:11 +0000 Subject: [PATCH] Improve the add_to_preamble routine. Now we really check all the lines. This is crucial, because people often do put the same sort of comment as the first line. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36110 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/lyx2lyx_tools.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/lyx2lyx/lyx2lyx_tools.py b/lib/lyx2lyx/lyx2lyx_tools.py index 24d6e1a449..bf14a5bc93 100644 --- a/lib/lyx2lyx/lyx2lyx_tools.py +++ b/lib/lyx2lyx/lyx2lyx_tools.py @@ -22,12 +22,12 @@ import string from parser_tools import find_token from unicode_symbols import unicode_reps + # This will accept either a list of lines or a single line. -# But it is bad practice to pass something with embedded -# newlines, though we will handle that. +# It is bad practice to pass something with embedded newlines, +# though we will handle that. def add_to_preamble(document, text): - """ Add text to the preamble if it is not already there. - Only the first line is checked!""" + " Add text to the preamble if it is not already there. " if not type(text) is list: # split on \n just in case @@ -35,7 +35,20 @@ def add_to_preamble(document, text): # if there's no \n, too text = text.split('\n') - if find_token(document.preamble, text[0], 0) != -1: + i = 0 + prelen = len(document.preamble) + while True: + i = find_token(document.preamble, text[0], i) + if i == -1: + break + # we need a perfect match + matched = True + for line in text: + if i >= prelen or line != document.preamble[i]: + matched = False + break + i += 1 + if matched: return document.preamble.extend(text)