3
3
import sys
4
4
import re
5
5
import os
6
+ import html
6
7
from bs4 import BeautifulSoup
7
8
8
9
# walk the combined output.
@@ -17,6 +18,31 @@ def compile_id_list(xml_content):
17
18
id_list = [x ["id" ] for x in els ]
18
19
return id_list
19
20
21
+ def insert_example_code_from_file (combined_content ):
22
+ els = combined_content .doxygen .find_all ("programlisting" )
23
+ all_examples = {}
24
+ # get the examples path
25
+ examples_path = re .sub (r"/scripts/.*+$" , "/lib/pico-examples" , os .path .realpath (__file__ ))
26
+ # get a recursive list of all files in examples
27
+ for f in os .walk (examples_path ):
28
+ for filename in f [2 ]:
29
+ if filename in all_examples :
30
+ all_examples [filename ].append (os .path .join (f [0 ], filename ))
31
+ else :
32
+ all_examples [filename ] = [os .path .join (f [0 ], filename )]
33
+ for el in els :
34
+ if el .get ("filename" ) is not None :
35
+ filename = el .get ("filename" )
36
+ # find the file here or in examples
37
+ if filename in all_examples :
38
+ with open (all_examples [filename ][0 ]) as f :
39
+ example_content = f .read ()
40
+ example_lines = example_content .split ("\n " )
41
+ for line in example_lines :
42
+ codeline = BeautifulSoup ("<codeline>" + html .escape (line )+ "</codeline>" , 'xml' )
43
+ el .append (codeline )
44
+ return combined_content
45
+
20
46
def walk_and_tag_xml_tree (el , output_contexts , all_contexts ):
21
47
"""
22
48
Process an individual xml file, adding context-specific tags as needed.
@@ -97,6 +123,7 @@ def postprocess_doxygen_xml_file(combined_xmlfile, xmlfiles, output_context_path
97
123
els = combined_content .doxygen .find_all (True , recursive = False )
98
124
for el in els :
99
125
walk_and_tag_xml_tree (el , output_contexts , list (output_context_paths .keys ()))
126
+ combined_content = insert_example_code_from_file (combined_content )
100
127
return str (combined_content )
101
128
102
129
def postprocess_doxygen_xml (xml_path ):
0 commit comments