mirror of https://github.com/CGAL/cgal
add tools use to replace markups
This commit is contained in:
parent
ae159cbdf3
commit
9126c1d4d2
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
@ -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<len(words):
|
||||
word=pattern.sub('',words[i])
|
||||
res+=word
|
||||
i+=1
|
||||
if anchors.has_key(res):
|
||||
anchors[res]+=1
|
||||
res+="_"+str(anchors[res])
|
||||
else:
|
||||
anchors[res]=0
|
||||
return res
|
||||
|
||||
f=file(argv[1])
|
||||
regexp_line=re.compile('^\s*#')
|
||||
#~ regexp_section=re.compile('^\s*#\s*([ a-b().,]+)\s*#(.*)')
|
||||
regexp_section=re.compile('^\s*(#+)\s*([0-9a-zA-Z (),.:?%-`\']+[0-9a-zA-Z.?`)])\s*#+(.*)')
|
||||
regexp_anchor=re.compile('^\s*{#([0-9a-zA-Z_]+)}')
|
||||
|
||||
result=""
|
||||
diff=False
|
||||
chapter=path.abspath(argv[1]).split('/')[-2]
|
||||
for line in f.readlines():
|
||||
if regexp_line.match(line):
|
||||
m=regexp_section.search(line)
|
||||
if m:
|
||||
values=m.groups()
|
||||
anchor=''
|
||||
if len(values)==2:
|
||||
anchor=generate_anchor(chapter,values[1])
|
||||
else:
|
||||
anchor=regexp_anchor.match(values[2])
|
||||
if anchor:
|
||||
anchor=anchor.group(1)
|
||||
else:
|
||||
anchor=generate_anchor(chapter,values[1])
|
||||
if len(values[0])==1:
|
||||
result+="\section "+anchor+" "+values[1]+"\n"
|
||||
elif len(values[0])==2:
|
||||
result+="\subsection "+anchor+" "+values[1]+"\n"
|
||||
elif len(values[0])==3:
|
||||
result+="\subsubsection "+anchor+" "+values[1]+"\n"
|
||||
else:
|
||||
print "Error while processing "+argv[1]
|
||||
assert False
|
||||
diff=True
|
||||
else:
|
||||
result+=line
|
||||
else:
|
||||
result+=line
|
||||
f.close()
|
||||
|
||||
if diff:
|
||||
f=file(argv[1],'w')
|
||||
f.write(result)
|
||||
f.close()
|
||||
Loading…
Reference in New Issue