Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added HTML Fallback & CTidy ( make the results more like NSDoc on mac) #18

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TIDY added, fallback to html added (as this seems to be what the mac …
…does)

Signed-off-by: Dominik Pich <[email protected]>
  • Loading branch information
Daij-Djan committed Jun 24, 2012
commit df7b41b0a557952a2ab24e42ee72063adae6cd37
7 changes: 4 additions & 3 deletions KissXML/DDXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
* https://github.com/robbiehanson/KissXML/wiki/Reference
**/

#define DDXML_FALLBACK_ON_HTML 1
#define DDXML_DROPIN_IOS 1

#import "DDXMLNode.h"
#import "DDXMLElement.h"
#import "DDXMLDocument.h"



#if TARGET_OS_IPHONE && 0 // Disabled by default
#if TARGET_OS_IPHONE && DDXML_DROPIN_IOS

#define NSXMLDocumentTidyXML DDXMLDocumentTidyXML
#define NSXMLDocumentTidyHTML DDXMLDocumentTidyHTML
Expand Down
2 changes: 2 additions & 0 deletions KissXML/DDXMLDocument.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#import <Foundation/Foundation.h>
#import "DDXMLElement.h"
#import "DDXMLNode.h"
#import <libxml/parser.h>
#import <libxml/HTMLparser.h>

/**
* Welcome to KissXML.
Expand Down
39 changes: 27 additions & 12 deletions KissXML/DDXMLDocument.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#import "DDXMLPrivate.h"
#import "NSString+DDXML.h"
#import "Additions/CTidy.h"
#if TARGET_OS_IPHONE
#import "Private/CTidy.h"
#endif

#if ! __has_feature(objc_arc)
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
Expand Down Expand Up @@ -86,16 +88,19 @@ - (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)err
}

#if TARGET_OS_IPHONE
if (mask & NSXMLDocumentTidyHTML)
{
data = [[CTidy tidy] tidyData:data inputFormat:TidyFormat_HTML outputFormat:TidyFormat_XHTML diagnostics:NULL error:&theError];
if (mask & DDXMLDocumentTidyHTML)
{
data = [[CTidy tidy] tidyData:data inputFormat:TidyFormat_HTML outputFormat:TidyFormat_XHTML diagnostics:NULL error:error];
}
else if (mask & DDXMLDocumentTidyXML)
{
data = [[CTidy tidy] tidyData:data inputFormat:TidyFormat_XML outputFormat:TidyFormat_XML diagnostics:NULL error:error];
}
if(!data) {
return nil;
}
else if (mask & NSXMLDocumentTidyXML)
{
data = [[CTidy tidy] tidyData:data inputFormat:TidyFormat_XML outputFormat:TidyFormat_XML diagnostics:NULL error:&theError];
}
#endif

// Even though xmlKeepBlanksDefault(0) is called in DDXMLNode's initialize method,
// it has been documented that this call seems to get reset on the iPhone:
// http://code.google.com/p/kissxml/issues/detail?id=8
Expand All @@ -107,9 +112,19 @@ - (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)err
xmlDocPtr doc = xmlParseMemory([data bytes], [data length]);
if (doc == NULL)
{
if (error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:1 userInfo:nil];

return nil;
#if DDXML_FALLBACK_ON_HTML
htmlParserCtxtPtr ctx = htmlCreateMemoryParserCtxt([data bytes], [data length]);
int err = htmlParseDocument(ctx);
if(err==0) {
doc = ctx->myDoc;
}
htmlFreeParserCtxt(ctx);
#endif
if(!doc) {
if (error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:1 userInfo:nil];

return nil;
}
}

return [self initWithDocPrimitive:doc owner:nil];
Expand Down
4 changes: 0 additions & 4 deletions KissXML/Private/CTidy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

#ifdef TOUCHXMLUSETIDY

#import <Foundation/Foundation.h>

#include "tidy.h"
Expand All @@ -49,5 +47,3 @@ typedef enum {
- (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat diagnostics:(NSString **)outDiagnostics error:(NSError **)outError;

@end

#endif /* TOUCHXMLUSETIDY */
9 changes: 3 additions & 6 deletions KissXML/Private/CTidy.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

#ifdef TOUCHXMLUSETIDY

#import "CTidy.h"

@interface CTidy ()
Expand All @@ -40,7 +38,7 @@ @implementation CTidy

+ (CTidy *)tidy
{
return([[[self alloc] init] autorelease]);
return([[self alloc] init]);
}

