addon: warn when document has multiple prefaces (#4076)

This commit is contained in:
Frédéric Péters 2013-12-16 10:05:06 +01:00
parent 5b9b47ff25
commit 292429c6e6
1 changed files with 8 additions and 0 deletions

View File

@ -852,6 +852,8 @@ class StructureError:
return u'Les parties légistiques doivent démarrer à un niveau supérieur'
if self.type == 'preface in wrong place':
return u'La préface est placée à un mauvais endroit'
if self.type == 'two prefaces':
return u'Le document contient deux préfaces'
if self.type == 'word-copy-paste-horizontal-line':
return u'Ligne horizontale, vraisemblablement copié/collé'
if self.type == 'paragraph-filled-with-nothing-but-spaces':
@ -869,6 +871,8 @@ class StructureError:
return u'''Erreur de hiérarchie légistique. Une partie légistique ne peut démarrer au niveau section ou sous-section. Les choix possibles sont Partie, Livre, Titre ou chapitre.'''
if self.type == 'preface in wrong place':
return u'''La préface doit se trouver à la base du document ou au niveau "Partie".'''
if self.type == 'two prefaces':
return u'Une seule préface est autorisée dans le document.'
if self.type == 'word-copy-paste-horizontal-line':
return u'''Une ligne horizontale provient généralement d'un '''\
u'''copié/collé depuis Microsoft Word d'un texte '''\
@ -1008,6 +1012,7 @@ def check_structure(doc):
legistic_styles = ['Lpart', 'LLivre', 'Ltitre', 'Lchapitre', 'Lsection', 'Lsoussection']
paragraph_index = 0
seen_preface = False
while True:
error = None
currentStyle = cursor.ParaStyleName
@ -1067,6 +1072,9 @@ def check_structure(doc):
last_level = styles.index(lastStyle)
if last_level > 0:
error = StructureError('preface in wrong place')
if seen_preface:
error = StructureError('two prefaces')
seen_preface = True
if currentStyle == 'Horizontal Line':
# this is added when copy/pasting footnotes from Microsoft Word
error = StructureError('word-copy-paste-horizontal-line')