Optimistic reading of a Markdeep file as a live object done.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2024-03-10 11:21:53 -05:00
parent 8143633b42
commit 05269ac364

View File

@ -183,7 +183,7 @@ Markdeep >> extractYamlMetadataFrom: documentTree [
yamlComment children allButFirst allButLast do: [:each | yamlComment children allButFirst allButLast do: [:each |
response nextPutAll: each text; cr response nextPutAll: each text; cr
]. ].
^ YAML2JSON fromString: response contents ^ {YAML2JSON fromString: response contents . yamlComment }
] ]
{ #category : #accessing } { #category : #accessing }
@ -194,7 +194,7 @@ Markdeep >> file: aFileReference [
{ #category : #accessing } { #category : #accessing }
Markdeep >> fillInContentsFrom: aFileReference [ Markdeep >> fillInContentsFrom: aFileReference [
| docTree docTreeChildren headTree bodyLineIndex | | docTree docTreeChildren headTree bodyStartLine bodyEndLine contentLines rawMetadata |
aFileReference exists ifFalse: [ ^ self ]. aFileReference exists ifFalse: [ ^ self ].
docTree := (Markdown new contents: aFileReference contents) documentTree. docTree := (Markdown new contents: aFileReference contents) documentTree.
docTreeChildren := docTree children. docTreeChildren := docTree children.
@ -205,15 +205,17 @@ Markdeep >> fillInContentsFrom: aFileReference [
headTree children allButFirst allButLast headTree children allButFirst allButLast
do: [ :node | 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.
self metadata: (self extractYamlMetadataFrom: docTree). rawMetadata := (self extractYamlMetadataFrom: docTree).
self metadata: rawMetadata first.
self title: (self metadata at: 'title' ifAbsent: [self extractTitleFrom: docTree]). self title: (self metadata at: 'title' ifAbsent: [self extractTitleFrom: docTree]).
self title: (self title trimBoth: [ :char | char = $" ]). self title: (self title trimBoth: [ :char | char = $" ]).
self metadata at: 'title' put: self title. self metadata at: 'title' put: self title.
bodyLineIndex := docTreeChildren contentLines := self file contents lines.
detectIndex: [ :node | node text includesSubstring: self title ]. bodyStartLine := (contentLines
^ {self . detectIndex: [ :line | line includesSubstring: '<!--@yaml' ]) + rawMetadata second children size.
bodyLineIndex. bodyEndLine := contentLines detectIndex: [:line | line includesSubstring: '<!-- Markdeep'] ifNone: [ 0 ].
docTree } self body: (contentLines copyFrom: bodyStartLine to: bodyEndLine - 1 ) asStringWithCr.
^ self .
] ]
{ #category : #accessing } { #category : #accessing }