-
Notifications
You must be signed in to change notification settings - Fork 3
/
EruditeXMLBook.pck.st
475 lines (347 loc) · 13.7 KB
/
EruditeXMLBook.pck.st
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
'From Cuis7.1 [latest update: #6487] on 23 June 2024 at 7:06:09 pm'!
'Description '!
!provides: 'EruditeXMLBook' 1 15!
!requires: 'Erudite' 1 267 nil!
!requires: 'YAXO' 1 27 nil!
SystemOrganization addCategory: #EruditeXMLBook!
!classDefinition: #XMLEruditeBook category: #EruditeXMLBook!
EruditeBook subclass: #XMLEruditeBook
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'XMLEruditeBook class' category: #EruditeXMLBook!
XMLEruditeBook class
instanceVariableNames: ''!
!classDefinition: #EruditeDocString category: #EruditeXMLBook!
EruditeDocNode subclass: #EruditeDocString
instanceVariableNames: 'contents'
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeDocString class' category: #EruditeXMLBook!
EruditeDocString class
instanceVariableNames: ''!
!classDefinition: #EruditeParagraphNode category: #EruditeXMLBook!
EruditeDocNode subclass: #EruditeParagraphNode
instanceVariableNames: 'contents'
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeParagraphNode class' category: #EruditeXMLBook!
EruditeParagraphNode class
instanceVariableNames: ''!
!classDefinition: #EruditeXMLElementParser category: #EruditeXMLBook!
Object subclass: #EruditeXMLElementParser
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeXMLElementParser class' category: #EruditeXMLBook!
EruditeXMLElementParser class
instanceVariableNames: ''!
!classDefinition: #EruditeXMLClassParser category: #EruditeXMLBook!
EruditeXMLElementParser subclass: #EruditeXMLClassParser
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeXMLClassParser class' category: #EruditeXMLBook!
EruditeXMLClassParser class
instanceVariableNames: ''!
!classDefinition: #EruditeXMLDoItParser category: #EruditeXMLBook!
EruditeXMLElementParser subclass: #EruditeXMLDoItParser
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeXMLDoItParser class' category: #EruditeXMLBook!
EruditeXMLDoItParser class
instanceVariableNames: ''!
!classDefinition: #EruditeXMLH1Parser category: #EruditeXMLBook!
EruditeXMLElementParser subclass: #EruditeXMLH1Parser
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeXMLH1Parser class' category: #EruditeXMLBook!
EruditeXMLH1Parser class
instanceVariableNames: ''!
!classDefinition: #EruditeXMLListItemParser category: #EruditeXMLBook!
EruditeXMLElementParser subclass: #EruditeXMLListItemParser
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeXMLListItemParser class' category: #EruditeXMLBook!
EruditeXMLListItemParser class
instanceVariableNames: ''!
!classDefinition: #EruditeXMLParagraphParser category: #EruditeXMLBook!
EruditeXMLElementParser subclass: #EruditeXMLParagraphParser
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeXMLParagraphParser class' category: #EruditeXMLBook!
EruditeXMLParagraphParser class
instanceVariableNames: ''!
!classDefinition: #EruditeXMLUnorderedListParser category: #EruditeXMLBook!
EruditeXMLElementParser subclass: #EruditeXMLUnorderedListParser
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeXMLUnorderedListParser class' category: #EruditeXMLBook!
EruditeXMLUnorderedListParser class
instanceVariableNames: ''!
!classDefinition: #EruditeXMLParser category: #EruditeXMLBook!
Object subclass: #EruditeXMLParser
instanceVariableNames: 'stream'
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeXMLParser class' category: #EruditeXMLBook!
EruditeXMLParser class
instanceVariableNames: ''!
!classDefinition: #EruditeXMLDOMParser category: #EruditeXMLBook!
XMLDOMParser subclass: #EruditeXMLDOMParser
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeXMLDOMParser class' category: #EruditeXMLBook!
EruditeXMLDOMParser class
instanceVariableNames: ''!
!classDefinition: #EruditeXMLElement category: #EruditeXMLBook!
XMLElement subclass: #EruditeXMLElement
instanceVariableNames: 'children'
classVariableNames: ''
poolDictionaries: ''
category: 'EruditeXMLBook'!
!classDefinition: 'EruditeXMLElement class' category: #EruditeXMLBook!
EruditeXMLElement class
instanceVariableNames: ''!
!XMLEruditeBook commentStamp: '<historical>' prior: 0!
|xml doc|
xml '<h1>Title</h1>
<p>Hello world</p>
<p>
<ul><li>Hello</li>
<li>World</li></ul>
</p>'.
doc EruditeXMLParser parse: xml.
(MorphicEruditeDocRenderer on: doc) render edit.
---------------
(XMLEruditeBook titled: 'My book') edit!
!XMLEruditeBook class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 15:59:28'!
parser
^ EruditeXMLParser new! !
!EruditeDocString methodsFor: 'accessing' stamp: 'MM 6/15/2024 19:27:20'!
contents
"Answer the value of contents"
^ contents! !
!EruditeDocString methodsFor: 'accessing' stamp: 'MM 6/15/2024 19:27:20'!
contents: anObject
"Set the value of contents"
contents := anObject! !
!EruditeDocString methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 19:29:41'!
accept: aVisitor
^ aVisitor visitString: self ! !
!EruditeDocString class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 19:27:40'!
contents: aString
^ self new contents: aString; yourself! !
!EruditeParagraphNode methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 19:24:36'!
accept: aVisitor
^ aVisitor visitParagraph: self! !
!EruditeParagraphNode methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 16:45:48'!
initialize
super initialize.
contents := OrderedCollection new! !
!EruditeParagraphNode methodsFor: 'accessing' stamp: 'MM 6/15/2024 16:45:57'!
contents
"Answer the value of contents"
^ contents! !
!EruditeParagraphNode methodsFor: 'accessing' stamp: 'MM 6/15/2024 16:45:57'!
contents: anObject
"Set the value of contents"
contents := anObject! !
!EruditeParagraphNode class methodsFor: 'as yet unclassified' stamp: 'MM 6/20/2024 12:21:22'!
contents: nodeContents
^ self new contents: nodeContents; yourself! !
!EruditeXMLElementParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:52:09'!
parse: anXMLElement using: aParser
^ self subclassResponsibility ! !
!EruditeXMLElementParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 16:42:20'!
tag
^ self subclassResponsibility ! !
!EruditeXMLClassParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 22:14:08'!
parse: anXMLElement using: aParser
|className|
className := anXMLElement contents first string.
^ EruditeDocLink target: className
type: #class
label: className! !
!EruditeXMLClassParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 22:11:49'!
tag
^ 'class'! !
!EruditeXMLDoItParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 22:21:50'!
parse: anXMLElement using: aParser
|code|
code := anXMLElement contents first string.
^ EruditeDocCode code: code action: (Dictionary newFromPairs: #(action doIt))! !
!EruditeXMLDoItParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 22:16:48'!
tag
^ 'doit'! !
!EruditeXMLH1Parser class methodsFor: 'as yet unclassified' stamp: 'MM 6/18/2024 00:39:02'!
parse: anXMLElement using: aParser
^ EruditeDocHeading
heading: (String streamContents: [:s |
s nextPutAll: anXMLElement contents first string;
nextPut: Character newLineCharacter ])
level: 1! !
!EruditeXMLH1Parser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 16:42:04'!
tag
^ 'h1'! !
!EruditeXMLListItemParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 18:04:20'!
parse: anXMLElement using: aParser
| li |
li := EruditeDocListItem new.
anXMLElement childrenDo: [:xmlElem |
li contents add: (aParser value: xmlElem)].
^ li! !
!EruditeXMLListItemParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 18:03:15'!
tag
^ 'li'! !
!EruditeXMLParagraphParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 18:02:24'!
parse: anXMLElement using: aParser
| paragraph |
paragraph := EruditeParagraphNode new.
anXMLElement childrenDo: [:xmlElem |
paragraph contents add: (aParser value: xmlElem)].
^ paragraph! !
!EruditeXMLParagraphParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 16:46:51'!
tag
^ 'p'! !
!EruditeXMLUnorderedListParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 18:02:16'!
parse: anXMLElement using: aParser
| list |
list := EruditeDocList new.
anXMLElement childrenDo: [:xmlElem | |listItem|
listItem := aParser value: xmlElem.
self assert: [listItem isKindOf: EruditeDocListItem] description: 'Should be a list item' .
list items add: listItem].
^ list! !
!EruditeXMLUnorderedListParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:56:30'!
tag
^ 'ul'! !
!EruditeXMLParser methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 15:43:59'!
initialize: aStream
stream := aStream.! !
!EruditeXMLParser methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 15:56:05'!
parse
^ EruditeDocument new
parser: self;
yourself! !
!EruditeXMLParser methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:54:37'!
parse: aString
| parser xml doc contents |
stream := aString readStream.
parser := EruditeXMLDOMParser.
xml := parser parseDocumentFrom: stream.
contents := OrderedCollection new.
doc := EruditeDocument new
contents: contents;
yourself.
xml elementsDo: [:xmlElem |
contents add: (self parseElement: xmlElem)].
^ doc! !
!EruditeXMLParser methodsFor: 'as yet unclassified' stamp: 'MM 6/18/2024 20:54:32'!
parseElement: anXMLElement
|tag|
(anXMLElement isKindOf: XMLStringNode) ifTrue:[
^ EruditeDocString contents: anXMLElement string].
tag := anXMLElement tag.
^ (self parserFor: tag)
parse: anXMLElement
using: [:elem | self parseElement: elem]! !
!EruditeXMLParser methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 16:05:13'!
parserAt: xmlTag
^ self parsers
detect: [:parserClass | parserClass tag sameAs: xmlTag]
ifNone: [self error: 'No parser for element: ', xmlTag]! !
!EruditeXMLParser methodsFor: 'as yet unclassified' stamp: 'MM 6/18/2024 20:54:46'!
parserFor: tag
^ self parserAt:tag! !
!EruditeXMLParser methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 16:01:31'!
parsers
^ self class parsers! !
!EruditeXMLParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 16:40:06'!
parse: aString
^ self new parse: aString! !
!EruditeXMLParser class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 16:02:39'!
parsers
^ EruditeXMLElementParser subclasses! !
!EruditeXMLDOMParser methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:41:33'!
startElement: elementName attributeList: attributeList
| newElement |
newElement := EruditeXMLElement named: elementName attributes: attributeList.
self incremental
ifFalse: [self stack isEmpty
ifFalse: [self top addElement: newElement]].
self push: newElement! !
!EruditeXMLDOMParser methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:41:38'!
startElement: localName namespaceURI: namespaceUri namespace: namespace attributeList: attributeList
| newElement |
newElement := EruditeXMLElement named: localName namespace: namespace uri: namespaceUri attributes: attributeList.
self incremental
ifFalse: [self stack isEmpty
ifFalse: [self top addElement: newElement]].
self push: newElement! !
!EruditeXMLElement methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:45:00'!
addContent: content
super addContent: content.
children addLast: content! !
!EruditeXMLElement methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:44:55'!
addElement: element
super addElement: element.
children addLast: element! !
!EruditeXMLElement methodsFor: 'as yet unclassified' stamp: 'MM 6/23/2024 18:52:04'!
attributeAt: aSymbol ifPresent: aBlock
| value |
value := self attributeAt: aSymbol.
^ value ifNotNil: [aBlock value: value]! !
!EruditeXMLElement methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:40:25'!
children
^ children! !
!EruditeXMLElement methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:40:39'!
childrenDo: aBlock
self children do: aBlock! !
!EruditeXMLElement methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:40:15'!
initialize
super initialize.
children := OrderedCollection new.! !
!EruditeXMLElement class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:46:35'!
named: aString attributes: attributeList
^ self new
name: aString;
setAttributes: attributeList.! !
!EruditeXMLElement class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:47:30'!
named: aString namespace: ns uri: uri attributes: attributeList
^ self new
name: aString;
namespace: ns
uri: uri;
setAttributes: attributeList.! !
!EruditeXMLElement class methodsFor: 'as yet unclassified' stamp: 'MM 6/15/2024 17:48:41'!
new
^ self basicNew initialize! !
!MorphicEruditeDocRenderer methodsFor: '*EruditeXMLBook' stamp: 'MM 6/20/2024 18:47:28'!
visitParagraph: aParagraph
aParagraph contents do: [:elem |
elem accept: self].
stream nextPut: Character newLineCharacter asString.
stream nextPut: Character newLineCharacter asString.
! !
!MorphicEruditeDocRenderer methodsFor: '*EruditeXMLBook' stamp: 'MM 6/15/2024 19:36:32'!
visitString: aStringNode
stream nextPut: (Text string: aStringNode contents)! !