Finishing optimistic extraction of Markdeep file contents as a live object.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2024-03-10 10:23:00 -05:00
parent 4199ed0a6c
commit ac41b1721f
1 changed files with 36 additions and 15 deletions

View File

@ -57,6 +57,11 @@ Markdeep >> bodyReplaceAll: original with: replacement [
self body: (self body copyReplaceAll: original with: replacement) self body: (self body copyReplaceAll: original with: replacement)
] ]
{ #category : #accessing }
Markdeep >> cleanMetadata [
metadata := nil
]
{ #category : #accessing } { #category : #accessing }
Markdeep >> commentPubPubDelimiters [ Markdeep >> commentPubPubDelimiters [
| commented openners | | commented openners |
@ -158,6 +163,16 @@ Markdeep >> converPubPubFootnoteBetween: footnote and: nextFootnote in: footnote
^ response contents ^ response contents
] ]
{ #category : #accessing }
Markdeep >> extractTitleFrom: docTree [
| tempTitle |
tempTitle := ((docTree children
detect: [ :node | node className = 'PPCMIndentedCode' ]) children
detect: [ :subnode | subnode text trimmed beginsWith: '**' ]) text trimmed.
self title: (tempTitle copyFrom: 3 to: tempTitle size - 2).
^ tempTitle
]
{ #category : #accessing } { #category : #accessing }
Markdeep >> file: aFileReference [ Markdeep >> file: aFileReference [
file := aFileReference. file := aFileReference.
@ -166,22 +181,26 @@ Markdeep >> file: aFileReference [
{ #category : #accessing } { #category : #accessing }
Markdeep >> fillInContentsFrom: aFileReference [ Markdeep >> fillInContentsFrom: aFileReference [
| docTree docTreeChildren headTree tempTitle bodyLineIndex | | docTree docTreeChildren headTree bodyLineIndex |
aFileReference exists ifFalse: [ ^ self ].
docTree := (Markdown new contents: aFileReference contents) documentTree. docTree := (Markdown new contents: aFileReference contents) documentTree.
docTreeChildren := docTree children. docTreeChildren := docTree children.
headTree := (docTreeChildren headTree := docTreeChildren
detect: [ :node | detect: [ :node |
node className = 'PPCMParagraph' node className = 'PPCMParagraph'
and: [ (node children detect: [ :subnode | subnode text = '<head>' ]) isNotNil ] ]). and: [ (node children detect: [ :subnode | subnode text = '<head>' ]) isNotNil ] ].
headTree children allButFirst allButLast do: [:node | headTree children allButFirst allButLast
(node className = 'PPCMHtml') ifTrue: [ self head add: node text ] do: [ :node | node className = 'PPCMHtml' ifTrue: [ self head add: node text ] ].
].
self head: self head asSet asOrderedCollection. self head: self head asSet asOrderedCollection.
tempTitle := ((docTreeChildren detect: [ :node | node className = 'PPCMIndentedCode']) self metadata: (self extractYamlMetadataFrom: docTree).
children detect: [:subnode | subnode text trimmed beginsWith: '**']) text trimmed. self title: (self metadata at: 'title' ifAbsent: [self extractTitleFrom: docTree]).
bodyLineIndex := docTreeChildren detectIndex: [ :node | node text includesSubstring: tempTitle ]. self title: (self title trimBoth: [ :char | char = $" ]).
self title: (tempTitle copyFrom: 3 to: tempTitle size - 2). self metadata at: 'title' put: self title.
^ { self head . self title . bodyLineIndex . docTree } bodyLineIndex := docTreeChildren
detectIndex: [ :node | node text includesSubstring: self title ].
^ {self .
bodyLineIndex.
docTree }
] ]
{ #category : #accessing } { #category : #accessing }
@ -290,7 +309,9 @@ Markdeep >> markdownFile: aFileReference [
{ #category : #'instance creation' } { #category : #'instance creation' }
Markdeep >> metadata [ Markdeep >> metadata [
^ metadata ifNil: [ metadata := OrderedDictionary new ] (metadata isNil and: [ self file contents isNil ])
ifTrue: [ metadata := OrderedDictionary new ].
^ metadata
] ]
{ #category : #accessing } { #category : #accessing }