-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvim2html.sh
More file actions
executable file
·53 lines (42 loc) · 1.52 KB
/
vim2html.sh
File metadata and controls
executable file
·53 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Create HTML code from Vim syntax highlighting (for use in coloring scripts)
filename=$@
background=light
colorscheme=beauty256
scrpt=${0##*/} # filename of script
# Display usage if no parameters given
if [[ -z "$@" ]]; then
echo " $scrpt <filename> - create HTML code from Vim syntax highlighting"
exit
fi
# Syntax highlighting to HTML export
vim -f +"syntax on" \
+"set background=$background" \
+"colorscheme $colorscheme" \
+"let html_use_css = 0" \
+"let html_no_pre = 1" \
+"let html_number_lines = 0" \
+"TOhtml" \
+"x" \
+"q" $filename
# Clean up HTML code
tidy -utf8 -f /dev/null --wrap -m $filename.html
# Delete the HTML meta page information.
#sed -i '1,/body bgcolor=/d' $filename.html
# Remove line breaks (needed for some things like blog posts)
#sed -i 's|<br>||g' $filename.html
# Remove the closing HTML tags
#sed -i 's~</body[^>]*>~~g' $filename.html
#sed -i 's~</html[^>]*>~~g' $filename.html
# Add preformatting tabs <pre> and </pre>
#sed -i '1 i <pre>' $filename.html
#sed -i '$ a </pre>' $filename.html
# Remove trailing blank lines
while [ "$(tail -n 1 $filename.html)" == "\n" ]; do
sed -i '$d' $filename.html
done
# Delete newline of last <font> line for better formatting
sed -i ':a;N;$!ba;s/\(.*\)\n/\1/' $filename.html
sed -i ':a;N;$!ba;s/\(.*\)\n/\1/' $filename.html
# Delete final newline
perl -i -e 'local $/; $_ = <>; s/\n$//; print' $filename.html