Improving populating metadata from a given Markdeep file.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2024-03-09 12:05:25 -05:00
parent 4199ed0a6c
commit c162b9b4bc

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,29 @@ 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 >> extractYamlMetadataFrom: documentTree [
| yamlComment response |
yamlComment := documentTree children
detect: [:node | node className = 'PPCMHtmlBlock' and: [node text trimmed beginsWith: '<!--@yaml']]
ifNone: [ ^ nil ].
response := '' writeStream.
yamlComment children allButFirst allButLast do: [:each |
response nextPutAll: each text; cr
].
^ YAML2JSON fromString: response contents
]
{ #category : #accessing }
Markdeep >> file: aFileReference [
file := aFileReference.
@ -166,22 +194,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
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 ]
].
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 ] ].
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 +322,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 }