- (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat diagnostics:(NSString **)outDiagnostics error:(NSError **)outError
Expand Down Expand Up @@ -126,7 +124,7 @@ - (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat out
if (outDiagnostics && theErrorBuffer.bp != NULL)
{
NSData *theErrorData = [NSData dataWithBytes:theErrorBuffer.bp length:theErrorBuffer.size];
*outDiagnostics = [[[NSString alloc] initWithData:theErrorData encoding:NSUTF8StringEncoding] autorelease];
*outDiagnostics = [[NSString alloc] initWithData:theErrorData encoding:NSUTF8StringEncoding];
}
tidyBufFree(&theErrorBuffer);

Expand Down Expand Up @@ -213,7 +211,7 @@ - (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFo
if (outDiagnostics && theErrorBuffer.bp != NULL)
{
NSData *theErrorData = [NSData dataWithBytes:theErrorBuffer.bp length:theErrorBuffer.size];
*outDiagnostics = [[[NSString alloc] initWithData:theErrorData encoding:NSUTF8StringEncoding] autorelease];
*outDiagnostics = [[NSString alloc] initWithData:theErrorData encoding:NSUTF8StringEncoding];
}
tidyBufFree(&theErrorBuffer);

Expand All @@ -229,4 +227,3 @@ - (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFo

@end

#endif /* TOUCHXMLUSETIDY */
16 changes: 15 additions & 1 deletion KissXML/Private/DDXMLPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,21 @@ NS_INLINE BOOL IsXmlNodePtr(void *kindPtr)

NS_INLINE BOOL IsXmlDocPtr(void *kindPtr)
{
return ((xmlKindPtr)kindPtr)->type == XML_DOCUMENT_NODE;
#if DDXML_FALLBACK_ON_HTML
switch (((xmlKindPtr)kindPtr)->type)
{
case XML_DOCUMENT_NODE :
case XML_HTML_DOCUMENT_NODE : return YES;
default : return NO;
}
#else
return ((xmlKindPtr)kindPtr)->type == XML_DOCUMENT_NODE;
#endif
}

NS_INLINE BOOL IsHtmlDocPtr(void *kindPtr)
{
return ((xmlKindPtr)kindPtr)->type == XML_HTML_DOCUMENT_NODE;
}

NS_INLINE BOOL IsXmlDtdPtr(void *kindPtr)
Expand Down
10 changes: 9 additions & 1 deletion UnitTesting/KissXML.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
B482F7E715967E1200E1A642 /* CTidy.m in Sources */ = {isa = PBXBuildFile; fileRef = B482F7E615967E1200E1A642 /* CTidy.m */; };
DC54426E0E8F33E100013051 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DC54426D0E8F33E100013051 /* AppDelegate.m */; };
DC5442710E8F340800013051 /* DDXMLTesting.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5442700E8F340800013051 /* DDXMLTesting.m */; };
DCC05A4D1361DB8200993C2A /* DDXMLElementAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DCC05A401361DB8200993C2A /* DDXMLElementAdditions.m */; };
Expand All @@ -31,6 +32,8 @@
32CA4F630368D1EE00C91783 /* KissXML_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KissXML_Prefix.pch; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* KissXML.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KissXML.app; sourceTree = BUILT_PRODUCTS_DIR; };
B482F7E515967E1200E1A642 /* CTidy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTidy.h; sourceTree = "<group>"; };
B482F7E615967E1200E1A642 /* CTidy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTidy.m; sourceTree = "<group>"; };
DC54426C0E8F33E100013051 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
DC54426D0E8F33E100013051 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
DC54426F0E8F340800013051 /* DDXMLTesting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDXMLTesting.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -178,6 +181,8 @@
DCC05A4B1361DB8200993C2A /* Private */ = {
isa = PBXGroup;
children = (
B482F7E515967E1200E1A642 /* CTidy.h */,
B482F7E615967E1200E1A642 /* CTidy.m */,
DCC05A4C1361DB8200993C2A /* DDXMLPrivate.h */,
);
path = Private;
Expand Down Expand Up @@ -210,7 +215,7 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
LastUpgradeCheck = 0450;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "KissXML" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -253,6 +258,7 @@
DCC05A4F1361DB8200993C2A /* DDXMLDocument.m in Sources */,
DCC05A501361DB8200993C2A /* DDXMLElement.m in Sources */,
DCC05A511361DB8200993C2A /* DDXMLNode.m in Sources */,
B482F7E715967E1200E1A642 /* CTidy.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -316,6 +322,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
COMBINE_HIDPI_IMAGES = YES;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
Expand All @@ -331,6 +338,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
COMBINE_HIDPI_IMAGES = YES;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Expand Down