Improving Markdown exportation from Markdeep files.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2024-03-10 15:57:05 -05:00
parent 05269ac364
commit 4c661e0b6d
4 changed files with 50 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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