summaryrefslogtreecommitdiffabout
path: root/html.c
Unidiff
Diffstat (limited to 'html.c') (more/less context) (ignore whitespace changes)
-rw-r--r--html.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/html.c b/html.c
index 8a69659..957b326 100644
--- a/html.c
+++ b/html.c
@@ -44,48 +44,76 @@ void htmlf(const char *format, ...)
44 44
45void html_txt(char *txt) 45void html_txt(char *txt)
46{ 46{
47 char *t = txt; 47 char *t = txt;
48 while(*t){ 48 while(*t){
49 int c = *t; 49 int c = *t;
50 if (c=='<' || c=='>' || c=='&') { 50 if (c=='<' || c=='>' || c=='&') {
51 *t = '\0'; 51 *t = '\0';
52 html(txt); 52 html(txt);
53 *t = c; 53 *t = c;
54 if (c=='>') 54 if (c=='>')
55 html("&gt;"); 55 html("&gt;");
56 else if (c=='<') 56 else if (c=='<')
57 html("&lt;"); 57 html("&lt;");
58 else if (c=='&') 58 else if (c=='&')
59 html("&amp;"); 59 html("&amp;");
60 txt = t+1; 60 txt = t+1;
61 } 61 }
62 t++; 62 t++;
63 } 63 }
64 if (t!=txt) 64 if (t!=txt)
65 html(txt); 65 html(txt);
66} 66}
67 67
68void html_ntxt(int len, char *txt)
69{
70 char *t = txt;
71 while(*t && len--){
72 int c = *t;
73 if (c=='<' || c=='>' || c=='&') {
74 *t = '\0';
75 html(txt);
76 *t = c;
77 if (c=='>')
78 html("&gt;");
79 else if (c=='<')
80 html("&lt;");
81 else if (c=='&')
82 html("&amp;");
83 txt = t+1;
84 }
85 t++;
86 }
87 if (t!=txt) {
88 char c = *t;
89 *t = '\0';
90 html(txt);
91 *t = c;
92 }
93 if (len<0)
94 html("...");
95}
68 96
69void html_attr(char *txt) 97void html_attr(char *txt)
70{ 98{
71 char *t = txt; 99 char *t = txt;
72 while(*t){ 100 while(*t){
73 int c = *t; 101 int c = *t;
74 if (c=='<' || c=='>' || c=='\'') { 102 if (c=='<' || c=='>' || c=='\'') {
75 *t = '\0'; 103 *t = '\0';
76 html(txt); 104 html(txt);
77 *t = c; 105 *t = c;
78 if (c=='>') 106 if (c=='>')
79 html("&gt;"); 107 html("&gt;");
80 else if (c=='<') 108 else if (c=='<')
81 html("&lt;"); 109 html("&lt;");
82 else if (c=='\'') 110 else if (c=='\'')
83 html("&quote;"); 111 html("&quote;");
84 txt = t+1; 112 txt = t+1;
85 } 113 }
86 t++; 114 t++;
87 } 115 }
88 if (t!=txt) 116 if (t!=txt)
89 html(txt); 117 html(txt);
90} 118}
91 119