-
Notifications
You must be signed in to change notification settings - Fork 2
/
ETXMLTextParser.m
66 lines (65 loc) · 1.71 KB
/
ETXMLTextParser.m
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
#import "EtoileText/EtoileText.h"
@implementation ETXMLTextParser
@synthesize document;
- (void)startElement: (NSString *)aName
attributes: (NSDictionary*)attributes;
{
if (depth > 0)
{
ETXMLTextParser *childParser =
[[[self class] alloc] initWithXMLParser: parser
parent: self
key: @"Text"];
childParser.document = document;
[childParser startElement: aName
attributes: attributes];
return;
}
[super startElement: aName attributes: attributes];
NSMutableDictionary *dict = [attributes mutableCopy];
if (nil == dict)
{
dict = [NSMutableDictionary new];
}
[dict setObject: aName
forKey: kETTextStyleName];
style = [document typeFromDictionary: dict];
value = [ETTextFragment new];
[value setTextType: style];
[dict release];
// TODO: Custom style by parsing CSS from style attribute - take code from
// ETXML
}
- (void)characters: (NSString *)aString
{
if ([value isKindOfClass: [ETTextFragment class]])
{
[value replaceCharactersInRange: NSMakeRange([value length], 0)
withString: aString];
}
else
{
ETTextFragment *fragment =
[[ETTextFragment alloc] initWithString: aString];
[value appendTextFragment: fragment];
[fragment release];
}
}
- (void)addText: (id<ETText>)aChild
{
if ([value isKindOfClass: [ETTextFragment class]])
{
ETTextFragment *fragment = value;
ETTextTree *tree = [ETTextTree textTreeWithChildren: A(value, aChild)];
tree.customAttributes = fragment.customAttributes;
fragment.customAttributes = nil;
tree.textType = fragment.textType;
fragment.textType = nil;
value = tree;
}
else
{
[value appendTextFragment: aChild];
}
}
@end