From 9126c1d4d2d25a7d984525f95d7ece7a2103b00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 6 Nov 2012 22:06:04 +0000 Subject: [PATCH] add tools use to replace markups --- .gitattributes | 2 + .../check_duplicated_section_anchor.py | 21 ++++++ .../conversion_tools/markup_replacement.py | 72 +++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 Documentation/conversion_tools/check_duplicated_section_anchor.py create mode 100644 Documentation/conversion_tools/markup_replacement.py diff --git a/.gitattributes b/.gitattributes index d9fdb64f421..edf568ed329 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2313,6 +2313,8 @@ Documentation/biblio/how_to_cite_cgal.txt -text Documentation/biblio/makebiblio -text Documentation/cgal_stylesheet.css -text Documentation/conceptify.py -text +Documentation/conversion_tools/check_duplicated_section_anchor.py -text +Documentation/conversion_tools/markup_replacement.py -text Documentation/doc/Developer_manual/Chapter_checks.txt -text Documentation/doc/Developer_manual/Chapter_code_format.txt -text Documentation/doc/Developer_manual/Chapter_debugging.txt -text diff --git a/Documentation/conversion_tools/check_duplicated_section_anchor.py b/Documentation/conversion_tools/check_duplicated_section_anchor.py new file mode 100644 index 00000000000..1541c6e8d07 --- /dev/null +++ b/Documentation/conversion_tools/check_duplicated_section_anchor.py @@ -0,0 +1,21 @@ +#!/usr/bin/python2 + +#checks whether there is a duplicated anchor name used in \section, \subsection or \subsubsection + +from sys import argv +import re + +anchors={} + +pattern=re.compile("\\\(sub)?(sub)?section\s+(\w*)") + +for i in range(0,len(argv)): + f=file(argv[i]) + for line in f.readlines(): + res=pattern.search(line) + if res: + key=res.groups()[-1] + if anchors.has_key(key): + print anchors[key],":",key, "in", argv[i] + else: + anchors[key]=argv[i] \ No newline at end of file diff --git a/Documentation/conversion_tools/markup_replacement.py b/Documentation/conversion_tools/markup_replacement.py new file mode 100644 index 00000000000..5e85977a407 --- /dev/null +++ b/Documentation/conversion_tools/markup_replacement.py @@ -0,0 +1,72 @@ +#!/usr/bin/python2 + +#replace markup #, ## ,### by \section, \subsection, \subsubsection. +#anchor names are preserved and generated from the section name otherwise +#The script is not perfect and might miss some specific cases + +from sys import argv +from os import path +import string +import re + +anchors={} + +def generate_anchor(chapter,text): + pattern = re.compile('[\W_]+') + words=text.split() + i=1; + res=chapter+pattern.sub('',words[0]) + while len(res)<40 and i