mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-28 16:11:24 +00:00
insert links to function definitions in html
This commit is contained in:
parent
de7c3fddec
commit
9153cb6355
@ -1,4 +1,6 @@
|
||||
all:
|
||||
rm -rf tmp
|
||||
mkdir tmp
|
||||
./update_apis.py
|
||||
./update_listings.py
|
||||
rm -rf docs_tmp
|
||||
@ -8,13 +10,14 @@ all:
|
||||
./markdown2mkdocs.py
|
||||
rm -rf docs_tmp
|
||||
mkdocs build --clean
|
||||
./mkdocs2html.py
|
||||
mkdir -p latex
|
||||
cp -r docs/picts latex
|
||||
./markdown2pdf.py
|
||||
cp btstack_gettingstarted.tex latex
|
||||
cd latex && pdflatex btstack_gettingstarted.tex && pdflatex btstack_gettingstarted.tex
|
||||
mv latex/btstack_gettingstarted.pdf btstack.pdf
|
||||
rm -rf latex
|
||||
rm -rf latex tmp
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys, yaml
|
||||
import os, re
|
||||
import sys, os, shutil
|
||||
import re, yaml
|
||||
|
||||
def insert_anchor(mdout, reference):
|
||||
mdout.write("<a name=\"" + reference + "\"></a>\n\n")
|
||||
@ -9,12 +9,6 @@ def insert_anchor(mdout, reference):
|
||||
def insert_reference(mdout, text, link):
|
||||
mdout.write("")
|
||||
|
||||
def fcopy(source_file, dest_file):
|
||||
with open(dest_file, 'w') as mdout:
|
||||
with open(source_file, 'r') as mdin:
|
||||
for line in mdin:
|
||||
mdout.write(line)
|
||||
|
||||
def process_sections(temp_file, dest_file):
|
||||
with open(dest_file, 'w') as mdout:
|
||||
with open(temp_file, 'r') as mdin:
|
||||
@ -26,7 +20,7 @@ def process_sections(temp_file, dest_file):
|
||||
else:
|
||||
mdout.write(line)
|
||||
|
||||
fcopy(dest_file, temp_file)
|
||||
shutil.copyfile(dest_file, temp_file)
|
||||
return
|
||||
|
||||
def process_figures(temp_file, dest_file):
|
||||
@ -44,7 +38,7 @@ def process_figures(temp_file, dest_file):
|
||||
md_reference = "[below](#"+figure_ref.group(2)+")"
|
||||
line = line.replace(figure_ref.group(1), md_reference)
|
||||
mdout.write(line)
|
||||
fcopy(dest_file, temp_file)
|
||||
shutil.copyfile(dest_file, temp_file)
|
||||
return
|
||||
|
||||
def process_tables(temp_file, dest_file):
|
||||
@ -62,7 +56,7 @@ def process_tables(temp_file, dest_file):
|
||||
md_reference = "[below](#"+table_ref.group(2)+")"
|
||||
line = line.replace(table_ref.group(1), md_reference)
|
||||
mdout.write(line)
|
||||
fcopy(dest_file, temp_file)
|
||||
shutil.copyfile(dest_file, temp_file)
|
||||
return
|
||||
|
||||
|
||||
@ -78,7 +72,7 @@ def process_listings(temp_file, dest_file):
|
||||
mdout.write("\n")
|
||||
else:
|
||||
mdout.write(line)
|
||||
fcopy(dest_file, temp_file)
|
||||
shutil.copyfile(dest_file, temp_file)
|
||||
return
|
||||
|
||||
|
||||
|
46
docs/manual/mkdocs2html.py
Executable file
46
docs/manual/mkdocs2html.py
Executable file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os, sys, shutil, re, pickle
|
||||
|
||||
|
||||
def writeCodeBlock(aout, code, references):
|
||||
for function_name, url in references.items():
|
||||
html_link = '<a href="' + url + '">' + function_name + '</a>'
|
||||
#print "before:" + code + "\n\n"
|
||||
code = code.replace(function_name, html_link)
|
||||
aout.write(code)
|
||||
|
||||
|
||||
def main(argv):
|
||||
html_path = "btstack/examples/examples/"
|
||||
html_tmppath = html_path + "tmp/"
|
||||
|
||||
html_in = html_path + "index.html"
|
||||
html_tmp = html_tmppath + "index.html"
|
||||
references = pickle.load(open( "tmp/references.p", "rb" ))
|
||||
|
||||
os.mkdir(html_tmppath)
|
||||
|
||||
codeblock = 0
|
||||
codeblock_end = 0
|
||||
|
||||
with open(html_in, 'r') as fin:
|
||||
with open(html_tmp, 'w') as fout:
|
||||
for line in fin:
|
||||
if not codeblock:
|
||||
fout.write(line)
|
||||
if re.match('.*<pre><code>.*',line):
|
||||
codeblock = 1
|
||||
continue
|
||||
|
||||
writeCodeBlock(fout,line, references)
|
||||
# check if codeblock ended
|
||||
if re.match('.*</code></pre>.*',line):
|
||||
codeblock = 0
|
||||
|
||||
|
||||
shutil.copyfile(html_tmp, html_in)
|
||||
shutil.rmtree(html_tmppath)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
import os, sys, getopt, re
|
||||
import os, sys, getopt, re, pickle
|
||||
|
||||
class State:
|
||||
SearchStartAPI = 0
|
||||
@ -35,12 +35,12 @@ api_header = """
|
||||
api_ending = """
|
||||
"""
|
||||
|
||||
code_ref = """[FNAME](GITHUBFPATH#LLINENR)"""
|
||||
code_ref = """GITHUBFPATH#LLINENR"""
|
||||
|
||||
|
||||
def codeReference(fname, githubfolder, filepath, linenr):
|
||||
global code_ref
|
||||
ref = code_ref.replace("FNAME",fname)
|
||||
ref = ref.replace("GITHUB", githubfolder)
|
||||
ref = code_ref.replace("GITHUB", githubfolder)
|
||||
ref = ref.replace("FPATH", filepath)
|
||||
ref = ref.replace("LINENR", str(linenr))
|
||||
return ref
|
||||
@ -80,47 +80,44 @@ def writeAPI(apifile, btstackfolder, apis, mk_codeidentation):
|
||||
continue
|
||||
|
||||
|
||||
def writeIndex(indexfile, btstackfolder, apis, githubfolder):
|
||||
def createIndex(btstackfolder, apis, githubfolder):
|
||||
global typedefs, functions
|
||||
|
||||
with open(indexfile, 'w') as fout:
|
||||
for api_tuple in apis:
|
||||
api_filename = btstackfolder + api_tuple[0]
|
||||
api_title = api_tuple[1]
|
||||
api_lable = api_tuple[2]
|
||||
for api_tuple in apis:
|
||||
api_filename = btstackfolder + api_tuple[0]
|
||||
api_title = api_tuple[1]
|
||||
api_lable = api_tuple[2]
|
||||
|
||||
linenr = 0
|
||||
with open(api_filename, 'rb') as fin:
|
||||
typedefFound = 0
|
||||
linenr = 0
|
||||
with open(api_filename, 'rb') as fin:
|
||||
typedefFound = 0
|
||||
|
||||
for line in fin:
|
||||
linenr = linenr + 1
|
||||
|
||||
typedef = re.match('.*typedef\s+struct.*', line)
|
||||
for line in fin:
|
||||
linenr = linenr + 1
|
||||
|
||||
# search typedef struct begin
|
||||
typedef = re.match('.*typedef\s+struct.*', line)
|
||||
if typedef:
|
||||
typedefFound = 1
|
||||
|
||||
# search typedef struct begin
|
||||
if typedefFound:
|
||||
typedef = re.match('}\s*(.*);\n', line)
|
||||
if typedef:
|
||||
typedefFound = 1
|
||||
continue
|
||||
typedefFound = 0
|
||||
typedefs[typedef.group(1)] = codeReference(typedef.group(1), githubfolder, api_tuple[0], linenr)
|
||||
continue
|
||||
|
||||
if typedefFound:
|
||||
typedef = re.match('}\s*(.*);\n', line)
|
||||
if typedef:
|
||||
typedefFound = 0
|
||||
typedefs[typedef.group(1)] = codeReference(typedef.group(1), githubfolder, api_tuple[0], linenr)
|
||||
fout.write(typedefs[typedef.group(1)]+"\n")
|
||||
continue
|
||||
function = re.match('.*typedef\s+void\s+\(\s*\*\s*(.*?)\)\(.*', line)
|
||||
if function:
|
||||
functions[function.group(1)] = codeReference(function.group(1), githubfolder, api_tuple[0], linenr)
|
||||
continue
|
||||
|
||||
function = re.match('.*typedef\s+void\s+\(\s*\*\s*(.*?)\)\(.*', line)
|
||||
if function:
|
||||
functions[function.group(1)] = codeReference(function.group(1), githubfolder, api_tuple[0], linenr)
|
||||
fout.write(functions[function.group(1)]+"\n")
|
||||
continue
|
||||
function = re.match('.*?\s+\*?\s*(.*?)\(.*\(*.*;', line)
|
||||
if function:
|
||||
functions[function.group(1)] = codeReference(function.group(1), githubfolder, api_tuple[0], linenr)
|
||||
continue
|
||||
|
||||
function = re.match('.*?\s+\*?\s*(.*?)\(.*\(*.*;', line)
|
||||
if function:
|
||||
|
||||
functions[function.group(1)] = codeReference(function.group(1), githubfolder, api_tuple[0], linenr)
|
||||
fout.write(functions[function.group(1)]+"\n")
|
||||
continue
|
||||
|
||||
|
||||
def main(argv):
|
||||
@ -157,7 +154,17 @@ def main(argv):
|
||||
print 'Index file is :', indexfile
|
||||
|
||||
writeAPI(apifile, btstackfolder, apis, mk_codeidentation)
|
||||
# writeIndex(indexfile, btstackfolder, apis, githubfolder)
|
||||
createIndex(btstackfolder, apis, githubfolder)
|
||||
|
||||
references = functions.copy()
|
||||
references.update(typedefs)
|
||||
|
||||
with open(indexfile, 'w') as fout:
|
||||
for function, reference in references.items():
|
||||
fout.write("[" + function + "](" + reference + ")\n")
|
||||
|
||||
|
||||
pickle.dump(references, open( "tmp/references.p", "wb" ) )
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user