diff --git a/src/MiniDocs/XMLElement.extension.st b/src/MiniDocs/XMLElement.extension.st index 76e8d74..895d5f6 100644 --- a/src/MiniDocs/XMLElement.extension.st +++ b/src/MiniDocs/XMLElement.extension.st @@ -9,48 +9,45 @@ XMLElement >> asSnippetDictionary [ ^ response ] +{ #category : #'*MiniDocs' } +XMLElement >> extractMarkdownImageLinkData [ + | linkParserNodes sanitizedText linkParser | + linkParser := (PPCommonMarkBlockParser parse: (self contentString trimBoth: [:each | each = Character lf]) allButFirst) + accept: CMBlockVisitor new. + linkParserNodes := linkParser children first children. + linkParserNodes size = 1 + ifTrue: [ sanitizedText := linkParserNodes first label text ] + ifFalse: [ sanitizedText := '' writeStream. + linkParserNodes allButLast + do: [ :each | + each className = 'PPCMText' + ifTrue: [ sanitizedText nextPutAll: each text allButFirst ]. + each className = 'PPCMLink' + ifTrue: [ sanitizedText nextPutAll: each printString ] ]. + sanitizedText := sanitizedText contents ]. + ^ {sanitizedText . self contentString } +] + { #category : #'*MiniDocs' } XMLElement >> sanitizedContent [ | className sanitizedText | className := self attributes at: 'st-class'. - (className = 'LeTextSnippet') - ifTrue: [ - sanitizedText := self contentString. - sanitizedText := sanitizedText allButFirst. - sanitizedText := sanitizedText allButLast. - ]. - (className = 'LePharoSnippet') ifTrue: [ | joinedText | - sanitizedText := self contentString lines. - sanitizedText := sanitizedText copyFrom: 4 to: sanitizedText size -2. - joinedText := '' writeStream. - sanitizedText do: [ :line | joinedText nextPutAll: line; nextPut: Character lf ]. - sanitizedText := joinedText contents allButLast. - ]. - (className = 'LePictureSnippet') - ifTrue: [ | linkParser linkParserNodes| - linkParser := (PPCommonMarkBlockParser parse: self contentString allButFirst) - accept: CMBlockVisitor new. - linkParserNodes := linkParser children first children. - linkParserNodes size = 1 - ifTrue: [ - linkParserNodes first className = 'PPCMLink' - ifTrue: [ sanitizedText := linkParserNodes first label text] - ifFalse: [ - sanitizedText := (linkParserNodes first text splitOn: '](') first. - sanitizedText := sanitizedText copyReplaceAll: '![' with: '' - ] - ] - ifFalse: [ - sanitizedText := '' writeStream. - linkParserNodes allButLast do: [:each | - each className = 'PPCMText' - ifTrue: [ sanitizedText nextPutAll: each text allButFirst ]. - each className = 'PPCMLink' - ifTrue: [ sanitizedText nextPutAll: each printString ] - ]. - sanitizedText := sanitizedText contents - ] - ]. + className = 'LeTextSnippet' + ifTrue: [ sanitizedText := self contentString. + sanitizedText := sanitizedText allButFirst. + sanitizedText := sanitizedText allButLast ]. + className = 'LePharoSnippet' + ifTrue: [ | joinedText | + sanitizedText := self contentString lines. + sanitizedText := sanitizedText copyFrom: 4 to: sanitizedText size - 2. + joinedText := '' writeStream. + sanitizedText + do: [ :line | + joinedText + nextPutAll: line; + nextPut: Character lf ]. + sanitizedText := joinedText contents allButLast ]. + className = 'LePictureSnippet' + ifTrue: [ sanitizedText := self extractMarkdownImageLinkData ]. ^ sanitizedText - ]