Preprocess HTML in Vim

Vim

Public Domain

Vim script for normalizing HTML

Download (right click, save as, rename as appropriate)

Embed

  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
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
:setfiletype html

:%s/^\s*$//g
:%s/^.*$/<p>&<\/p>\r/g										" Wrap each line in <p> tags 
:%s/<p><\/p>[\n]*//g										" Delete empty lines wrapped in <p> tags
:%s/ b\.c\.e\. /<span style="font-variant:small-caps;">\L&\E<\/span>/gi				" Common Era, etc. 
:%s/<\/p>\n*/<\/p>\r\r/g									" Normalize inter-paragraph spaces


:%s/&/\&amp;/g
:%s/‘/\&lsquo;/g
:%s/’/\&rsquo;/g
:%s/‚/\&sbquo;/g
:%s/“/\&ldquo;/g
:%s/”/\&rdquo;/g
:%s/„/\&bdquo;/g
:%s/†/\&dagger;/g
:%s/‡/\&Dagger;/g
:%s/‰/\&permil;/g
:%s/‹/\&lsaquo;/g
:%s/›/\&rsaquo;/g
:%s/?/\&spades;/g
:%s/?/\&clubs;/g
:%s/?/\&hearts;/g
:%s/?/\&diams;/g
:%s/?/\&oline;/g
:%s/?/\&larr;/g
:%s/?/\&uarr;/g
:%s/?/\&rarr;/g
:%s/?/\&darr;/g
:%s/™/\&trade;/g
:%s/"/\&quot;/g
:%s/—/\&mdash;/g
:%s/–/\&ndash;/g
:%s/¡/\&iexcl;/g
:%s/¢/\&cent;/g
:%s/£/\&pound;/g
:%s/¤/\&curren;/g
:%s/¥/\&yen;/g
:%s/§/\&sect;/g
:%s/©/\&copy;/g
:%s/ª/\&ordf;/g
:%s/«/\&laquo;/g
:%s/¬/\&not;/g
:%s/®/\&reg;/g
:%s/?/\&deg;/g
:%s/±/\&plusmn;/g
:%s/²/\&sup2;/g
:%s/³/\&sup3;/g
:%s/´/\&acute;/g
:%s/µ/\&micro;/g
:%s/¶/\&para;/g
:%s/·/\&middot;/g
:%s/¸/\&cedil;/g
:%s/¹/\&sup1;/g
:%s/º/\&ordm;/g
:%s/»/\&raquo;/g
:%s/¼/\&frac14;/g
:%s/½/\&frac12;/g
:%s/¾/\&frac34;/g
:%s/¿/\&iquest;/g
:%s/À/\&Agrave;/g
:%s/Á/\&Aacute;/g
:%s/Â/\&Acirc;/g
:%s/Ã/\&Atilde;/g
:%s/Ä/\&Auml;/g
:%s/Å/\&Aring;/g
:%s/Æ/\&AElig;/g
:%s/Ç/\&Ccedil;/g
:%s/ç/\&ccedil;/g
:%s/È/\&Egrave;/g
:%s/É/\&Eacute;/g
:%s/Ê/\&Ecirc;/g
:%s/Ë/\&Euml;/g
:%s/Ì/\&Igrave;/g
:%s/Í/\&Iacute;/g
:%s/Î/\&Icirc;/g
:%s/Ï/\&Iuml;/g
:%s/Ð/\&ETH;/g
:%s/Ñ/\&Ntilde;/g
:%s/Ò/\&Ograve;/g
:%s/Ó/\&Oacute;/g
:%s/Ô/\&Ocirc;/g
:%s/Õ/\&Otilde;/g
:%s/Ö/\&Ouml;/g
:%s/×/\&times;/g
:%s/Ø/\&Oslash;/g
:%s/Ù/\&Ugrave;/g
:%s/Ú/\&Uacute;/g
:%s/Û/\&Ucirc;/g
:%s/Ü/\&Uuml;/g
:%s/Ý/\&Yacute;/g
:%s/Þ/\&THORN;/g
:%s/ß/\&szlig;/g
:%s/à/\&agrave;/g
:%s/á/\&aacute;/g
:%s/â/\&acirc;/g
:%s/ã/\&atilde;/g
:%s/ä/\&auml;/g
:%s/å/\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