YAML metada support.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2020-07-10 17:52:16 -05:00
parent 51f09e40bd
commit 9ac4985542
2 changed files with 60 additions and 1 deletions

View File

@ -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

View File

@ -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 ]
]
]