-
Notifications
You must be signed in to change notification settings - Fork 2
/
ETTextHTML.h
147 lines (140 loc) · 4.71 KB
/
ETTextHTML.h
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
#import "ETTextProtocols.h"
@class ETXHTMLWriter;
/**
* Protocol used for element handlers when writing XHTML. This is similar to
* the visitor protocol, but takes an ETXHTMLWriter as the first argument.
*/
@protocol ETXHTMLWriterDelegate
/**
* Method called when entering a node for which this delegate is registered.
*/
- (void)writer: (ETXHTMLWriter*)aWriter startTextNode: (id<ETText>)aNode;
/**
* Method called when traversing a leaf node for which this delegate is
* registered.
*/
- (void)writer: (ETXHTMLWriter*)aWriter visitTextNode: (id<ETText>)aNode;
/**
* Method called after visiting this node and all of its children.
*/
- (void)writer: (ETXHTMLWriter*)aWriter endTextNode: (id<ETText>)aNode;
@end
@class ETXMLWriter;
@class ETXHTMLFootnoteBuilder;
@class ETReferenceBuilder;
/**
* ETXHTMLWriter is a visitor class that walks an EtoileText tree and generates
* an XHTML document from it.
*/
@interface ETXHTMLWriter : NSObject <ETTextVisitor>
{
/**
* Mapping from EtoileText types to XHTML tag names. Used for one-to-one
* mappings. More complex mappings require a delegate.
*/
NSMutableDictionary *types;
/** Mapping from EtoileText type to tag attributes. */
NSMutableDictionary *defaultAttributes;
/** Mapping from EtoileText types to delegates for custom handling. */
NSMutableDictionary *customHandlers;
/** Flag indicating that the writer is current outputting footnotes. */
BOOL isWritingFootnotes;
/** Footnote builder. */
ETXHTMLFootnoteBuilder *footnotes;
/** Cross-reference builder. */
ETReferenceBuilder *referenceBuilder;
/** Title of the current chapter. */
NSString *chapterTitle;
}
/** The XML writer object used for output. */
@property (nonatomic, retain) ETXMLWriter *writer;
/**
* Do not output anything until the specified node is ended. Used, for
* example, by footnotes to just output a number for the current footnote and
* then emit a body of the footnote node later.
*/
@property (nonatomic, assign) id skipToEndOfNode;
/**
* Flag set if each chapter should be written to a separate file.
*/
@property (nonatomic) BOOL writeChaptersToFiles;
/**
* Sets the HTML tag name to use for a specified EtoileText type. Ignored if a
* delegate is set for this type. If no tag name is specified for a type, span
* is used.
*/
- (void)setTagName: (NSString*)aString forTextType: (NSString*)aType;
/**
* Sets the default attributes to use for a specified EtoileText type. If no
* attributes are specified for a tag type, the class attribute is set to the
* EtoileText type.
*/
- (void)setAttributes: (NSDictionary*)attributes forTextType: (NSString*)aType;
/**
* Specifies a delegate to use for a specified EtoileText type.
*/
- (void)setDelegate: (id<ETXHTMLWriterDelegate>)aDelegate
forTextType: (NSString*)aType;
- (NSString*)generateHTMLForDocument: (id<ETText>)aDocument;
/**
* Ends the document and returns a string containing the XHTML rendition of it.
*/
- (NSString*)endDocument;
@end
/**
* Class used for generating footnotes in XHTML output.
*/
@interface ETXHTMLFootnoteBuilder : NSObject <ETXHTMLWriterDelegate>
{
/** Array of footnotes collected so far. */
NSMutableArray *footnotes;
}
/**
* Writes the collected footnote bodies to the provided writer.
*/
- (void)writeCollectedFootnotesForXHTMLWriter: (ETXHTMLWriter*)aWriter;
@end
/**
* Class used for outputting headings as XHTML. Maps EtoileText heading levels
* to h1, h2, and so on.
*/
@interface ETXHTMLHeadingBuilder : NSObject <ETXHTMLWriterDelegate> @end
/**
* Version of the heading builder that generates a link target for every
* heading. This is used when generating a table of contents.
*/
@interface ETXHTMLAutolinkingHeadingBuilder : ETXHTMLHeadingBuilder
{
/** The number to use for the next heading. */
int headingNumber;
}
@end
/**
* Class that resolves references in an EtoileText tree.
*/
@interface ETReferenceBuilder : NSObject <ETTextVisitor>
{
/** Text nodes referring to other elements. */
NSMutableArray *referenceNodes;
NSString *chapter;
/** Link targets. */
NSMutableDictionary *linkTargets;
NSMutableDictionary *linkNames;
NSMutableDictionary *crossReferences;
NSMutableArray *headings;
/** Index entries. */
NSMutableDictionary *indexEntries;
int sectionCounter[10];
int sectionCounterDepth;
int headingCounter;
}
- (void)finishVisiting;
@property (readonly) NSArray *referenceNodes;
@property (readonly) NSArray *headings;
@property (readonly) NSDictionary *linkTargets;
@property (readonly) NSDictionary *linkNames;
@property (readonly) NSDictionary *crossReferences;
- (NSString*)linkTitleForTarget: (NSString*)linkTarget inChapter: (NSString*)currentChapter;
- (void)writeTableOfContentsWithXMLWriter: (ETXMLWriter*)writer;
- (void)writeIndexWithXMLWriter: (ETXMLWriter*)writer;
@end