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

View File

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