diff --git a/src/Microdown-BrowserExtensions/Class.extension.st b/src/Microdown-BrowserExtensions/Class.extension.st index 6eb2d249..6172aa4a 100644 --- a/src/Microdown-BrowserExtensions/Class.extension.st +++ b/src/Microdown-BrowserExtensions/Class.extension.st @@ -29,18 +29,8 @@ Class >> addDocumentSectionTo: aBuilder label: label methods: methods [ { #category : '*Microdown-BrowserExtensions' } Class >> buildMicroDownUsing: aBuilder withComment: aString [ - aBuilder - header: [ aBuilder text: 'Class: '. - aBuilder text: self name ] withLevel: 1; - horizontalLine; - text: aString. - - self addDocumentSectionExampleCodeTo: aBuilder. - - self - addDocumentSectionTo: aBuilder - label: 'Examples' - methods: (self class methods select: [ :each | each protocol = self documentExamplesProtocol ]) + aString. + ] { #category : '*Microdown-BrowserExtensions' } diff --git a/src/Microdown-Tests/MicElementTest.class.st b/src/Microdown-Tests/MicElementTest.class.st index 58e69a76..73536704 100644 --- a/src/Microdown-Tests/MicElementTest.class.st +++ b/src/Microdown-Tests/MicElementTest.class.st @@ -5,7 +5,7 @@ Class { 'parser' ], #pools : [ - 'MicMicrodownSharedPool' + 'MicSharedPool' ], #category : 'Microdown-Tests-Parser', #package : 'Microdown-Tests', diff --git a/src/Microdown-Tests/MicInlineBlockTest.class.st b/src/Microdown-Tests/MicInlineBlockTest.class.st index fd80fb29..5d017c19 100644 --- a/src/Microdown-Tests/MicInlineBlockTest.class.st +++ b/src/Microdown-Tests/MicInlineBlockTest.class.st @@ -2,7 +2,7 @@ Class { #name : 'MicInlineBlockTest', #superclass : 'TestCase', #pools : [ - 'MicMicrodownSharedPool' + 'MicSharedPool' ], #category : 'Microdown-Tests-InlineParser', #package : 'Microdown-Tests', diff --git a/src/Microdown-Tests/MicInlineParserTest.class.st b/src/Microdown-Tests/MicInlineParserTest.class.st index c6c997d4..cdbd1acd 100644 --- a/src/Microdown-Tests/MicInlineParserTest.class.st +++ b/src/Microdown-Tests/MicInlineParserTest.class.st @@ -2,7 +2,7 @@ Class { #name : 'MicInlineParserTest', #superclass : 'TestCase', #pools : [ - 'MicMicrodownSharedPool' + 'MicSharedPool' ], #category : 'Microdown-Tests-InlineParser', #package : 'Microdown-Tests', diff --git a/src/Microdown-Tests/MicInlineTokenStreamTest.class.st b/src/Microdown-Tests/MicInlineTokenStreamTest.class.st index 825d63fe..a84133dc 100644 --- a/src/Microdown-Tests/MicInlineTokenStreamTest.class.st +++ b/src/Microdown-Tests/MicInlineTokenStreamTest.class.st @@ -5,7 +5,7 @@ Class { #name : 'MicInlineTokenStreamTest', #superclass : 'TestCase', #pools : [ - 'MicMicrodownSharedPool' + 'MicSharedPool' ], #category : 'Microdown-Tests-InlineParser', #package : 'Microdown-Tests', diff --git a/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st b/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st index aa8937d8..eee75c7c 100644 --- a/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st +++ b/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st @@ -26,7 +26,7 @@ Class { 'parserClass' ], #pools : [ - 'MicMicrodownSharedPool' + 'MicSharedPool' ], #category : 'Microdown-Tests-Snippets', #package : 'Microdown-Tests', diff --git a/src/Microdown-Tests/MicMicrodownTextualBuilderTest.class.st b/src/Microdown-Tests/MicMicrodownTextualBuilderTest.class.st index f015d7e9..0b8730d8 100644 --- a/src/Microdown-Tests/MicMicrodownTextualBuilderTest.class.st +++ b/src/Microdown-Tests/MicMicrodownTextualBuilderTest.class.st @@ -9,7 +9,7 @@ Class { 'builder' ], #pools : [ - 'MicMicrodownSharedPool' + 'MicSharedPool' ], #category : 'Microdown-Tests-Builder', #package : 'Microdown-Tests', diff --git a/src/Microdown-Tests/MicParserTest.class.st b/src/Microdown-Tests/MicParserTest.class.st index 4ddf27ab..4c7078cc 100644 --- a/src/Microdown-Tests/MicParserTest.class.st +++ b/src/Microdown-Tests/MicParserTest.class.st @@ -5,7 +5,7 @@ Class { 'parser' ], #pools : [ - 'MicMicrodownSharedPool' + 'MicSharedPool' ], #category : 'Microdown-Tests-Parser', #package : 'Microdown-Tests', diff --git a/src/Microdown-Tests/MicRawBlockTest.class.st b/src/Microdown-Tests/MicRawBlockTest.class.st index 4692d388..caea092d 100644 --- a/src/Microdown-Tests/MicRawBlockTest.class.st +++ b/src/Microdown-Tests/MicRawBlockTest.class.st @@ -11,6 +11,17 @@ MicRawBlockTest >> subjectClass [ ^ MicRawBlock ] +{ #category : 'tests' } +MicRawBlockTest >> testASimpleRawParagaaph [ + | mic | + mic := (parser parse: ' +No idea what it is :) +') children first. + self assert: mic class equals: MicRawParagraphBlock. + self assert: mic label equals: 'title'. + +] + { #category : 'tests' } MicRawBlockTest >> testRaw [ diff --git a/src/Microdown-Tests/MicRawParagraphBlockTest.class.st b/src/Microdown-Tests/MicRawParagraphBlockTest.class.st new file mode 100644 index 00000000..042d7ef7 --- /dev/null +++ b/src/Microdown-Tests/MicRawParagraphBlockTest.class.st @@ -0,0 +1,74 @@ +Class { + #name : 'MicRawParagraphBlockTest', + #superclass : 'MicBlockTest', + #category : 'Microdown-Tests', + #package : 'Microdown-Tests' +} + +{ #category : 'tests' } +MicRawParagraphBlockTest >> subjectClass [ + ^ MicRawParagraphBlock +] + +{ #category : 'tests' } +MicRawParagraphBlockTest >> testASimpleRawParagraph [ + | mic | + mic := (parser parse: ' +No idea what it is :) +') children first. + self assert: mic class equals: MicRawParagraphBlock. + self assert: mic label equals: 'title'. + +] + +{ #category : 'tests' } +MicRawParagraphBlockTest >> testNotASimpleRawParagraph [ + | mic | + mic := (parser parse: ' +No idea what it is :) +') children first. + self assert: mic class equals: MicParagraphBlock. + +] + +{ #category : 'tests' } +MicRawParagraphBlockTest >> testNotASimpleRawParagraphNoSpaceInFrontToClose [ + | children | + children := (parser parse: ' +No idea what it is :) + + +And after we get a paragraph') children. + self assert: children size equals: 1. + "so far we eat as much as we can and put everything in the raw" + + + self assert: children first class equals: MicRawParagraphBlock. + +] + +{ #category : 'tests' } +MicRawParagraphBlockTest >> testRawParagraphCannotBeNested [ + | children | + children := (parser parse: ' +No idea what it is :) + +<button> +hkhkjhkj +</button> +') children. + self assert: children size equals: 1. + self assert: children first class equals: MicRawParagraphBlock. + self assert: children first label equals: 'title'. + +] + +{ #category : 'tests' } +MicRawParagraphBlockTest >> testThereIsNoValidationIfThetagStartWithAKnowHtml [ + | mic | + mic := (parser parse: ' +No idea what it is :) +') children first. + self assert: mic class equals: MicRawParagraphBlock. + +] diff --git a/src/Microdown-Tests/MicScriptBlockExtensionTest.class.st b/src/Microdown-Tests/MicScriptBlockExtensionTest.class.st index ee95544a..063e350f 100644 --- a/src/Microdown-Tests/MicScriptBlockExtensionTest.class.st +++ b/src/Microdown-Tests/MicScriptBlockExtensionTest.class.st @@ -2,7 +2,7 @@ Class { #name : 'MicScriptBlockExtensionTest', #superclass : 'TestCase', #pools : [ - 'MicMicrodownSharedPool' + 'MicSharedPool' ], #category : 'Microdown-Tests-Extensions', #package : 'Microdown-Tests', diff --git a/src/Microdown-Tests/MicrodownParserTest.class.st b/src/Microdown-Tests/MicrodownParserTest.class.st index 64b69c25..d8491ffa 100644 --- a/src/Microdown-Tests/MicrodownParserTest.class.st +++ b/src/Microdown-Tests/MicrodownParserTest.class.st @@ -5,7 +5,7 @@ Class { 'parser' ], #pools : [ - 'MicMicrodownSharedPool' + 'MicSharedPool' ], #category : 'Microdown-Tests-Parser', #package : 'Microdown-Tests', diff --git a/src/Microdown/MicAbstractBlock.class.st b/src/Microdown/MicAbstractBlock.class.st index 89866392..8ff2ac8c 100644 --- a/src/Microdown/MicAbstractBlock.class.st +++ b/src/Microdown/MicAbstractBlock.class.st @@ -21,7 +21,8 @@ Class { { #category : 'public' } MicAbstractBlock class >> alternateBlockClassFor: line [ "This hook supports extensions of environments. - we get > blockExtensionStarterClassFrom: line [ { #category : 'public' } MicAbstractBlock >> blockStarterClassFrom: line [ - "return the class of a block which can start with line, or nil if none" + "Return the class of a block which can start with line, or nil if none. + The principle is the following + - first we get a class + - then such class as environment are asked since they can act as factory + and return other classes. + For example > addDocumentDefinedEnvironments: aBuilder [ { #category : 'public' } MicEnvironmentBlock class >> alternateBlockClassFor: line [ - "If there is one subclass with the corresponding tag, returns it, else resturn the current class." + "If there is one subclass with the corresponding tag, returns it, else return the current class." "line is of the form > handlesUriScheme: scheme [ + ^ scheme beginsWith: 'mailto' +] diff --git a/src/Microdown/MicMetaDataBlock.class.st b/src/Microdown/MicMetaDataBlock.class.st index 67fff225..a4a9349f 100644 --- a/src/Microdown/MicMetaDataBlock.class.st +++ b/src/Microdown/MicMetaDataBlock.class.st @@ -21,9 +21,9 @@ Class { #instVars : [ 'bogusParsing' ], - #category : 'Microdown-BookRelated', + #category : 'Microdown-Extensions', #package : 'Microdown', - #tag : 'BookRelated' + #tag : 'Extensions' } { #category : 'markups' } diff --git a/src/Microdown/MicRawParagraphBlock.class.st b/src/Microdown/MicRawParagraphBlock.class.st new file mode 100644 index 00000000..b31e9a5e --- /dev/null +++ b/src/Microdown/MicRawParagraphBlock.class.st @@ -0,0 +1,37 @@ +Class { + #name : 'MicRawParagraphBlock', + #superclass : 'MicStartStopMarkupBlock', + #instVars : [ + 'label' + ], + #category : 'Microdown-Extensions', + #package : 'Microdown', + #tag : 'Extensions' +} + +{ #category : 'handle' } +MicRawParagraphBlock >> bodyFromLine: line [ + + (self doesLineStartWithStopMarkup: line) + ifTrue: [ isClosed := true ] + ifFalse: [ body := body ifNil: [ line ] ifNotNil: [ body , String cr , line ] ] +] + +{ #category : 'handle' } +MicRawParagraphBlock >> extractFirstLineFrom: line [ + "we cannot know in advance the markup so we have to guess and store it for closing." + + label := line allButFirst copyUpToSubstring: '>' + +] + +{ #category : 'accessing' } +MicRawParagraphBlock >> label [ + ^ label +] + +{ #category : 'markups' } +MicRawParagraphBlock >> lineStopMarkup [ + + ^ '' +] diff --git a/src/Microdown/MicMicrodownSharedPool.class.st b/src/Microdown/MicSharedPool.class.st similarity index 59% rename from src/Microdown/MicMicrodownSharedPool.class.st rename to src/Microdown/MicSharedPool.class.st index 49f4d243..0a38485f 100644 --- a/src/Microdown/MicMicrodownSharedPool.class.st +++ b/src/Microdown/MicSharedPool.class.st @@ -2,7 +2,7 @@ I define all the constants for parsing Microdown blocks. " Class { - #name : 'MicMicrodownSharedPool', + #name : 'MicSharedPool', #superclass : 'SharedPool', #classVars : [ 'AnchorMarkup', @@ -25,8 +25,10 @@ Class { 'EnvironmentOpeningBlockMarkup', 'FigureNameOpenerMarkup', 'FixiousTextDelimiter', + 'HTMLTags', 'HeaderMarkup', 'HorizontalLineMarkup', + 'InlineSpace', 'ItalicMarkup', 'LinkNameCloserMarkup', 'LinkNameOpenerMarkup', @@ -43,6 +45,7 @@ Class { 'RawOpenerMarkup', 'StrikeMarkup', 'TableCellMarkup', + 'ThreeLettersHTMLTags', 'URLCloserMarkup', 'URLOpenerMarkup', 'UnorderedListMarkup', @@ -55,7 +58,14 @@ Class { } { #category : 'class initialization' } -MicMicrodownSharedPool class >> initialize [ +MicSharedPool class >> htmlTags [ + "Pay attention that br is not in this list!" + + ^ #('!--' 'a' 'abbr' 'address' 'area' 'article' 'aside' 'audio' 'b' 'base' 'bdi' 'bdo' 'blockquote' 'body' 'button' 'canvas' 'caption' 'cite' 'code' 'col' 'colgroup' 'data' 'datalist' 'dd' 'del' 'details' 'dfn' 'dialog' 'div' 'dl' 'dt' 'em' 'embed' 'fieldset' 'figcaption' 'figure' 'footer' 'form' 'h1' 'h2' 'h3' 'h4' 'h5' 'h6' 'head' 'header' 'hgroup' 'hr' 'html' 'i' 'iframe' 'img' 'input' 'ins' 'kbd' 'label' 'legend' 'li' 'link' 'main' 'map' 'mark' 'menu' 'meta' 'meter' 'nav' 'noscript' 'object' 'ol' 'optgroup' 'option' 'output' 'p' 'param' 'picture' 'pre' 'progress' 'q' 'rb' 'rp' 'rt' 'rtc' 'ruby' 's' 'samp' 'script' 'section' 'select' 'slot' 'small' 'source' 'span' 'strong' 'style' 'sub' 'summary' 'sup' 'table' 'tbody' 'td' 'template' 'textarea' 'tfoot' 'th' 'thead' 'time' 'title' 'tr' 'track' 'u' 'ul' 'var' 'video' 'wbr') +] + +{ #category : 'class initialization' } +MicSharedPool class >> initialize [ "self initialize" AnchorMarkup := '@'. @@ -84,14 +94,14 @@ MicMicrodownSharedPool class >> initialize [ ArgumentListEqualsDelimiter := '='. ArgumentListOfFigureStartDelimiter := '?'. ArgumentListStartDelimiter := '|'. - - + AnchorReferenceCloserMarkup := '@*'. AnchorReferenceOpenerMarkup := '*@'. AnnotationCloserMarkup := '!}'. AnnotationOpenerMarkup := '{!'. + InlineSpace := '
'. BoldMarkup := '**'. FigureNameOpenerMarkup := '!['. ItalicMarkup := '_'. @@ -107,6 +117,9 @@ MicMicrodownSharedPool class >> initialize [ NameCloserUrlOpener := ']('. FixiousTextDelimiter := 0 asCharacter asString. + self initializeRawParagraph. + + Delimiters := { AnchorReferenceCloserMarkup . AnchorReferenceOpenerMarkup . AnnotationCloserMarkup . @@ -140,4 +153,20 @@ MicMicrodownSharedPool class >> initialize [ +] + +{ #category : 'class initialization' } +MicSharedPool class >> initializeRawParagraph [ + "self initializeRawParagraph" + + HTMLTags := self htmlTags. + ThreeLettersHTMLTags := self threeLetterhtmlTags +] + +{ #category : 'class initialization' } +MicSharedPool class >> threeLetterhtmlTags [ + "self threeLetterhtmlTags #('!--' 'a' 'abb' 'add' 'are' 'art' 'asi' 'aud' 'b' 'bas' 'bdi' 'bdo' 'blo' 'bod' 'br' 'but' 'can' 'cap' 'cit' 'cod' 'col' 'col' 'dat' 'dat' 'dd' 'del' 'det' 'dfn' 'dia' 'div' 'dl' 'dt' 'em' 'emb' 'fie' 'fig' 'fig' 'foo' 'for' 'h1' 'h2' 'h3' 'h4' 'h5' 'h6' 'hea' 'hea' 'hgr' 'hr' 'htm' 'i' 'ifr' 'img' 'inp' 'ins' 'kbd' 'lab' 'leg' 'li' 'lin' 'mai' 'map' 'mar' 'men' 'met' 'met' 'nav' 'nos' 'obj' 'ol' 'opt' 'opt' 'out' 'p' 'par' 'pic' 'pre' 'pro' 'q' 'rb' 'rp' 'rt' 'rtc' 'rub' 's' 'sam' 'scr' 'sec' 'sel' 'slo' 'sma' 'sou' 'spa' 'str' 'sty' 'sub' 'sum' 'sup' 'tab' 'tbo' 'td' 'tem' 'tex' 'tfo' 'th' 'the' 'tim' 'tit' 'tr' 'tra' 'u' 'ul' 'var' 'vid' 'wbr')" + "self threeLetterhtmlTags size = self htmlTags size is true so with 3 letter we can distinguish uniquely tags." + + ^ self htmlTags collect: [ :each | each truncateTo: 3 ] ] diff --git a/src/Microdown/MicStartStopMarkupBlock.class.st b/src/Microdown/MicStartStopMarkupBlock.class.st index 2143c081..c1ccefb4 100644 --- a/src/Microdown/MicStartStopMarkupBlock.class.st +++ b/src/Microdown/MicStartStopMarkupBlock.class.st @@ -73,14 +73,6 @@ MicStartStopMarkupBlock >> canConsumeLine: line [ ^ true ] -{ #category : 'testing' } -MicStartStopMarkupBlock >> doesLineStartWithMarkup: line [ - "return if the line starts with a markup" - - ^ line beginsWith: self lineStartMarkup - -] - { #category : 'testing' } MicStartStopMarkupBlock >> doesLineStartWithStopMarkup: line [ diff --git a/src/Microdown/MicroSharedPool.class.st b/src/Microdown/MicroSharedPool.class.st deleted file mode 100644 index d5e888bd..00000000 --- a/src/Microdown/MicroSharedPool.class.st +++ /dev/null @@ -1,7 +0,0 @@ -Class { - #name : 'MicroSharedPool', - #superclass : 'MicMicrodownSharedPool', - #category : 'Microdown-Parser', - #package : 'Microdown', - #tag : 'Parser' -} diff --git a/src/Microdown/MicrodownParser.class.st b/src/Microdown/MicrodownParser.class.st index 773ea59a..22e551a4 100644 --- a/src/Microdown/MicrodownParser.class.st +++ b/src/Microdown/MicrodownParser.class.st @@ -175,7 +175,7 @@ Class { 'dispatchTable' ], #pools : [ - 'MicMicrodownSharedPool' + 'MicSharedPool' ], #category : 'Microdown-Parser', #package : 'Microdown', @@ -202,20 +202,32 @@ MicrodownParser class >> parse: aString [ { #category : 'node creation' } MicrodownParser >> blockStarterClassFrom: line [ "return the class of a block which can start with line, or nil if none" - + line ifEmpty: [ ^ nil ]. (self matchOrdered: line) ifTrue: [ ^ self orderedListBlockClass ] ifFalse: [ + "right now this is super ugly and slow + but this is to try. Once we understand and probably change the environment syntax for now it is