2
Copyright (C) 2004 eXtrapola Srl
4
This file is part of SOPE.
6
SOPE is free software; you can redistribute it and/or modify it under
7
the terms of the GNU Lesser General Public License as published by the
8
Free Software Foundation; either version 2, or (at your option) any
11
SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14
License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with SOPE; see the file COPYING. If not, write to the
18
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22
#error does not compile, just for reference!
24
#include "StructuredText_XHTML.h"
27
@implementation StructuredTextRenderingDelegate_XHTML
29
- (NSString *)insertText:(NSString *)_txt inContext:(NSDictionary *)_ctx {
30
return [NSString stringWithFormat:@"<p>%@</p>", _txt];
33
- (NSString *)insertItalics:(NSString *)_txt inContext:(NSDictionary *)_ctx {
34
return [NSString stringWithFormat:
35
@"<span class=\"italics\">%@</span>", _txt];
38
- (NSString *)insertUnderline:(NSString *)_txt inContext:(NSDictionary *)_ctx {
39
return [NSString stringWithFormat:
40
@"<span class=\"underline\">%@</span>", _txt];
43
- (NSString *)insertBold:(NSString *)_txt inContext:(NSDictionary *)_ctx {
44
return [NSString stringWithFormat:@"<span class=\"bold\">%@</span>", _txt];
47
- (NSString *)insertPreformatted:(NSString *)_txt
48
inContext:(NSDictionary *)_ctx
50
return [NSString stringWithFormat:
51
@"<span class=\"preformatted\">%@</span>", _txt];
54
- (NSString *)insertLink:(NSString *)_txt
55
withUrl:(NSString *)anUrl target:(NSString *)aTarget
56
inContext:(NSDictionary *)_ctx
60
if ([aTarget length] > 0) {
61
result = [NSString stringWithFormat:
62
@"<a href=\"%@\" target=\"%@\">%@</a>",
63
anUrl, aTarget, _txt];
66
result = [NSString stringWithFormat:@"<a href=\"%@\">%@</a>", anUrl, _txt];
72
- (NSString *)insertEmail:(NSString *)_txt withAddress:(NSString *)anAddress
73
inContext:(NSDictionary *)_ctx
75
return [NSString stringWithFormat:@"<a href=\"%@\">%@</a>", anAddress, _txt];
78
- (NSString *)insertImage:(NSString *)_txt withUrl:(NSString *)anUrl
79
inContext:(NSDictionary *)_ctx
81
return [NSString stringWithFormat:@"<img src=\"%@\" title=\"%@\" />",
85
- (NSString *)insertExtrapolaLink:(NSString *)_txt
86
parameters:(NSDictionary *)someParameters withTarget:(NSString *)aTarget
87
inContext:(NSDictionary *)_ctx
90
NSString *targetString;
93
if ([aTarget length] > 0)
94
targetString = [NSString stringWithFormat:@" target = \"%@\"", aTarget];
98
result = [NSString stringWithFormat:
99
@"<a href=\"/cgi-bin/WebObjects/NewsX.woa/wa/%@\" %@>%@</a>",
100
[someParameters objectForKey:@"page"],
106
- (NSString *)insertPreprocessedTextForKey:(NSString *)aKey
107
inContext:(NSDictionary *)_ctx
109
return [_ctx objectForKey:aKey];
112
@end /* StructuredTextRenderingDelegate_XHTML */
114
@implementation NSArray (StructuredText_XHTML)
116
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
117
NSMutableString *result;
121
result = [NSMutableString stringWithCapacity:(c * 16)];
122
for (i = 0; i < c; i++) {
125
currentObject = [self objectAtIndex:i];
126
[result appendString:[currentObject toXhtmlInContext:_ctx]];
134
@implementation StructuredText(StructuredText_XHTML)
136
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
137
return [[self document] toXhtmlInContext:_ctx];
140
@end /* StructuredText(StructuredText_XHTML) */
142
@implementation StructuredTextDocument(StructuredText_XHTML)
144
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
145
return [[self bodyElements] toXhtmlInContext:_ctx];
148
@end /* StructuredTextDocument(StructuredText_XHTML) */
150
@implementation StructuredTextBodyElement(StructuredText_XHTML)
152
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
153
return [[self elements] toXhtmlInContext:_ctx];
156
@end /* StructuredTextBodyElement(StructuredText_XHTML) */
158
@implementation StructuredTextHeader(StructuredText_XHTML)
160
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
164
delegate = [StructuredTextRenderingDelegate_XHTML delegate] ;
166
ms = [NSMutableString stringWithCapacity:64];
167
[ms appendFormat:@"<h%d>", [self level]];
168
[ms appendString:[self textParsedWithDelegate:delegate inContext:_ctx]];
169
[ms appendFormat:@"</h%d>", [self level]];
171
[ms appendString:[super toXhtmlInContext:_ctx]];
175
@end /* StructuredTextHeader(StructuredText_XHTML) */
177
@implementation StructuredTextParagraph(StructuredText_XHTML)
179
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
182
delegate = [StructuredTextRenderingDelegate_XHTML delegate];
183
return [self textParsedWithDelegate:delegate inContext:_ctx];
186
@end /* StructuredTextParagraph (StructuredText_XHTML) */
188
@implementation StructuredTextList(StructuredText_XHTML)
190
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
194
elemText = [[self elements] toXhtmlInContext:_ctx];
196
switch ([self typology]) {
197
case StructuredTextList_BULLET: {
198
result = [NSString stringWithFormat:@"<ul>%@</ul>", elemText];
201
case StructuredTextList_ENUMERATED: {
202
result = [NSString stringWithFormat:@"<ol>%@</ol>", elemText];
205
case StructuredTextList_DEFINITION: {
206
result = [NSString stringWithFormat:@"<dl>%@</dl>", elemText];
217
@end /* StructuredTextList(StructuredText_XHTML) */
219
@implementation StructuredTextListItem(StructuredText_XHTML)
221
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
223
NSString *textParsed;
226
elemText = [[self elements] toXhtmlInContext:_ctx];
227
textParsed = [self textParsedWithDelegate:
228
[StructuredTextRenderingDelegate_XHTML delegate]
231
switch ([[self list] typology]) {
232
case StructuredTextList_BULLET: {
233
result = [NSString stringWithFormat:@"<li>%@%@</li>",
234
textParsed, elemText];
237
case StructuredTextList_ENUMERATED: {
238
result = [NSString stringWithFormat:@"<li>%@%@</li>",
239
textParsed, elemText];
242
case StructuredTextList_DEFINITION: {
243
result = [NSString stringWithFormat:@"<dt>%@</dt><dd>%@</dd>",
244
[self titleParsedWithDelegate:
245
[StructuredTextRenderingDelegate_XHTML delegate]
259
@end /* StructuredTextListItem(StructuredText_XHTML) */
261
@implementation StructuredTextLiteralBlock(StructuredText_XHTML)
263
- (NSString *)toXhtmlInContext:(NSDictionary *)_ctx {
264
return [NSString stringWithFormat:
265
@"<div class=\"preformatted\">%@</div>", [self text]];
268
@end /* StructuredTextLiteralBlock(StructuredText_XHTML) */