From 234c47027b03241a3ca8361c64177eb09e38a4fa Mon Sep 17 00:00:00 2001 From: kasperosterbye Date: Wed, 28 Sep 2022 10:02:41 +0200 Subject: [PATCH] Fixes #556, allowing tabs to be preserved in code blocks (and elsewhere) --- .../MicHTMLVisitorTest.class.st | 15 ++++++------- .../MicSBALaTeXWriterTest.class.st | 17 +++++++++----- .../MicTextualMicrodownExporterTest.class.st | 4 ++-- .../MicRichTextComposerTest.class.st | 15 +++++++++++++ .../MicRichTextComposer.class.st | 1 - .../MicMicrodownSnippetFactory.class.st | 22 +++++++++---------- src/Microdown/MicrodownParser.class.st | 18 ++++++--------- 7 files changed, 53 insertions(+), 39 deletions(-) diff --git a/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st b/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st index ea56ca0d..07497766 100644 --- a/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st +++ b/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st @@ -88,16 +88,15 @@ MicHTMLVisitorTest >> testContents [ { #category : #tests } MicHTMLVisitorTest >> testConvertMicFile [ - + writer convertMicFile: (fileSystem / 'anExample1.md') asFileReference. - + self assert: (fileSystem / 'anExample1.html') asFileReference exists. - self - assert: (fileSystem / 'anExample1.html') asFileReference contents - equals: newLine , -'

Foo

', newLine , -'

Pharo is cool

', newLine , -'
 this is a code blu blu
', newLine + self + assert: (fileSystem / 'anExample1.html') asFileReference contents + equals: newLine , '

Foo

' , newLine + , '

Pharo is cool

' , newLine + , '
	this is a code blu blu
' , newLine ] { #category : #tests } diff --git a/src/Microdown-LaTeXExporter-Tests/MicSBALaTeXWriterTest.class.st b/src/Microdown-LaTeXExporter-Tests/MicSBALaTeXWriterTest.class.st index 06a2c47a..790ee857 100644 --- a/src/Microdown-LaTeXExporter-Tests/MicSBALaTeXWriterTest.class.st +++ b/src/Microdown-LaTeXExporter-Tests/MicSBALaTeXWriterTest.class.st @@ -41,12 +41,17 @@ MicSBALaTeXWriterTest >> testCodeblockWithCaption [ { #category : #tests } MicSBALaTeXWriterTest >> testCodeblockWithChevron [ - self writeFor: (factory codeblock: 'caption=Pharo is **cool**' body: 'MyClass >> foo - this is a code'). - self assert: writer contents equals: '\begin{listing}[float]{smalltalk}{Pharo is \textbf{cool}}', newLine , - 'MyClass >> foo', newLine , - ' this is a code', newLine , - '\end{listing}', newLine + self writeFor: + (factory + codeblock: 'caption=Pharo is **cool**' + body: 'MyClass >> foo + this is a code'). + self + assert: writer contents + equals: + '\begin{listing}[float]{smalltalk}{Pharo is \textbf{cool}}' + , newLine , 'MyClass >> foo' , newLine , ' this is a code' + , newLine , '\end{listing}' , newLine ] { #category : #tests } diff --git a/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st b/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st index 47289a0a..df9fdc0b 100644 --- a/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st +++ b/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st @@ -85,14 +85,14 @@ MicTextualMicrodownExporterTest >> testCodeBlock [ { #category : #'tests-codeblock' } MicTextualMicrodownExporterTest >> testCodeBlockNewLine [ - + | mic | mic := parser parse: '``` this is a codeblock ```'. self assert: (mic accept: visitor) contents equals: ' ``` - this is a codeblock + this is a codeblock ``` ' ] diff --git a/src/Microdown-RichTextComposer-Tests/MicRichTextComposerTest.class.st b/src/Microdown-RichTextComposer-Tests/MicRichTextComposerTest.class.st index ee96f28a..07fbbf8c 100644 --- a/src/Microdown-RichTextComposer-Tests/MicRichTextComposerTest.class.st +++ b/src/Microdown-RichTextComposer-Tests/MicRichTextComposerTest.class.st @@ -277,6 +277,21 @@ line 2 Roger Rabbit' ] +{ #category : #'tests - codeBlock' } +MicRichTextComposerTest >> testCodeBlockWithTabbedCode [ + + | source richText | + source := ' +``` +7 + 8 +``` +'. + richText := self richTextForString: source. + self assert: richText asString trim equals: '7 + 8' +] + { #category : #tests } MicRichTextComposerTest >> testEnvironment_unknownShouldNotFail [ | src | diff --git a/src/Microdown-RichTextComposer/MicRichTextComposer.class.st b/src/Microdown-RichTextComposer/MicRichTextComposer.class.st index 8cc94bb2..c77fa142 100644 --- a/src/Microdown-RichTextComposer/MicRichTextComposer.class.st +++ b/src/Microdown-RichTextComposer/MicRichTextComposer.class.st @@ -382,7 +382,6 @@ MicRichTextComposer >> visitCenter: aMicCenterBlock [ { #category : #visiting } MicRichTextComposer >> visitCode: aCodeBlock [ - canvas newLineIfNotAlready. canvas indentIn: [ canvas diff --git a/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st b/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st index 40b8a589..606fc4d4 100644 --- a/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st +++ b/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st @@ -634,11 +634,11 @@ MicMicrodownSnippetFactory >> nestedOrderedList2Sample [ ^ ' - Foo - Bar - 1. B - 1. a - 1. r - - 3rdlvel - - 3rdlevl2 + 1. B + 1. a + 1. r + - 3rdlvel + - 3rdlevl2 - Zork ' ] @@ -648,9 +648,9 @@ MicMicrodownSnippetFactory >> nestedOrderedListSample [ ^ ' - Foo - Bar - 1. B - 1. a - 1. r + 1. B + 1. a + 1. r ' ] @@ -659,9 +659,9 @@ MicMicrodownSnippetFactory >> nestedUnorderedListSample [ ^ ' - Foo - Bar - - B - - a - - r + - B + - a + - r ' ] diff --git a/src/Microdown/MicrodownParser.class.st b/src/Microdown/MicrodownParser.class.st index 58cb4171..c58f1e35 100644 --- a/src/Microdown/MicrodownParser.class.st +++ b/src/Microdown/MicrodownParser.class.st @@ -226,22 +226,18 @@ MicrodownParser >> delimiterBlockClassFor: prefix [ { #category : #parsing } MicrodownParser >> handleLine: line [ + "The logic is the following: - -first line is cleaned to avoid noise, - -then if the current block can consume the line, it manages it and this potentially creates a new block that becomes the current one. + -if the current block can consume the line, it manages it and this potentially creates a new block that becomes the current one. When the line is not consumed, the current block is closed and its parent becomes the current one and the process is called back to treat the line." - - | normalized | - normalized := line copyReplaceAll: String tab with: String space. - - (current canConsumeLine: normalized) + + (current canConsumeLine: line) ifTrue: [ - current := current addLineAndReturnNextNode: normalized. + current := current addLineAndReturnNextNode: line. ^ current ] - ifFalse: [ - current closeMe ]. + ifFalse: [ current closeMe ]. current := current parent. - self handleLine: normalized + self handleLine: line ] { #category : #initialization }