Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved debugDescription of nodes

  • Loading branch information...
commit 389c7fe8dddc6d335ccebe6608e1e5e64834eafb 1 parent dda9708
@Cocoanetics authored
View
6 Core/Source/DTCSSStylesheet.m
@@ -315,7 +315,7 @@ - (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element
}
// Get based on class(es)
- NSString *classString = [element attributeForKey:@"class"];
+ NSString *classString = [element.attributes objectForKey:@"class"];
NSArray *classes = [classString componentsSeparatedByString:@" "];
for (NSString *class in classes)
@@ -338,7 +338,7 @@ - (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element
}
// Get based on id
- NSString *idRule = [NSString stringWithFormat:@"#%@", [element attributeForKey:@"id"]];
+ NSString *idRule = [NSString stringWithFormat:@"#%@", [element.attributes objectForKey:@"id"]];
NSDictionary *byID = [_styles objectForKey:idRule];
if (byID)
@@ -347,7 +347,7 @@ - (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element
}
// Get tag's local style attribute
- NSString *styleString = [element attributeForKey:@"style"];
+ NSString *styleString = [element.attributes objectForKey:@"style"];
if ([styleString length])
{
View
1  Core/Source/DTHTMLElement.h
@@ -67,7 +67,6 @@
CGSize _size;
NSMutableArray *_children;
- NSDictionary *_attributes; // contains all attributes from parsing
NSDictionary *_styles;
View
12 Core/Source/DTHTMLElement.m
@@ -1147,13 +1147,10 @@ - (DTHTMLElementFontVariant)fontVariant
- (void)setAttributes:(NSDictionary *)attributes
{
- if (_attributes != attributes)
- {
- _attributes = attributes;
-
- // decode size contained in attributes, might be overridden later by CSS size
- _size = CGSizeMake([[self attributeForKey:@"width"] floatValue], [[self attributeForKey:@"height"] floatValue]);
- }
+ [super setAttributes:[attributes copy]];
+
+ // decode size contained in attributes, might be overridden later by CSS size
+ _size = CGSizeMake([[self attributeForKey:@"width"] floatValue], [[self attributeForKey:@"height"] floatValue]);
}
- (void)setTextAttachment:(DTTextAttachment *)textAttachment
@@ -1197,7 +1194,6 @@ - (void)setLink:(NSURL *)link
@synthesize fontVariant = _fontVariant;
@synthesize textScale = _textScale;
@synthesize size = _size;
-@synthesize attributes = _attributes;
@synthesize linkGUID = _linkGUID;
@end
View
8 Core/Source/DTHTMLParserNode.h
@@ -11,6 +11,9 @@
@class DTHTMLParserTextNode;
@interface DTHTMLParserNode : NSObject
+{
+ NSDictionary *_attributes;
+}
/**
Designated initializer
@@ -48,4 +51,9 @@
*/
- (NSString *)debugDescription;
+/**
+ Concatenated contents of all text nodes
+ */
+- (NSString *)text;
+
@end
View
33 Core/Source/DTHTMLParserNode.m
@@ -7,11 +7,11 @@
//
#import "DTHTMLParserNode.h"
+#import "DTHTMLParserTextNode.h"
@implementation DTHTMLParserNode
{
NSString *_name;
- NSDictionary *_attributes;
__unsafe_unretained DTHTMLParserNode *_parentNode;
NSMutableArray *_childNodes;
}
@@ -24,7 +24,7 @@ - (id)initWithName:(NSString *)name attributes:(NSDictionary *)attributes
if (self)
{
_name = [name copy];
- self.attributes = [attributes copy]; // property to allow overriding
+ [self setAttributes:attributes]; // property to allow overriding
}
return self;
@@ -59,19 +59,19 @@ - (void)_appendHTMLToString:(NSMutableString *)string indentLevel:(NSUInteger)in
// write own name tag open
[string appendFormat:@"<%@", _name];
- if (![_childNodes count])
- {
- [string appendString:@" \\>\n"];
- return;
- }
-
// sort attribute names
NSArray *sortedKeys = [_attributes.allKeys sortedArrayUsingSelector:@selector(compare:)];
for (NSString *oneKey in sortedKeys)
{
NSString *attribute = [_attributes objectForKey:oneKey];
- [string appendFormat:@" %@='%@'", oneKey, attribute];
+ [string appendFormat:@" %@=\"%@\"", oneKey, attribute];
+ }
+
+ if (![_childNodes count])
+ {
+ [string appendString:@" \\>\n"];
+ return;
}
[string appendFormat:@">\n"];
@@ -101,6 +101,21 @@ - (NSString *)debugDescription
return tmpString;
}
+- (NSString *)text
+{
+ NSMutableString *text = [NSMutableString string];
+
+ for (DTHTMLParserTextNode *oneChild in self.childNodes)
+ {
+ if ([oneChild isKindOfClass:[DTHTMLParserTextNode class]])
+ {
+ [text appendString:[oneChild characters]];
+ }
+ }
+
+ return text;
+}
+
#pragma mark - Properties
@synthesize name = _name;
View
2  Core/Source/DTTextAttachment.m
@@ -75,7 +75,7 @@ + (DTTextAttachment *)textAttachmentWithElement:(DTHTMLElement *)element options
NSURL *baseURL = [options objectForKey:NSBaseURLDocumentOption];
// decode URL
- NSString *src = [element attributeForKey:@"src"];
+ NSString *src = [element.attributes objectForKey:@"src"];
NSURL *contentURL = nil;
DTImage *decodedImage = nil;
View
28 DTCoreText.xcodeproj/project.pbxproj
@@ -370,7 +370,6 @@
A7EB84CD168B9A8500D686B7 /* DTHTMLElementAttachment.h in Headers */ = {isa = PBXBuildFile; fileRef = A7EB84C9168B9A8400D686B7 /* DTHTMLElementAttachment.h */; };
A7EB84CE168B9A8500D686B7 /* DTHTMLElementAttachment.h in Headers */ = {isa = PBXBuildFile; fileRef = A7EB84C9168B9A8400D686B7 /* DTHTMLElementAttachment.h */; };
A7EB84CF168B9A8500D686B7 /* DTHTMLElementAttachment.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB84CA168B9A8400D686B7 /* DTHTMLElementAttachment.m */; };
- A7EB84D0168B9A8500D686B7 /* DTHTMLElementAttachment.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB84CA168B9A8400D686B7 /* DTHTMLElementAttachment.m */; };
A7EB84D1168B9A8500D686B7 /* DTHTMLElementAttachment.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB84CA168B9A8400D686B7 /* DTHTMLElementAttachment.m */; };
A7EB84D2168B9A8500D686B7 /* DTHTMLElementAttachment.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB84CA168B9A8400D686B7 /* DTHTMLElementAttachment.m */; };
A7EB84D5168B9B1300D686B7 /* DTHTMLElementHR.h in Headers */ = {isa = PBXBuildFile; fileRef = A7EB84D3168B9B1100D686B7 /* DTHTMLElementHR.h */; };
@@ -399,6 +398,17 @@
A7EB84EE168C657100D686B7 /* DTHTMLElementLI.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB84E4168C657000D686B7 /* DTHTMLElementLI.m */; };
A7EB84FC168ED63A00D686B7 /* FontSizes.html in Resources */ = {isa = PBXBuildFile; fileRef = A7EB84FB168ED63A00D686B7 /* FontSizes.html */; };
A7EB84FD168ED63A00D686B7 /* FontSizes.html in Resources */ = {isa = PBXBuildFile; fileRef = A7EB84FB168ED63A00D686B7 /* FontSizes.html */; };
+ A7EB8534168F336000D686B7 /* DTHTMLElementAttachment.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB84CA168B9A8400D686B7 /* DTHTMLElementAttachment.m */; };
+ A7EB8535168F336100D686B7 /* DTHTMLElementAttachment.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB84CA168B9A8400D686B7 /* DTHTMLElementAttachment.m */; };
+ A7EB8536168F336200D686B7 /* DTHTMLElementAttachment.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB84CA168B9A8400D686B7 /* DTHTMLElementAttachment.m */; };
+ A7EB8539168FA33500D686B7 /* DTHTMLElementStylesheet.h in Headers */ = {isa = PBXBuildFile; fileRef = A7EB8537168FA33000D686B7 /* DTHTMLElementStylesheet.h */; };
+ A7EB853A168FA33500D686B7 /* DTHTMLElementStylesheet.h in Headers */ = {isa = PBXBuildFile; fileRef = A7EB8537168FA33000D686B7 /* DTHTMLElementStylesheet.h */; };
+ A7EB853B168FA33500D686B7 /* DTHTMLElementStylesheet.h in Headers */ = {isa = PBXBuildFile; fileRef = A7EB8537168FA33000D686B7 /* DTHTMLElementStylesheet.h */; };
+ A7EB853D168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB8538168FA33300D686B7 /* DTHTMLElementStylesheet.m */; };
+ A7EB853E168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB8538168FA33300D686B7 /* DTHTMLElementStylesheet.m */; };
+ A7EB853F168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB8538168FA33300D686B7 /* DTHTMLElementStylesheet.m */; };
+ A7EB8540168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB8538168FA33300D686B7 /* DTHTMLElementStylesheet.m */; };
+ A7EB8541168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EB8538168FA33300D686B7 /* DTHTMLElementStylesheet.m */; };
A7F5671414D841EA00D1F167 /* NSString+CSS.h in Headers */ = {isa = PBXBuildFile; fileRef = A7F5671214D841E900D1F167 /* NSString+CSS.h */; settings = {ATTRIBUTES = (Public, ); }; };
A7F5671514D841EA00D1F167 /* NSString+CSS.h in Headers */ = {isa = PBXBuildFile; fileRef = A7F5671214D841E900D1F167 /* NSString+CSS.h */; settings = {ATTRIBUTES = (Public, ); }; };
A7F5671614D841EA00D1F167 /* NSString+CSS.m in Sources */ = {isa = PBXBuildFile; fileRef = A7F5671314D841E900D1F167 /* NSString+CSS.m */; };
@@ -923,6 +933,8 @@
A7EB84E3168C656E00D686B7 /* DTHTMLElementLI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTHTMLElementLI.h; sourceTree = "<group>"; };
A7EB84E4168C657000D686B7 /* DTHTMLElementLI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTHTMLElementLI.m; sourceTree = "<group>"; };
A7EB84FB168ED63A00D686B7 /* FontSizes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FontSizes.html; sourceTree = "<group>"; };
+ A7EB8537168FA33000D686B7 /* DTHTMLElementStylesheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTHTMLElementStylesheet.h; sourceTree = "<group>"; };
+ A7EB8538168FA33300D686B7 /* DTHTMLElementStylesheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTHTMLElementStylesheet.m; sourceTree = "<group>"; };
A7F5671214D841E900D1F167 /* NSString+CSS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = "NSString+CSS.h"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
A7F5671314D841E900D1F167 /* NSString+CSS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "NSString+CSS.m"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
A7F5671C14D8469000D1F167 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Cocoa.framework; sourceTree = DEVELOPER_DIR; };
@@ -1268,6 +1280,8 @@
A7EB84D4168B9B1200D686B7 /* DTHTMLElementHR.m */,
A7EB84E3168C656E00D686B7 /* DTHTMLElementLI.h */,
A7EB84E4168C657000D686B7 /* DTHTMLElementLI.m */,
+ A7EB8537168FA33000D686B7 /* DTHTMLElementStylesheet.h */,
+ A7EB8538168FA33300D686B7 /* DTHTMLElementStylesheet.m */,
A7EB84BF168B973900D686B7 /* DTHTMLElementText.h */,
A7EB84C0168B973A00D686B7 /* DTHTMLElementText.m */,
A7EB84C9168B9A8400D686B7 /* DTHTMLElementAttachment.h */,
@@ -1445,6 +1459,7 @@
A7EB84CB168B9A8500D686B7 /* DTHTMLElementAttachment.h in Headers */,
A7EB84D5168B9B1300D686B7 /* DTHTMLElementHR.h in Headers */,
A7EB84E5168C657100D686B7 /* DTHTMLElementLI.h in Headers */,
+ A7EB8539168FA33500D686B7 /* DTHTMLElementStylesheet.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1500,6 +1515,7 @@
A7EB84CC168B9A8500D686B7 /* DTHTMLElementAttachment.h in Headers */,
A7EB84D6168B9B1300D686B7 /* DTHTMLElementHR.h in Headers */,
A7EB84E6168C657100D686B7 /* DTHTMLElementLI.h in Headers */,
+ A7EB853A168FA33500D686B7 /* DTHTMLElementStylesheet.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1554,6 +1570,7 @@
A7EB84CD168B9A8500D686B7 /* DTHTMLElementAttachment.h in Headers */,
A7EB84D7168B9B1300D686B7 /* DTHTMLElementHR.h in Headers */,
A7EB84E7168C657100D686B7 /* DTHTMLElementLI.h in Headers */,
+ A7EB853B168FA33500D686B7 /* DTHTMLElementStylesheet.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2077,6 +2094,7 @@
A7EB84CF168B9A8500D686B7 /* DTHTMLElementAttachment.m in Sources */,
A7EB84D9168B9B1300D686B7 /* DTHTMLElementHR.m in Sources */,
A7EB84E9168C657100D686B7 /* DTHTMLElementLI.m in Sources */,
+ A7EB853D168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2127,9 +2145,10 @@
A7EB84AC168B3EC000D686B7 /* DTHTMLParserTextNode.m in Sources */,
A7EB84BC168B948000D686B7 /* DTHTMLElementBR.m in Sources */,
A7EB84C6168B973A00D686B7 /* DTHTMLElementText.m in Sources */,
- A7EB84D0168B9A8500D686B7 /* DTHTMLElementAttachment.m in Sources */,
A7EB84DA168B9B1300D686B7 /* DTHTMLElementHR.m in Sources */,
A7EB84EA168C657100D686B7 /* DTHTMLElementLI.m in Sources */,
+ A7EB8536168F336200D686B7 /* DTHTMLElementAttachment.m in Sources */,
+ A7EB853E168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2185,6 +2204,8 @@
A7EB84E1168BAB2D00D686B7 /* DTHTMLElementHR.m in Sources */,
A7EB84E2168BAB2D00D686B7 /* DTHTMLElementText.m in Sources */,
A7EB84EB168C657100D686B7 /* DTHTMLElementLI.m in Sources */,
+ A7EB8535168F336100D686B7 /* DTHTMLElementAttachment.m in Sources */,
+ A7EB853F168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2224,6 +2245,8 @@
A7EB84DE168BAB2D00D686B7 /* DTHTMLElementHR.m in Sources */,
A7EB84DF168BAB2D00D686B7 /* DTHTMLElementText.m in Sources */,
A7EB84EC168C657100D686B7 /* DTHTMLElementLI.m in Sources */,
+ A7EB8534168F336000D686B7 /* DTHTMLElementAttachment.m in Sources */,
+ A7EB8540168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2276,6 +2299,7 @@
A7EB84D1168B9A8500D686B7 /* DTHTMLElementAttachment.m in Sources */,
A7EB84DB168B9B1300D686B7 /* DTHTMLElementHR.m in Sources */,
A7EB84ED168C657100D686B7 /* DTHTMLElementLI.m in Sources */,
+ A7EB8541168FA33500D686B7 /* DTHTMLElementStylesheet.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Please sign in to comment.
Something went wrong with that request. Please try again.