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