Skip to content

Commit 0121cd3

Browse files
authored
Merge pull request pillar-markup#1004 from pillar-markup/enh/Raw
Enh/raw
2 parents 83b1ec5 + 89664c3 commit 0121cd3

21 files changed

Lines changed: 879 additions & 624 deletions

src/Microdown-HTMLExporter-Tests/MicHTMLExporterTest.class.st

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ MicHTMLExporterTest >> factory: aFactory [
3030
factory := aFactory new
3131
]
3232

33+
{ #category : 'accessing' }
34+
MicHTMLExporterTest >> newLine [
35+
36+
^ newLine
37+
]
38+
3339
{ #category : 'accessing' }
3440
MicHTMLExporterTest >> newLine: aNewLine [
3541
(aNewLine = String cr) ifTrue:[ writer crAsNewLine ].
@@ -39,7 +45,7 @@ MicHTMLExporterTest >> newLine: aNewLine [
3945
]
4046

4147
{ #category : 'tests - paragraph' }
42-
MicHTMLExporterTest >> newLines: aString [
48+
MicHTMLExporterTest >> newLineParagraphAround: aString [
4349

4450
^ newLine, '<p>', aString, '</p>', newLine
4551
]
@@ -105,7 +111,7 @@ I''m really interested in any topics that evolve Pharo into a better Pharo.
105111
{ #category : 'tests - paragraph' }
106112
MicHTMLExporterTest >> testAccents [
107113

108-
self parse: 'éà' andCheckWeGet: (self newLines:
114+
self parse: 'éà' andCheckWeGet: (self newLineParagraphAround:
109115
'éà')
110116
]
111117

@@ -144,7 +150,7 @@ MicHTMLExporterTest >> testFigure [
144150

145151
self
146152
parse: factory figureSample
147-
andCheckWeGet: (self newLines:
153+
andCheckWeGet: (self newLineParagraphAround:
148154
'<figure><img src="/anUrl" alt="Foo" class="figureTest" width="80"><figcaption>Foo</figcaption></img></figure>')
149155
]
150156

@@ -153,7 +159,7 @@ MicHTMLExporterTest >> testFigureBold [
153159

154160
self
155161
parse: factory figureBoldSample
156-
andCheckWeGet: (self newLines:
162+
andCheckWeGet: (self newLineParagraphAround:
157163
'<figure><img src="/anUrl" alt="Foo" class="figureTest" width="80"><figcaption><strong>Foo</strong></figcaption></img></figure>' )
158164
]
159165

@@ -162,7 +168,7 @@ MicHTMLExporterTest >> testFigureItalic [
162168

163169
self
164170
parse: factory figureItalicSample
165-
andCheckWeGet: (self newLines:
171+
andCheckWeGet: (self newLineParagraphAround:
166172
'<figure><img src="/anUrl" alt="Foo" class="figureTest" width="80"><figcaption><i>Foo</i></figcaption></img></figure>')
167173
]
168174

@@ -171,7 +177,7 @@ MicHTMLExporterTest >> testFigureNested [
171177

172178
self
173179
parse: factory figureNestedSample
174-
andCheckWeGet: (self newLines:
180+
andCheckWeGet: (self newLineParagraphAround:
175181
'<figure><img src="/anUrl" alt="Foo_" class="figureTest" width="80"><figcaption><strong>Foo_</strong></figcaption></img></figure>')
176182
]
177183

@@ -180,7 +186,7 @@ MicHTMLExporterTest >> testFigureReal [
180186

181187
self
182188
parse: factory figureRealSample
183-
andCheckWeGet: (self newLines:
189+
andCheckWeGet: (self newLineParagraphAround:
184190
'<figure><img src="figures/logo.png" alt="A logo png under figures folder" class="figureTest" width="80"><figcaption>A logo png under figures folder</figcaption></img></figure>')
185191
]
186192

@@ -189,7 +195,7 @@ MicHTMLExporterTest >> testFigureStrike [
189195

190196
self
191197
parse: factory figureStrikeSample
192-
andCheckWeGet: (self newLines:
198+
andCheckWeGet: (self newLineParagraphAround:
193199
'<figure><img src="/anUrl" alt="Foo" class="figureTest" width="80"><figcaption><strike>Foo</strike></figcaption></img></figure>')
194200
]
195201

@@ -198,7 +204,7 @@ MicHTMLExporterTest >> testFigureWithLabelWithoutSize [
198204

199205
self
200206
parse: factory figureWithLabelWithoutSizeSample
201-
andCheckWeGet: (self newLines:
207+
andCheckWeGet: (self newLineParagraphAround:
202208
'<figure><img src="/anUrl" alt="Foo" class="figureTest"><figcaption>Foo</figcaption></img></figure>')
203209
]
204210

@@ -207,7 +213,7 @@ MicHTMLExporterTest >> testFigureWithoutCaption [
207213

208214
self
209215
parse: factory figureWithoutCaptionSample
210-
andCheckWeGet: (self newLines:
216+
andCheckWeGet: (self newLineParagraphAround:
211217
'<figure><img src="/anUrl" alt="" class="figureTest" width="80"><figcaption></figcaption></img></figure>')
212218
]
213219

@@ -216,7 +222,7 @@ MicHTMLExporterTest >> testFigureWithoutSizeAndLabel [
216222

217223
self
218224
parse: factory figureSampleWithoutSizeAndLabel
219-
andCheckWeGet: (self newLines:
225+
andCheckWeGet: (self newLineParagraphAround:
220226
'<figure><img src="/anUrl" alt="Foo"><figcaption>Foo</figcaption></img></figure>')
221227
]
222228

@@ -225,7 +231,7 @@ MicHTMLExporterTest >> testGoutDeFraise [
225231

226232
self
227233
parse: factory figureGoutDeFraise
228-
andCheckWeGet: (self newLines:
234+
andCheckWeGet: (self newLineParagraphAround:
229235
'<figure><img src="un-gout-de-fraise.jpg" alt="Proposition pour le thème : Un goût de fraise"><figcaption>Proposition pour le thème : <i>Un goût de fraise</i></figcaption></img></figure>')
230236
]
231237

@@ -280,20 +286,20 @@ MicHTMLExporterTest >> testOrderedListIsRecognized [
280286
{ #category : 'tests - paragraph' }
281287
MicHTMLExporterTest >> testParagraph [
282288

283-
self parse: factory paragraphSample andCheckWeGet: (self newLines: 'Foo')
289+
self parse: factory paragraphSample andCheckWeGet: (self newLineParagraphAround: 'Foo')
284290
]
285291

286292
{ #category : 'tests' }
287293
MicHTMLExporterTest >> testParagraphLongWithAccents [
288294

289-
self parse: factory paragraphOnMultipleLinesSample andCheckWeGet: (self newLines:
295+
self parse: factory paragraphOnMultipleLinesSample andCheckWeGet: (self newLineParagraphAround:
290296
'Je ne connais pas la peur, car la peur tue l''esprit. La peur est la petite mort qui conduit à l''oblitération totale. J''affonterai ma peur. Je lui permettrais de passer sur moi, au travers de moi. Et lorsqu''elle sera passée, je tournerai mon oeil interieur sur son chemin. Et là où elle sera passée, il n''y aura plus rien, rien que moi.')
291297
]
292298

293299
{ #category : 'tests - formats' }
294300
MicHTMLExporterTest >> testParagraphNestedSample [
295301

296-
self parse: factory paragraphNestedSample andCheckWeGet: (self newLines:
302+
self parse: factory paragraphNestedSample andCheckWeGet: (self newLineParagraphAround:
297303
'this is a <strong><i>paragraph</i></strong>')
298304
]
299305

@@ -302,21 +308,21 @@ MicHTMLExporterTest >> testParagraphWithBold [
302308

303309
self
304310
parse: factory paragraphBoldSample
305-
andCheckWeGet: (self newLines:
311+
andCheckWeGet: (self newLineParagraphAround:
306312
'this is a <strong>paragraph</strong>')
307313
]
308314

309315
{ #category : 'tests' }
310316
MicHTMLExporterTest >> testParagraphWithItalic [
311317

312-
self parse: factory paragraphItalicSample andCheckWeGet: (self newLines:
318+
self parse: factory paragraphItalicSample andCheckWeGet: (self newLineParagraphAround:
313319
'this is a <i>paragraph</i>')
314320
]
315321

316322
{ #category : 'tests - formats' }
317323
MicHTMLExporterTest >> testParagraphWithMonospace [
318324

319-
self parse: factory paragraphMonospaceSample andCheckWeGet: (self newLines:
325+
self parse: factory paragraphMonospaceSample andCheckWeGet: (self newLineParagraphAround:
320326
'this is a <code>paragraph</code>')
321327
]
322328

@@ -338,10 +344,47 @@ MicHTMLExporterTest >> testQuote [
338344
'<q>Foo</q>'
339345
]
340346

347+
{ #category : 'tests - raw' }
348+
MicHTMLExporterTest >> testRawOnMultipleLinesIsNotRawButTwoPargraphs [
349+
350+
| mic |
351+
mic := parser
352+
parse: 'some text here!{{ <a class="btn btn-block download" href="https://files.pharo.org/pharo-launcher/mac-arm64"> ', self newLine,'
353+
<i class="fa fa-apple"></i> macOs arm64</a> }}...and there'.
354+
"notice that I did on purpose that I do not have space around"
355+
356+
self assert: mic children size equals: 2.
357+
self assert: mic children first class equals: MicParagraphBlock .
358+
self assert: mic children second class equals: MicParagraphBlock .
359+
360+
361+
362+
]
363+
364+
{ #category : 'tests - raw' }
365+
MicHTMLExporterTest >> testRawOnSingleLineShouldNotGoToTheNextLine [
366+
367+
| mic |
368+
mic := parser
369+
parse: 'some text here!{{ <a class="btn btn-block download" href="https://files.pharo.org/pharo-launcher/mac-arm64"> <i class="fa fa-apple"></i> macOs arm64</a> }}...and there'.
370+
"notice that I did on purpose that I do not have space around"
371+
372+
writer visit: mic children first.
373+
self
374+
assert: writer contents
375+
equals:
376+
(
377+
self newLine, '<p>some text here! <a class="btn btn-block download" href="https://files.pharo.org/pharo-launcher/mac-arm64"> <i class="fa fa-apple"></i> macOs arm64</a> ...and there</p>', self newLine
378+
379+
)
380+
381+
382+
]
383+
341384
{ #category : 'tests - formats' }
342385
MicHTMLExporterTest >> testStrike [
343386

344-
self parse: factory strikethroughFormatSample andCheckWeGet: (self newLines:
387+
self parse: factory strikethroughFormatSample andCheckWeGet: (self newLineParagraphAround:
345388
'<strike>Foo</strike>')
346389
]
347390

src/Microdown-HTMLExporter/MicHTMLVisitor.class.st

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,22 @@ MicHTMLVisitor >> visitFigure: aFigure [
392392

393393
]
394394

395+
{ #category : 'visiting - html extensions' }
396+
MicHTMLVisitor >> visitHTMLTagParagraph: anHTMLTagParagraph [
397+
398+
canvas
399+
newLine;
400+
raw: '<' , anHTMLTagParagraph label.
401+
anHTMLTagParagraph hasArguments
402+
ifTrue: [ canvas space; raw: anHTMLTagParagraph argumentString ].
403+
canvas raw: '>' .
404+
405+
anHTMLTagParagraph children do: [ :each | each accept: self ].
406+
canvas
407+
newLine;
408+
raw: anHTMLTagParagraph lineStopMarkup.
409+
]
410+
395411
{ #category : 'visiting' }
396412
MicHTMLVisitor >> visitHeader: aHeader [
397413

@@ -545,26 +561,17 @@ MicHTMLVisitor >> visitQuote: aQuote [
545561
]
546562

547563
{ #category : 'visiting - html extensions' }
548-
MicHTMLVisitor >> visitRaw: aParagraph [
564+
MicHTMLVisitor >> visitRaw: aMicRaw [
565+
"Raw should be raw and it should NOT go the next line or whatever"
566+
"Pay attention aMicRaw is not a paragraph but an inline element."
549567

550-
canvas raw: aParagraph bodyString.
551-
canvas newLine
568+
canvas raw: aMicRaw bodyString
552569
]
553570

554571
{ #category : 'visiting - html extensions' }
555572
MicHTMLVisitor >> visitRawParagraph: aParagraph [
556573

557-
canvas
558-
newLine;
559-
raw: '<' , aParagraph label.
560-
aParagraph hasArguments
561-
ifTrue: [ canvas space; raw: aParagraph argumentString ].
562-
canvas raw: '>' .
563-
564-
aParagraph children do: [ :each | each accept: self ].
565-
canvas
566-
newLine;
567-
raw: aParagraph lineStopMarkup.
574+
canvas raw: aParagraph body
568575
]
569576

570577
{ #category : 'templating ping pong' }

src/Microdown-RichTextComposer/MicrodownParser.extension.st renamed to src/Microdown-RichTextComposer/MicParser.extension.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Extension { #name : 'MicrodownParser' }
1+
Extension { #name : 'MicParser' }
22

33
{ #category : '*Microdown-RichTextComposer' }
4-
MicrodownParser class >> convertToRichText: aString [
4+
MicParser class >> convertToRichText: aString [
55
^ MicRichTextComposer new visit: (self new parse: aString)
66
]

src/Microdown-Tests/MicAnchorLinkerTest.class.st

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Class {
1010
MicAnchorLinkerTest >> testAnchorIsAttachedToItsTarget [
1111
| linker doc |
1212
linker := MicAnchorLinker new.
13-
doc := MicrodownParser parse: '
13+
doc := MicParser parse: '
1414
this is a sentence
1515
1616
#Header1
@@ -26,7 +26,7 @@ this is a sentence
2626
MicAnchorLinkerTest >> testAnchorIsAttachedToItsTarget2 [
2727
| linker doc |
2828
linker := MicAnchorLinker new.
29-
doc := MicrodownParser parse: '
29+
doc := MicParser parse: '
3030
this is a sentence
3131
3232
#Header1
@@ -44,7 +44,7 @@ this is a sentence
4444
MicAnchorLinkerTest >> testHeaderLast [
4545
| linker doc |
4646
linker := MicAnchorLinker new.
47-
doc := MicrodownParser parse: '
47+
doc := MicParser parse: '
4848
this is a sentence
4949
5050
#Header1'.

src/Microdown-Tests/MicElementTest.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ MicElementTest >> parserClass [
2828
"This references to MicrodownParser is needed for the test.
2929
Replacing it by Microdown does not work."
3030

31-
^ MicrodownParser
31+
^ MicParser
3232
]
3333

3434
{ #category : 'running' }

0 commit comments

Comments
 (0)