Using PetitParser for YAML processing. It should be added to the baseline as prerequisite.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2020-10-21 18:38:29 -05:00
parent 92d8403b75
commit 938c5cc8e9

View File

@ -31,8 +31,7 @@ Markdown >> commentYAMLMetadata [
self detectYAMLMetadata ifFalse: [ ^ self ].
newContents := '' writeStream.
newContents nextPutAll: '<!--@yaml:'; crlf.
self extractYAMLMetadata do: [ :line |
newContents nextPutAll: line ].
newContents nextPutAll: self extractYAMLMetadata.
newContents nextPutAll: String cr.
newContents nextPutAll: '-->'; crlf.
(self lines copyFrom: self locateYAMLMetadataClosing + 2 to: self lines size) do: [ :line |
@ -97,8 +96,15 @@ Markdown >> exportMetadataAsYaml [
{ #category : #operation }
Markdown >> extractYAMLMetadata [
| output yamlLines |
self detectYAMLMetadata ifFalse: [ ^ nil ].
^ self lines copyFrom: 2 to: (self locateYAMLMetadataClosing)
yamlLines := self lines copyFrom: 2 to: (self locateYAMLMetadataClosing).
output := '' writeStream.
yamlLines do: [ :line |
output
nextPutAll: line;
nextPut: Character cr. ].
^ output contents
]
{ #category : #accessing }
@ -138,7 +144,7 @@ Markdown >> locateYAMLMetadataClosing [
{ #category : #accessing }
Markdown >> metadata [
^ NeoJSONReader fromString: self exportMetadataAsJson.
^ PPYAMLGrammar new parse: self extractYAMLMetadata.
]
{ #category : #utilities }
@ -153,9 +159,7 @@ Markdown >> yamlMetadataAsString [
self extractYAMLMetadata ifNil: [ ^ nil ].
output := String new writeStream.
output nextPutAll: self class yamlMetadataDelimiter; cr.
self extractYAMLMetadata do: [ :line |
output nextPutAll: line; cr.
].
output nextPutAll: self extractYAMLMetadata.
output nextPutAll: self class yamlMetadataDelimiter; cr.
^ output contents.
]