From 938c5cc8e9cd5b9849ab5dad25690fd1cb0a4f40 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Wed, 21 Oct 2020 18:38:29 -0500 Subject: [PATCH] Using PetitParser for YAML processing. It should be added to the baseline as prerequisite. --- repository/Grafoscopio-Utils/Markdown.class.st | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/repository/Grafoscopio-Utils/Markdown.class.st b/repository/Grafoscopio-Utils/Markdown.class.st index fc85dad..752091a 100644 --- a/repository/Grafoscopio-Utils/Markdown.class.st +++ b/repository/Grafoscopio-Utils/Markdown.class.st @@ -31,8 +31,7 @@ Markdown >> commentYAMLMetadata [ self detectYAMLMetadata ifFalse: [ ^ self ]. newContents := '' writeStream. 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. ]