YAML metada support.
This commit is contained in:
parent
51f09e40bd
commit
9ac4985542
@ -8,7 +8,8 @@ Class {
|
|||||||
#name : #Markdown,
|
#name : #Markdown,
|
||||||
#superclass : #Object,
|
#superclass : #Object,
|
||||||
#instVars : [
|
#instVars : [
|
||||||
'contents'
|
'contents',
|
||||||
|
'file'
|
||||||
],
|
],
|
||||||
#category : #'Grafoscopio-Utils'
|
#category : #'Grafoscopio-Utils'
|
||||||
}
|
}
|
||||||
@ -65,15 +66,47 @@ Markdown >> detectYAMLMetadata [
|
|||||||
ifFound: [ ^ true ] ifNone: [ ^ false ] ]
|
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 }
|
{ #category : #operation }
|
||||||
Markdown >> extractYAMLMetadata [
|
Markdown >> extractYAMLMetadata [
|
||||||
self detectYAMLMetadata ifFalse: [ ^ nil ].
|
self detectYAMLMetadata ifFalse: [ ^ nil ].
|
||||||
^ self lines copyFrom: 2 to: (self locateYAMLMetadataClosing)
|
^ 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' }
|
{ #category : #'instance creation' }
|
||||||
Markdown >> fromFile: aFileReference [
|
Markdown >> fromFile: aFileReference [
|
||||||
self contents: aFileReference contents.
|
self contents: aFileReference contents.
|
||||||
|
self file: aFileReference
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #utilities }
|
{ #category : #utilities }
|
||||||
@ -93,6 +126,12 @@ Markdown >> locateYAMLMetadataClosing [
|
|||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
Markdown >> metadata [
|
||||||
|
self exportMetadataAsJson.
|
||||||
|
^ NeoJSONReader fromString: FileLocator temp / 'metadata.json' contents.
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : #utilities }
|
{ #category : #utilities }
|
||||||
Markdown >> startsWithYAMLMetadataDelimiter [
|
Markdown >> startsWithYAMLMetadataDelimiter [
|
||||||
^ self lines first beginsWith: self class yamlMetadataDelimiter
|
^ self lines first beginsWith: self class yamlMetadataDelimiter
|
||||||
|
@ -110,3 +110,23 @@ Pandoc class >> luaFilters [
|
|||||||
add: 'http://mutabit.com/repos.fossil/dataweek/doc/tip/Artefactos/Scripts/image-links.lua'.
|
add: 'http://mutabit.com/repos.fossil/dataweek/doc/tip/Artefactos/Scripts/image-links.lua'.
|
||||||
^ filters
|
^ 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 ]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user