Coverage for src/ensae_teaching_cs/homeblog/latex_helper.py: 18%

17 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-01-27 05:44 +0100

1""" 

2@file 

3@brief Various function about processing latex file 

4""" 

5import os 

6from .latex_file import LatexFile 

7 

8 

9def explore_folder_produce_code_html(files, header, footer, destination, 

10 classpre="prettyprint", classpre_type="brush: {0}", 

11 classcom="codeintro", skip_missing=False): 

12 """ 

13 Explores a list of files, extract all pieces of code and produces html page 

14 for each latex file 

15 

16 @param files list of 2uple [ (file, title) ] 

17 @param header header for html file, must contain two ``%s`` for the title (header + body) 

18 @param footer footer 

19 @param destination where to put the produced html file, name is the file with the extension replaced by .html 

20 @param classpre class for pre 

21 @param classpre_type if the type can be guessed, then this template will used instead of the first one 

22 @param classcom class for the comment 

23 @param skip_missing skip missing file (True) or raise an exception (False) 

24 @return list of produced file 

25 """ 

26 res = [] 

27 for file in files: 

28 

29 tex, title = file 

30 lat = LatexFile(tex) 

31 html = [header % (title, title)] 

32 html.append(lat.code_in_html( 

33 classpre=classpre, 

34 classpre_type=classpre_type, 

35 classcom=classcom, 

36 skip_missing=skip_missing)) 

37 html.append(footer) 

38 

39 filh = os.path.split(tex)[-1] 

40 filh = os.path.splitext(filh)[0] 

41 filh = os.path.join(destination, filh + ".html") 

42 

43 with open(filh, "w", encoding="utf8") as h: 

44 h.write("\n".join(html)) 

45 

46 res.append(filh) 

47 return res