diff --git a/repository/Grafoscopio-Utils/Markdown.class.st b/repository/Grafoscopio-Utils/Markdown.class.st index b0866db..cc27488 100644 --- a/repository/Grafoscopio-Utils/Markdown.class.st +++ b/repository/Grafoscopio-Utils/Markdown.class.st @@ -8,7 +8,8 @@ Class { #name : #Markdown, #superclass : #Object, #instVars : [ - 'contents' + 'contents', + 'file' ], #category : #'Grafoscopio-Utils' } @@ -65,15 +66,47 @@ Markdown >> detectYAMLMetadata [ ifFound: [ ^ true ] ifNone: [ ^ false ] ] ] +{ #category : #operation } +Markdown >> exportMetadataAsJson [ + | yaml2json | + self exportMetadataAsYaml. + yaml2json := OSSUnixSubprocess new + shellCommand: 'yaml2json /tmp/metadata.yaml > /tmp/metadata.json'; + run. + yaml2json waitForExit. + yaml2json closeAndCleanStreams. + ^ FileLocator temp / 'metadata.json' +] + +{ #category : #operation } +Markdown >> exportMetadataAsYaml [ + | exportedFile | + exportedFile := FileLocator temp / 'metadata.yaml'. + MarkupFile exportAsFileOn: exportedFile containing: self yamlMetadataAsString. + ^ exportedFile +] + { #category : #operation } Markdown >> extractYAMLMetadata [ self detectYAMLMetadata ifFalse: [ ^ nil ]. ^ self lines copyFrom: 2 to: (self locateYAMLMetadataClosing) ] +{ #category : #accessing } +Markdown >> file [ + ^ file +] + +{ #category : #accessing } +Markdown >> file: aFileReference [ + "I store the origen/destination of the Markdown contents." + file := aFileReference +] + { #category : #'instance creation' } Markdown >> fromFile: aFileReference [ self contents: aFileReference contents. + self file: aFileReference ] { #category : #utilities } @@ -93,6 +126,12 @@ Markdown >> locateYAMLMetadataClosing [ ] +{ #category : #accessing } +Markdown >> metadata [ + self exportMetadataAsJson. + ^ NeoJSONReader fromString: FileLocator temp / 'metadata.json' contents. +] + { #category : #utilities } Markdown >> startsWithYAMLMetadataDelimiter [ ^ self lines first beginsWith: self class yamlMetadataDelimiter diff --git a/repository/Grafoscopio-Utils/Pandoc.class.st b/repository/Grafoscopio-Utils/Pandoc.class.st index f10cc1f..98beb62 100644 --- a/repository/Grafoscopio-Utils/Pandoc.class.st +++ b/repository/Grafoscopio-Utils/Pandoc.class.st @@ -110,3 +110,23 @@ Pandoc class >> luaFilters [ add: 'http://mutabit.com/repos.fossil/dataweek/doc/tip/Artefactos/Scripts/image-links.lua'. ^ filters ] + +{ #category : #converters } +Pandoc class >> markdownToHtml: inputFile [ + + | outputFile | + outputFile := FileLocator temp / (inputFile basenameWithoutExtension , '.html'). + outputFile ensureDelete. + outputFile ensureCreateFile. + OSSUnixSubprocess new + command: 'pandoc'; + arguments: {'-f'. 'markdown'. '-t'. 'html'. inputFile fullName. + '--output'. outputFile fullName }; + redirectStdout; + redirectStderr; + runAndWaitOnExitDo: [ :process :outString :errString | + process isSuccess + ifTrue: [ ^ outputFile ] + ifFalse: [ ^ inputFile ] + ] +]