forked from Mynigma/HTMLPurifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLPurifier_HTMLModule_Legacy.m
More file actions
162 lines (120 loc) · 6.15 KB
/
HTMLPurifier_HTMLModule_Legacy.m
File metadata and controls
162 lines (120 loc) · 6.15 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
// HTMLPurifier_HTMLModule_Legacy.m
// HTMLPurifier
//
// Created by Roman Priebe on 18.01.14.
#import "HTMLPurifier_HTMLModule_Legacy.h"
#import "HTMLPurifier_ElementDef.h"
#import "HTMLPurifier_AttrDef_Integer.h"
/**
* XHTML 1.1 Legacy module defines elements that were previously
* deprecated.
*
* @note Not all legacy elements have been implemented yet, which
* is a bit of a reverse problem as compared to browsers! In
* addition, this legacy module may implement a bit more than
* mandated by XHTML 1.1.
*
* This module can be used in combination with TransformToStrict in order
* to transform as many deprecated elements as possible, but retain
* questionably deprecated elements that do not have good alternatives
* as well as transform elements that don't have an implementation.
* See docs/ref-strictness.txt for more details.
*/
@implementation HTMLPurifier_HTMLModule_Legacy
- (id)initWithConfig:(HTMLPurifier_Config*)config
{
self = [super initWithConfig:config];
if (self) {
self.name = @"Legacy";
[self addElement:@"basefont" type:@"Inline" contents:@"Empty" attrIncludes:nil attr:@{@"color":@"Color", @"face":@"Text",@"size":@"Text",@"id":@"ID"}];
[self addElement:@"center" type:@"Block" contents:@"Flow" attrIncludes:@"Common" attr:nil];
[self addElement:@"dir" type:@"Block" contents:@"Required: li" attrIncludes:@"Common" attr:@{@"compact":@"Bool#compact"}];
[self addElement:@"font" type:@"Inline" contents:@"Inline" attrIncludes:@[@"Core", @"I18N"] attr:@{@"color":@"Color",@"face":@"Text",@"size":@"Text"}];
[self addElement:@"menu" type:@"Block" contents:@"Required: li" attrIncludes:@"Common" attr:@{@"compact":@"Bool#compact"}];
HTMLPurifier_ElementDef* s = [self addElement:@"s" type:@"Inline" contents:@"Inline" attrIncludes:@"Common" attr:nil];
s.formatting = YES;
HTMLPurifier_ElementDef* strike = [self addElement:@"strike" type:@"Inline" contents:@"Inline" attrIncludes:@"Common" attr:nil];
strike.formatting = YES;
HTMLPurifier_ElementDef* u = [self addElement:@"u" type:@"Inline" contents:@"Inline" attrIncludes:@"Common" attr:nil];
u.formatting = YES;
// setup modifications to old elements
NSString* align = @"Enum#left,right,center,justify";
HTMLPurifier_ElementDef* address = [self addBlankElement:@"address"];
address.content_model = @"Inline | #PCDATA | p";
address.content_model_type = @"optional";
address.child = nil;
HTMLPurifier_ElementDef* blockquote = [self addBlankElement:@"blockquote"];
blockquote.content_model = @"Flow | #PCDATA";
blockquote.content_model_type = @"optional";
blockquote.child = nil;
HTMLPurifier_ElementDef* br = [self addBlankElement:@"br"];
br.attr[@"clear"] = @"Enum#left,all,right,none";
HTMLPurifier_ElementDef* caption = [self addBlankElement:@"caption"];
caption.attr[@"align"] = @"Enum#top,bottom,left,right";
HTMLPurifier_ElementDef* div = [self addBlankElement:@"div"];
div.attr[@"align"] = align;
HTMLPurifier_ElementDef* dl = [self addBlankElement:@"dl"];
dl.attr[@"compact"] = @"Bool#compact";
for(NSInteger i=1; i<=6; i++)
{
HTMLPurifier_ElementDef* h = [self addBlankElement:[NSString stringWithFormat:@"h%ld", (long)i]];
h.attr[@"align"] = align;
}
HTMLPurifier_ElementDef* hr = [self addBlankElement:@"hr"];
hr.attr[@"align"] = align;
hr.attr[@"noshade"] = @"Bool#noshade";
hr.attr[@"size"] = @"Pixels";
hr.attr[@"width"] = @"Length";
HTMLPurifier_ElementDef* img = [self addBlankElement:@"img"];
img.attr[@"align"] = @"IAlign";
img.attr[@"border"] = @"Pixels";
img.attr[@"hspace"] = @"Pixels";
img.attr[@"vspace"] = @"Pixels";
// figure out this integer business
HTMLPurifier_ElementDef* li = [self addBlankElement:@"li"];
li.attr[@"value"] = [HTMLPurifier_AttrDef_Integer new];
li.attr[@"type"] = @"Enum#s:1,i,I,a,A,disc,square,circle";
HTMLPurifier_ElementDef* ol = [self addBlankElement:@"ol"];
ol.attr[@"compact"] = @"Bool#compact";
ol.attr[@"start"] = [HTMLPurifier_AttrDef_Integer new];
ol.attr[@"type"] = @"Enum#s:1,i,I,a,A";
HTMLPurifier_ElementDef* p = [self addBlankElement:@"p"];
p.attr[@"align"] = align;
HTMLPurifier_ElementDef* pre = [self addBlankElement:@"pre"];
pre.attr[@"width"] = @"Number";
// script omitted
HTMLPurifier_ElementDef* table = [self addBlankElement:@"table"];
table.attr[@"align"] = @"Enum#left,center,right";
table.attr[@"bgcolor"] = @"Color";
HTMLPurifier_ElementDef* tr = [self addBlankElement:@"tr"];
tr.attr[@"bgcolor"] = @"Color";
HTMLPurifier_ElementDef* th = [self addBlankElement:@"th"];
th.attr[@"bgcolor"] = @"Color";
th.attr[@"height"] = @"Length";
th.attr[@"nowrap"] = @"Bool#nowrap";
th.attr[@"width"] = @"Length";
HTMLPurifier_ElementDef* td = [self addBlankElement:@"td"];
td.attr[@"bgcolor"] = @"Color";
td.attr[@"height"] = @"Length";
td.attr[@"nowrap"] = @"Bool#nowrap";
td.attr[@"width"] = @"Length";
HTMLPurifier_ElementDef* ul = [self addBlankElement:@"ul"];
ul.attr[@"compact"] = @"Bool#compact";
ul.attr[@"type"] = @"Enum#square,disc,circle";
// "safe" modifications to "unsafe" elements
// WARNING: If you want to add support for an unsafe, legacy
// attribute, make a new TrustedLegacy module with the trusted
// bit set appropriately
HTMLPurifier_ElementDef* form = [self addBlankElement:@"form"];
form.content_model = @"Flow | #PCDATA";
form.content_model_type = @"optional";
form.attr[@"target"] = @"FrameTarget";
HTMLPurifier_ElementDef* input = [self addBlankElement:@"input"];
input.attr[@"align"] = @"IAlign";
HTMLPurifier_ElementDef* legend = [self addBlankElement:@"legend"];
legend.attr[@"align"] = @"LAlign";
}
return self;
}
@end