Improving metadata reading.
This commit is contained in:
parent
d7bc31b094
commit
9a3d17e200
@ -277,6 +277,7 @@ Markdeep >> processMarkdownFor: aFileReference [
|
|||||||
self markdownFile: aFileReference.
|
self markdownFile: aFileReference.
|
||||||
markdownContent := Markdown fromFile: aFileReference.
|
markdownContent := Markdown fromFile: aFileReference.
|
||||||
self body: (markdownContent commentYAMLMetadata contents).
|
self body: (markdownContent commentYAMLMetadata contents).
|
||||||
|
self metadata: markdownContent yamlMetadata
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
|
@ -31,13 +31,12 @@ Markdown >> commentYAMLMetadata [
|
|||||||
self detectYAMLMetadata ifFalse: [ ^ self ].
|
self detectYAMLMetadata ifFalse: [ ^ self ].
|
||||||
newContents := '' writeStream.
|
newContents := '' writeStream.
|
||||||
newContents nextPutAll: '<!--@yaml:'; crlf.
|
newContents nextPutAll: '<!--@yaml:'; crlf.
|
||||||
newContents nextPutAll: self extractYAMLMetadata.
|
newContents nextPutAll: self yamlMetadataString.
|
||||||
newContents nextPutAll: String cr.
|
newContents nextPutAll: String cr.
|
||||||
newContents nextPutAll: '-->'; crlf.
|
newContents nextPutAll: '-->'; crlf.
|
||||||
(self lines copyFrom: self yamlMetadataClosingLineNumber + 2 to: self lines size) do: [ :line |
|
(self lines copyFrom: self yamlMetadataClosingLineNumber + 2 to: self lines size) do: [ :line |
|
||||||
newContents nextPutAll: line; crlf ].
|
newContents nextPutAll: line; crlf ].
|
||||||
self contents: newContents contents.
|
^ newContents contents.
|
||||||
^ self contents
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #utilities }
|
{ #category : #utilities }
|
||||||
@ -90,23 +89,10 @@ Markdown >> exportMetadataAsJson [
|
|||||||
Markdown >> exportMetadataAsYaml [
|
Markdown >> exportMetadataAsYaml [
|
||||||
| exportedFile |
|
| exportedFile |
|
||||||
exportedFile := FileLocator temp / 'metadata.yaml'.
|
exportedFile := FileLocator temp / 'metadata.yaml'.
|
||||||
MarkupFile exportAsFileOn: exportedFile containing: self yamlMetadataAsString.
|
MarkupFile exportAsFileOn: exportedFile containing: self yamlMetadataStringWithDelimiters.
|
||||||
^ exportedFile
|
^ exportedFile
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #operation }
|
|
||||||
Markdown >> extractYAMLMetadata [
|
|
||||||
| output yamlLines |
|
|
||||||
self detectYAMLMetadata ifFalse: [ ^ nil ].
|
|
||||||
yamlLines := self lines copyFrom: 2 to: self yamlMetadataClosingLineNumber - 1.
|
|
||||||
output := '' writeStream.
|
|
||||||
yamlLines do: [ :line |
|
|
||||||
output
|
|
||||||
nextPutAll: line;
|
|
||||||
nextPut: Character cr. ].
|
|
||||||
^ output contents
|
|
||||||
]
|
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Markdown >> file [
|
Markdown >> file [
|
||||||
^ file
|
^ file
|
||||||
@ -121,7 +107,7 @@ Markdown >> file: aFileReference [
|
|||||||
{ #category : #'instance creation' }
|
{ #category : #'instance creation' }
|
||||||
Markdown >> fromFile: aFileReference [
|
Markdown >> fromFile: aFileReference [
|
||||||
self contents: aFileReference contents.
|
self contents: aFileReference contents.
|
||||||
self file: aFileReference
|
self file: aFileReference.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
@ -140,7 +126,7 @@ Markdown >> lines [
|
|||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Markdown >> metadata [
|
Markdown >> metadata [
|
||||||
| rawMeta |
|
| rawMeta |
|
||||||
rawMeta := PPYAMLGrammar new parse: self extractYAMLMetadata.
|
rawMeta := PPYAMLGrammar new parse: self yamlMetadataString.
|
||||||
rawMeta associationsDo: [ :assoc |
|
rawMeta associationsDo: [ :assoc |
|
||||||
assoc value = 'false' ifTrue: [ assoc value: false ].
|
assoc value = 'false' ifTrue: [ assoc value: false ].
|
||||||
assoc value = 'true' ifTrue: [ assoc value: true ] ].
|
assoc value = 'true' ifTrue: [ assoc value: true ] ].
|
||||||
@ -160,15 +146,9 @@ Markdown >> startsWithYAMLMetadataDelimiter [
|
|||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #utilities }
|
{ #category : #accessing }
|
||||||
Markdown >> yamlMetadataAsString [
|
Markdown >> yamlMetadata [
|
||||||
| output |
|
^ MiniDocs yamlToJson: self yamlMetadataString
|
||||||
self extractYAMLMetadata ifNil: [ ^ nil ].
|
|
||||||
output := String new writeStream.
|
|
||||||
output nextPutAll: self class yamlMetadataDelimiter; cr.
|
|
||||||
output nextPutAll: self extractYAMLMetadata.
|
|
||||||
output nextPutAll: self class yamlMetadataDelimiter; cr.
|
|
||||||
^ output contents.
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #utilities }
|
{ #category : #utilities }
|
||||||
@ -179,3 +159,27 @@ Markdown >> yamlMetadataClosingLineNumber [
|
|||||||
(currentLine beginsWith: self class yamlMetadataDelimiter) ifTrue: [ ^ i + 1 ]]
|
(currentLine beginsWith: self class yamlMetadataDelimiter) ifTrue: [ ^ i + 1 ]]
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #operation }
|
||||||
|
Markdown >> yamlMetadataString [
|
||||||
|
| output yamlLines |
|
||||||
|
self detectYAMLMetadata ifFalse: [ ^ nil ].
|
||||||
|
yamlLines := self lines copyFrom: 2 to: self yamlMetadataClosingLineNumber - 1.
|
||||||
|
output := '' writeStream.
|
||||||
|
yamlLines do: [ :line |
|
||||||
|
output
|
||||||
|
nextPutAll: line;
|
||||||
|
nextPut: Character cr. ].
|
||||||
|
^ output contents
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #utilities }
|
||||||
|
Markdown >> yamlMetadataStringWithDelimiters [
|
||||||
|
| output |
|
||||||
|
self yamlMetadataString ifNil: [ ^ nil ].
|
||||||
|
output := String new writeStream.
|
||||||
|
output nextPutAll: self class yamlMetadataDelimiter; cr.
|
||||||
|
output nextPutAll: self yamlMetadataString.
|
||||||
|
output nextPutAll: self class yamlMetadataDelimiter; cr.
|
||||||
|
^ output contents.
|
||||||
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user