Optimistic reading of a Markdeep file as a live object done.
This commit is contained in:
parent
8143633b42
commit
05269ac364
@ -183,7 +183,7 @@ Markdeep >> extractYamlMetadataFrom: documentTree [
|
||||
yamlComment children allButFirst allButLast do: [:each |
|
||||
response nextPutAll: each text; cr
|
||||
].
|
||||
^ YAML2JSON fromString: response contents
|
||||
^ {YAML2JSON fromString: response contents . yamlComment }
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
@ -194,7 +194,7 @@ Markdeep >> file: aFileReference [
|
||||
|
||||
{ #category : #accessing }
|
||||
Markdeep >> fillInContentsFrom: aFileReference [
|
||||
| docTree docTreeChildren headTree bodyLineIndex |
|
||||
| docTree docTreeChildren headTree bodyStartLine bodyEndLine contentLines rawMetadata |
|
||||
aFileReference exists ifFalse: [ ^ self ].
|
||||
docTree := (Markdown new contents: aFileReference contents) documentTree.
|
||||
docTreeChildren := docTree children.
|
||||
@ -205,15 +205,17 @@ Markdeep >> fillInContentsFrom: aFileReference [
|
||||
headTree children allButFirst allButLast
|
||||
do: [ :node | node className = 'PPCMHtml' ifTrue: [ self head add: node text ] ].
|
||||
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 title trimBoth: [ :char | char = $" ]).
|
||||
self metadata at: 'title' put: self title.
|
||||
bodyLineIndex := docTreeChildren
|
||||
detectIndex: [ :node | node text includesSubstring: self title ].
|
||||
^ {self .
|
||||
bodyLineIndex.
|
||||
docTree }
|
||||
contentLines := self file contents lines.
|
||||
bodyStartLine := (contentLines
|
||||
detectIndex: [ :line | line includesSubstring: '<!--@yaml' ]) + rawMetadata second children size.
|
||||
bodyEndLine := contentLines detectIndex: [:line | line includesSubstring: '<!-- Markdeep'] ifNone: [ 0 ].
|
||||
self body: (contentLines copyFrom: bodyStartLine to: bodyEndLine - 1 ) asStringWithCr.
|
||||
^ self .
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
|
Loading…
Reference in New Issue
Block a user