diff --git a/src/MiniDocs/Markdeep.class.st b/src/MiniDocs/Markdeep.class.st index 1531adc..64c7adc 100644 --- a/src/MiniDocs/Markdeep.class.st +++ b/src/MiniDocs/Markdeep.class.st @@ -277,6 +277,7 @@ Markdeep >> processMarkdownFor: aFileReference [ self markdownFile: aFileReference. markdownContent := Markdown fromFile: aFileReference. self body: (markdownContent commentYAMLMetadata contents). + self metadata: markdownContent yamlMetadata ] { #category : #accessing } diff --git a/src/MiniDocs/Markdown.class.st b/src/MiniDocs/Markdown.class.st index 369a7f6..e9124ca 100644 --- a/src/MiniDocs/Markdown.class.st +++ b/src/MiniDocs/Markdown.class.st @@ -31,13 +31,12 @@ Markdown >> commentYAMLMetadata [ self detectYAMLMetadata ifFalse: [ ^ self ]. newContents := '' writeStream. newContents nextPutAll: ''; crlf. (self lines copyFrom: self yamlMetadataClosingLineNumber + 2 to: self lines size) do: [ :line | newContents nextPutAll: line; crlf ]. - self contents: newContents contents. - ^ self contents + ^ newContents contents. ] { #category : #utilities } @@ -90,23 +89,10 @@ Markdown >> exportMetadataAsJson [ Markdown >> exportMetadataAsYaml [ | exportedFile | exportedFile := FileLocator temp / 'metadata.yaml'. - MarkupFile exportAsFileOn: exportedFile containing: self yamlMetadataAsString. + MarkupFile exportAsFileOn: exportedFile containing: self yamlMetadataStringWithDelimiters. ^ 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 } Markdown >> file [ ^ file @@ -121,7 +107,7 @@ Markdown >> file: aFileReference [ { #category : #'instance creation' } Markdown >> fromFile: aFileReference [ self contents: aFileReference contents. - self file: aFileReference + self file: aFileReference. ] { #category : #accessing } @@ -140,7 +126,7 @@ Markdown >> lines [ { #category : #accessing } Markdown >> metadata [ | rawMeta | - rawMeta := PPYAMLGrammar new parse: self extractYAMLMetadata. + rawMeta := PPYAMLGrammar new parse: self yamlMetadataString. rawMeta associationsDo: [ :assoc | assoc value = 'false' ifTrue: [ assoc value: false ]. assoc value = 'true' ifTrue: [ assoc value: true ] ]. @@ -160,15 +146,9 @@ Markdown >> startsWithYAMLMetadataDelimiter [ ] -{ #category : #utilities } -Markdown >> yamlMetadataAsString [ - | output | - 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 : #accessing } +Markdown >> yamlMetadata [ + ^ MiniDocs yamlToJson: self yamlMetadataString ] { #category : #utilities } @@ -179,3 +159,27 @@ Markdown >> yamlMetadataClosingLineNumber [ (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. +]