-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml-table-to-bbcode.py
23 lines (18 loc) · 1.03 KB
/
html-table-to-bbcode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
import re
import sys
html_contents = sys.stdin.read()
html_contents = re.sub(r'^.*?<table', r'<table', html_contents, flags=re.DOTALL)
html_contents = re.sub(r'^(.*)</table>.*?$', r'\1</table>', html_contents, flags=re.DOTALL)
html_contents = re.sub(r'</table>.+?<table', r'</table>\n<table', html_contents, flags=re.DOTALL)
html_contents = re.sub(r'<table[^>]*>', r'[table]', html_contents)
html_contents = re.sub(r'</table[^>]*>', r'[/table]', html_contents)
html_contents = re.sub(r'^\s*</?thead>$', r'', html_contents, flags=re.MULTILINE)
html_contents = re.sub(r'^\s*</?tbody>$', r'', html_contents, flags=re.MULTILINE)
html_contents = re.sub(r'<th[^>]*>', r'[td][b]', html_contents)
html_contents = re.sub(r'</th[^>]*>', r'[/b][/td]', html_contents)
html_contents = re.sub(r'<tr[^>]*>', r'[tr]', html_contents)
html_contents = re.sub(r'</tr[^>]*>', r'[/tr]', html_contents)
html_contents = re.sub(r'<td[^>]*>', r'[td]', html_contents)
html_contents = re.sub(r'</td[^>]*>', r'[/td]', html_contents)
print(html_contents)