Skip to content

Commit ef0446e

Browse files
committed
Add script to fix Markdown files by protecting code blocks with raw tags; update multiple lesson files to include raw tags for code snippets
1 parent 568af06 commit ef0446e

75 files changed

Lines changed: 525 additions & 10 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

fix-all-liquid.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env python3
2+
import re
3+
from pathlib import Path
4+
5+
def protect_code_blocks(content):
6+
lines = content.split('\n')
7+
result = []
8+
in_code_block = False
9+
code_block_start = -1
10+
code_block_lang = None
11+
code_block_lines = []
12+
13+
i = 0
14+
while i < len(lines):
15+
line = lines[i]
16+
17+
if line.strip().startswith('```'):
18+
if in_code_block:
19+
code_block_content = '\n'.join(code_block_lines)
20+
if '{{' in code_block_content and ('|' in code_block_content or '?' in code_block_content or '===' in code_block_content or '||' in code_block_content):
21+
result.append('{% raw %}')
22+
result.append(f'```{code_block_lang}')
23+
result.extend(code_block_lines)
24+
result.append('```')
25+
result.append('{% endraw %}')
26+
else:
27+
result.append(f'```{code_block_lang}')
28+
result.extend(code_block_lines)
29+
result.append('```')
30+
31+
in_code_block = False
32+
code_block_start = -1
33+
code_block_lang = None
34+
code_block_lines = []
35+
else:
36+
in_code_block = True
37+
code_block_start = i
38+
match = re.match(r'```(\w*)', line)
39+
code_block_lang = match.group(1) if match else ''
40+
i += 1
41+
continue
42+
43+
if in_code_block:
44+
code_block_lines.append(line)
45+
else:
46+
if re.search(r'\{\{.*\|.*\}\}', line) or re.search(r'\{\{.*\?.*:.*\}\}', line) or re.search(r'\{\{.*===.*\}\}', line) or re.search(r'\{\{.*\|\|.*\}\}', line) or re.search(r'\{\{.*\+.*\}\}', line):
47+
if not (line.strip().startswith('{% raw %}') or line.strip().startswith('{% endraw %}')):
48+
if not any('{% raw %}' in l for l in result[-5:]):
49+
result.append('{% raw %}')
50+
result.append(line)
51+
if i + 1 >= len(lines) or not (re.search(r'\{\{.*\|.*\}\}', lines[i+1]) or re.search(r'\{\{.*\?.*:.*\}\}', lines[i+1]) or re.search(r'\{\{.*===.*\}\}', lines[i+1]) or re.search(r'\{\{.*\|\|.*\}\}', lines[i+1]) or re.search(r'\{\{.*\+.*\}\}', lines[i+1])):
52+
result.append('{% endraw %}')
53+
else:
54+
result.append(line)
55+
else:
56+
if any('{% raw %}' in l for l in result[-5:]) and not any('{% endraw %}' in l for l in result[-5:]):
57+
if not (re.search(r'\{\{.*\|.*\}\}', line) or re.search(r'\{\{.*\?.*:.*\}\}', line) or re.search(r'\{\{.*===.*\}\}', line) or re.search(r'\{\{.*\|\|.*\}\}', line) or re.search(r'\{\{.*\+.*\}\}', line)):
58+
result.append('{% endraw %}')
59+
result.append(line)
60+
61+
i += 1
62+
63+
if in_code_block:
64+
code_block_content = '\n'.join(code_block_lines)
65+
if '{{' in code_block_content:
66+
result.append('{% raw %}')
67+
result.append(f'```{code_block_lang}')
68+
result.extend(code_block_lines)
69+
result.append('```')
70+
result.append('{% endraw %}')
71+
else:
72+
result.append(f'```{code_block_lang}')
73+
result.extend(code_block_lines)
74+
result.append('```')
75+
76+
final_content = '\n'.join(result)
77+
78+
final_content = re.sub(r'\{% raw %\}\s*\{% raw %\}', '{% raw %}', final_content)
79+
final_content = re.sub(r'\{% endraw %\}\s*\{% endraw %\}', '{% endraw %}', final_content)
80+
81+
return final_content
82+
83+
def process_file(file_path):
84+
try:
85+
with open(file_path, 'r', encoding='utf-8') as f:
86+
content = f.read()
87+
88+
if '{{' in content:
89+
new_content = protect_code_blocks(content)
90+
if new_content != content:
91+
with open(file_path, 'w', encoding='utf-8') as f:
92+
f.write(new_content)
93+
print(f"Fixed: {file_path}")
94+
return True
95+
except Exception as e:
96+
print(f"Error processing {file_path}: {e}")
97+
98+
return False
99+
100+
def main():
101+
base_dir = Path(__file__).parent
102+
modules_dir = base_dir / 'modules'
103+
104+
if not modules_dir.exists():
105+
print(f"Modules directory not found: {modules_dir}")
106+
return
107+
108+
fixed_count = 0
109+
for md_file in modules_dir.rglob('*.md'):
110+
if process_file(md_file):
111+
fixed_count += 1
112+
113+
print(f"\nTotal files fixed: {fixed_count}")
114+
115+
if __name__ == '__main__':
116+
main()
117+

