diff --git a/src/MiniDocs/HedgeDocGrammar.class.st b/src/MiniDocs/HedgeDocGrammar.class.st index f94395a..16e405e 100644 --- a/src/MiniDocs/HedgeDocGrammar.class.st +++ b/src/MiniDocs/HedgeDocGrammar.class.st @@ -8,16 +8,16 @@ Class { } { #category : #accessing } -HedgeDocGrammar >> start [ - | any | - any := #any asPParser. - ^ (self yamlMetadata / any starLazy), youtubeEmbeddedLink +HedgeDocGrammar >> metadataAsYAML [ + "I parse the header of the hedgedoc document for YAML metadata." + ^ '---' asPParser token, #any asPParser starLazy token, '---' asPParser token ] { #category : #accessing } -HedgeDocGrammar >> yamlMetadata [ - "I parse the header of the hedgedoc document for YAML metadata." - ^ '---' asPParser token, #any asPParser starLazy token, '---' asPParser token +HedgeDocGrammar >> start [ + | any | + any := #any asPParser. + ^ (self metadataAsYAML / any starLazy), youtubeEmbeddedLink ] { #category : #accessing } diff --git a/src/MiniDocs/Markdeep.class.st b/src/MiniDocs/Markdeep.class.st index 03fabae..f69b11b 100644 --- a/src/MiniDocs/Markdeep.class.st +++ b/src/MiniDocs/Markdeep.class.st @@ -30,6 +30,14 @@ Markdeep class >> fromPubPubTOC: orderedDictionary folder: folder index: ordina ^ self new fromMarkdownFile: testFile. ] +{ #category : #accessing } +Markdeep >> asMarkdown [ + ^ Markdown new + metadata: self metadata; + body: self body; + file: self markdownFile +] + { #category : #'instance creation' } Markdeep >> authors [ self metadata at: 'authors' ifPresent: [:k | ^ '**', k, '**' ]. @@ -380,7 +388,7 @@ Markdeep >> processMarkdownFor: aFileReference [ | markdownContent | self file: aFileReference, 'html'. markdownContent := Markdown fromFile: aFileReference. - self metadata: markdownContent yamlMetadata. + self metadata: markdownContent metadataAsYAML. self body: (markdownContent commentYAMLMetadata contents). ] diff --git a/src/MiniDocs/Markdown.class.st b/src/MiniDocs/Markdown.class.st index a144e53..24be866 100644 --- a/src/MiniDocs/Markdown.class.st +++ b/src/MiniDocs/Markdown.class.st @@ -62,7 +62,14 @@ Markdown >> containsYAMLMetadataClosing [ { #category : #accessing } Markdown >> contents [ - ^ body + | response | + response := WriteStream on: ''. + response + nextPutAll: self class yamlMetadataDelimiter; cr; + nextPutAll: self metadataAsYAML; cr; + nextPutAll: self class yamlMetadataDelimiter; cr; + nextPutAll: self body. + ^ response contents ] { #category : #accessing } @@ -121,7 +128,7 @@ Markdown >> exportAsFileOn: aFileReference [ aFileReference ensureDelete. aFileReference exists ifFalse: [ aFileReference ensureCreateFile ]. aFileReference writeStreamDo: [ :stream | - stream nextPutAll: self contents ]. + stream nextPutAll: self contents withInternetLineEndings ]. ] { #category : #operation } @@ -203,6 +210,12 @@ Markdown >> metadata: rawMeta [ metadata := rawMeta ] +{ #category : #accessing } +Markdown >> metadataAsYAML [ + self metadata isEmptyOrNil ifTrue: [ ^ self ]. + ^ YQ jsonToYaml: self metadata +] + { #category : #persistence } Markdown >> notifyExportAsFileOn: aFileReference [ self exportAsFileOn: aFileReference. @@ -234,11 +247,6 @@ Markdown >> startsWithYAMLMetadataDelimiter [ ] -{ #category : #accessing } -Markdown >> yamlMetadata [ - ^ MiniDocs yamlToJson: self yamlMetadataString -] - { #category : #utilities } Markdown >> yamlMetadataClosingLineNumber [ "I return the line where the closing of the YAML metadata occurs or 0 if no closing is found." diff --git a/src/MiniDocs/YQ.class.st b/src/MiniDocs/YQ.class.st index 57c7d1c..8b0eacf 100644 --- a/src/MiniDocs/YQ.class.st +++ b/src/MiniDocs/YQ.class.st @@ -17,11 +17,30 @@ YQ class >> binaryDownloadLinkFor: operativeSystem on: processor [ ^ binaryDownloadData at: 'browser_download_url' ] +{ #category : #accessing } +YQ class >> binaryFile [ + "Starting with location on Arch Linux and its derivates. Multidistro and multiOS support should be added." + ^ FileLocator root / 'usr/bin/yq' +] + { #category : #accessing } YQ class >> install [ ^ self lastReleaseData ] +{ #category : #accessing } +YQ class >> jsonToYaml: aDictionary [ + | jsonFile | + self binaryFile exists ifFalse: [ YQ install]. + jsonFile := MarkupFile exportAsFileOn: FileLocator temp / 'data.json' containing: aDictionary. + OSSUnixSubprocess new + shellCommand: 'cat ', jsonFile fullName,' | yq -y'; + redirectStdout; + runAndWaitOnExitDo: [ :command :outString | + ^ outString + ]. +] + { #category : #accessing } YQ class >> lastReleaseData [ ^ (STONJSON