|
2 | 2 |
|
3 | 3 | import re |
4 | 4 | import configparser |
| 5 | +from pathlib import Path |
5 | 6 |
|
6 | 7 |
|
7 | | -book_dir = '../capitulos/' |
8 | | -FILES = [book_dir+"/cap%02d.adoc"%i for i in range(1,25)] |
| 8 | +book_dir = Path('../online') |
| 9 | +FILES = [(book_dir / f'cap{i:02d}.adoc') for i in range(1,25)] |
| 10 | + |
| 11 | +print(book_dir) |
| 12 | +for file in FILES: |
| 13 | + print(repr(file)) |
9 | 14 |
|
10 | 15 | def find_anchors(file): |
11 | 16 | """Encontra todas as âncoras em um capítulo""" |
@@ -56,23 +61,26 @@ def find_all_xrefs(repeticao = "False"): |
56 | 61 | for file in FILES: |
57 | 62 | with open(file,"r",encoding="utf-8") as fp: |
58 | 63 | f = fp.read() |
59 | | - actual_chap = re.search(r'\[\[[\w-]+\]\]', f).group(0)[2:-2] |
60 | | - xrefs_ini += f'\n[{actual_chap}]\n' # Escreve o nome do capítulo no arquivo |
| 64 | + match = re.search(r'\[\[[\w-]+\]\]', f) |
| 65 | + if match is None: |
| 66 | + continue |
| 67 | + current_chap = match.group(0)[2:-2] |
| 68 | + xrefs_ini += f'\n[{current_chap}]\n' # Escreve o nome do capítulo no arquivo |
61 | 69 | xrefs_chap = dict() # {xref, parte} |
62 | 70 | refs = find_refs(f) |
63 | 71 | for ref in refs: |
64 | 72 | if ref in xrefs_chap and repeticao: |
65 | 73 | continue # Pula caso a referência encontrada já esteja listada |
66 | | - elif ref in anchors[actual_chap]: |
| 74 | + elif ref in anchors[current_chap]: |
67 | 75 | continue # Pula caso a referência encontrada esteja no próprio capítulo |
68 | | - elif ref in chapters and parte[ref] != parte[actual_chap]: |
| 76 | + elif ref in chapters and parte[ref] != parte[current_chap]: |
69 | 77 | # A referência encontrada é um capítulo |
70 | 78 | xrefs_chap[ref] = f'{parte[ref]}' |
71 | 79 | else: |
72 | 80 | for chapter in chapters: # Procura em cada cap pela âncora |
73 | 81 | if ref in anchors[chapter]: |
74 | 82 | # A referência encontrada é uma âncora dentro de um capítulo |
75 | | - if parte[chapter] != parte[actual_chap]: |
| 83 | + if parte[chapter] != parte[current_chap]: |
76 | 84 | xrefs_chap[ref] = f'do capítulo [[{chapter}]] da {parte[chapter]}' |
77 | 85 | break |
78 | 86 | else: |
|
0 commit comments