modules/module-1/lessons/exercises/lesson-1-2-exercise-5-integracao-angular.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export class ProductListComponent implements OnInit {
165165
```
166166

167167
**product-list.component.html**
168+
{% raw %}
168169
```html
169170
<div class="product-list">
170171
<h2>Lista de Produtos</h2>
@@ -192,6 +193,7 @@ export class ProductListComponent implements OnInit {
192193
</div>
193194
</div>
194195
```
196+
{% endraw %}
195197

196198
**product.service.ts** (se não existir)
197199
```typescript

modules/module-1/lessons/exercises/lesson-1-3-exercise-2-input-output.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ onClick(): void {
9494

9595
### Dica 4: Classes Dinâmicas no Template
9696

97+
{% raw %}
9798
```html
9899
<button
99100
[class.btn-primary]="variant === 'primary'"
@@ -102,6 +103,7 @@ onClick(): void {
102103
{{ label }}
103104
</button>
104105
```
106+
{% endraw %}
105107

106108
### Dica 5: Usar ngClass
107109

@@ -228,6 +230,7 @@ import { ButtonComponent } from './button/button.component';
228230
selector: 'app-root',
229231
standalone: true,
230232
imports: [ButtonComponent],
233+
{% raw %}
231234
template: `
232235
<app-button
233236
label="Clique Aqui"
@@ -251,6 +254,7 @@ import { ButtonComponent } from './button/button.component';
251254
(clicked)="onDelete()">
252255
</app-button>
253256
`
257+
{% endraw %}
254258
})
255259
export class AppComponent {
256260
isDeleting: boolean = false;

modules/module-1/lessons/exercises/lesson-1-3-exercise-3-template-avancado.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ interface User {
9090

9191
### Dica 3: Classes Condicionais
9292

93+
{% raw %}
9394
```html
9495
<button [class.following]="user.isFollowing">
9596
{{ user.isFollowing ? 'Seguindo' : 'Seguir' }}
9697
</button>
9798
```
99+
{% endraw %}
98100

99101
### Dica 4: *ngFor para Estatísticas
100102

@@ -178,6 +180,7 @@ export class UserProfileComponent {
178180
```
179181

180182
**user-profile.component.html**
183+
{% raw %}
181184
```html
182185
<div class="user-profile">
183186
<div class="profile-header">
@@ -227,6 +230,7 @@ export class UserProfileComponent {
227230
</div>
228231
</div>
229232
```
233+
{% endraw %}
230234

231235
**user-profile.component.css**
232236
```css

modules/module-1/lessons/exercises/lesson-1-3-exercise-5-ciclo-vida.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ export class LifecycleDemoComponent implements
376376
```
377377

378378
**app.component.ts** (exemplo de uso)
379+
{% raw %}
379380
```typescript
380381
import { Component } from '@angular/core';
381382
import { LifecycleDemoComponent } from './lifecycle-demo/lifecycle-demo.component';
@@ -408,6 +409,7 @@ export class AppComponent {
408409
}
409410
}
410411
```
412+
{% endraw %}
411413

412414
**Explicação da Solução**:
413415

modules/module-1/lessons/exercises/lesson-1-3-exercise-6-projecao-conteudo.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ import { CommonModule } from '@angular/common';
228228
selector: 'app-exemplo-uso',
229229
standalone: true,
230230
imports: [CardComponent, CommonModule],
231+
{% raw %}
231232
template: `
232233
<h1>Exemplos de Uso do Card Component</h1>
233234
@@ -267,6 +268,7 @@ import { CommonModule } from '@angular/common';
267268
</div>
268269
</app-card>
269270
`
271+
{% endraw %}
270272
})
271273
export class ExemploUsoComponent {
272274
lastUpdate: string = new Date().toLocaleDateString();

modules/module-1/lessons/exercises/lesson-1-4-exercise-1-two-way-binding.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export class ContactFormComponent {
159159
```
160160

161161
**contact-form.component.html**
162+
{% raw %}
162163
```html
163164
<div class="contact-form">
164165
<h2>Formulário de Contato</h2>
@@ -239,6 +240,7 @@ export class ContactFormComponent {
239240
</div>
240241
</div>
241242
```
243+
{% endraw %}
242244

243245
**contact-form.component.css**
244246
```css

modules/module-1/lessons/exercises/lesson-1-4-exercise-2-ngfor-filtros.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export class ProductListComponent implements OnInit {
175175
```
176176

177177
**product-list.component.html**
178+
{% raw %}
178179
```html
179180
<div class="product-list">
180181
<h2>Lista de Produtos</h2>
@@ -209,6 +210,7 @@ export class ProductListComponent implements OnInit {
209210
</div>
210211
</div>
211212
```
213+
{% endraw %}
212214

213215
**product-list.component.css**
214216
```css

modules/module-1/lessons/exercises/lesson-1-4-exercise-3-ngclass-dinamico.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ import { StatusComponent } from './status/status.component';
224224
selector: 'app-exemplo-uso',
225225
standalone: true,
226226
imports: [StatusComponent],
227+
{% raw %}
227228
template: `
228229
<div class="status-examples">
229230
<h2>Exemplos de Status</h2>
@@ -237,6 +238,7 @@ import { StatusComponent } from './status/status.component';
237238
<app-status status="error" label="Falha na Conexão" [showIcon]="false"></app-status>
238239
</div>
239240
`
241+
{% endraw %}
240242
})
241243
export class ExemploUsoComponent {}
242244
```

modules/module-1/lessons/exercises/lesson-1-4-exercise-4-ngstyle-dinamico.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export class ColorPickerComponent {
139139
```
140140

141141
**color-picker.component.html**
142+
{% raw %}
142143
```html
143144
<div class="color-picker">
144145
<h2>Seletor de Cores e Estilos</h2>
@@ -200,6 +201,7 @@ export class ColorPickerComponent {
200201
</div>
201202
</div>
202203
```
204+
{% endraw %}
203205

204206
**color-picker.component.css**
205207
```css

0 commit comments

Comments
 (0)