PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/extras/unhtml.vim

http://txt2tags.googlecode.com/
Vim Script | 95 lines | 88 code | 7 blank | 0 comment | 0 complexity | 5aefa158d798e1927c831221845785bf MD5 | raw file
 1" unhtml.vim - by Aurelio Jargas
 2" - Converts HTML tags into txt2tags marks
 3" - Part of the txt2tags <http://txt2tags.org> software
 4"
 5" INSTRUCTIONS
 6"   1. Open the HTML file on Vim and execute
 7"        :so /path/to/unhtml.vim
 8"
 9"   2. A new <yourfile>.html.t2t will be saved.
10"
11"   3. Check the new .t2t file and correct by hand what has left.
12"
13
14""" [ preparing ]
15" ignore case
16set ic
17" join multiline tags
18g/<\s*\([ap]\|img\)\s*$/join
19g/<\s*a\s[^>]*>[^<]*$/join
20
21
22""" [ do it! ]
23" link
24%s,<\s*a\s[^>]*href="\(.\{-}\)"[^>]*>\(.\{-}\)<\/a>,[\2 \1],ge
25%s,<\s*a\s[^>]*href=\([^ >]\+\)[^>]*>\(.\{-}\)<\/a>,[\2 \1],ge
26" images
27%s,<\s*img\s[^>]*src="\(.\{-}\)"[^>]*>,[\1],ge
28%s,<\s*img\s[^>]*src=\([^ >]\+\)[^>]*>,[\1],ge
29" anchor
30%s,^<\s*a\s\+name=.\{-}>\(.*\)<\/a>,== \1 ==,ge
31" comments
32%s,\s*<!--\(.*\)-->,\% \1,ge
33
34/<!--/,/-->/s,^,\% ,e
35" paragraph
36%s,<\s*p\(\s[^>]*\)\=\s*>,
37,ge
38" bar
39%s,<\s*hr[^>]*>,-------------------------------------------------,ge
40" title
41%s,</\=\s*h1\s*>,=,ge
42%s,</\=\s*h2\s*>,==,ge
43%s,</\=\s*h3\s*>,===,ge
44%s,</\=\s*h4\s*>,====,ge
45%s,</\=\s*h5\s*>,=====,ge
46%s,</\=\s*h6\s*>,=====,ge
47" beautifiers
48%s,</\=\s*code\s*>,``,ge
49%s,</\=\s*\(b\|strong\)\s*>,**,ge
50%s,</\=\s*\(i\|em\)\s*>,//,ge
51%s,</\=\s*u\s*>,__,ge
52%s,</\=\s*s\s*>,--,ge
53" pre
54%s,</\=\s*pre\s*>,
55```
56,ge
57" bullet/numbered list
58%s,<\s*li\s*>,- ,ge
59%s,</\s*li\s*>,,ge
60%s,<\s*[uo]l\s*>,,ge
61%s,</\s*[uo]l\s*>,
62
63,ge
64" definition list
65%s,<\s*dl\s*>,,ge
66%s,</\s*dl\s*>,
67
68,ge
69%s,<\s*dt\s*>,: ,ge
70%s,</\s*dt\s*>,
71,ge
72%s,</\=\s*dd\s*>,,ge
73" BR is ignored
74%s,<\s*br\s*/*>,
75,ge
76" trash
77%s,</\s*font[^>]*\s*>,,ge
78%s,</\s*p\s*>,,ge
79%s,</\s*a\s*>,,ge
80%s,</\=\s*blink\s*>,,ge
81%s,<\s*a\s\+name=[^>]*>,,ge
82%s,</\=\s*\(html\|body\|head\|title\)\(\s[^>]*\)\=\s*>,,ge
83" mmmmm, dangerous! it removes all remaining HTML tags
84"%s,<[^>]*>,,ge
85" clear just-blanks lines
86%s,^\s*$,,
87" special entities
88%s,&quot;,",ge
89%s,&amp;,\&,ge
90%s,&gt;,>,ge
91%s,&lt;,<,ge
92%s,&nbsp;, ,ge
93
94" save new .t2t file and turn on syntax
95saveas! %.t2t | set ft=txt2tags