From e73cbbb72a6dcf28699c0c6471103f97d665370f Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Sat, 16 Nov 2024 18:03:04 -0500 Subject: [PATCH] Improving Markdown with metadata file exportation. --- src/MiniDocs/LePage.extension.st | 19 +++++++++++-------- src/MiniDocs/LeTextualSnippet.extension.st | 5 ++--- src/MiniDocs/Markdown.class.st | 6 +++--- src/MiniDocs/OrderedDictionary.extension.st | 5 +++++ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/MiniDocs/LePage.extension.st b/src/MiniDocs/LePage.extension.st index 97e9527..347aa18 100644 --- a/src/MiniDocs/LePage.extension.st +++ b/src/MiniDocs/LePage.extension.st @@ -3,7 +3,7 @@ Extension { #name : #LePage } { #category : #'*MiniDocs' } LePage >> asHtmlFile [ - self asMarkdownFile. + self asMarkdownFileWIthMetadataWrappers. self defaultPandocTemplate exists ifFalse: [ MarkupFile installTemplate: 'https://mutabit.com/repos.fossil/mutabit/doc/trunk/plantillas/Pandoc/clean-menu-mod.html' into: self defaultPandocTemplate parent ]. @@ -48,6 +48,7 @@ LePage >> asMarkdeepFile [ { #category : #'*MiniDocs' } LePage >> asMarkdown [ + "PENDING: to debug the output." | bodyStream markdown | bodyStream := '' writeStream. bodyStream @@ -55,13 +56,13 @@ LePage >> asMarkdown [ self preorderTraversal do: [ :snippet | bodyStream nextPutAll: snippet asMarkdown ]. markdown := Markdown new - contents: bodyStream contents demoteMarkdownHeaders; + contents: bodyStream contents promoteMarkdownHeaders; metadata: (self metadata at: 'original' ifAbsentPut: Dictionary new). ^ markdown ] { #category : #'*MiniDocs' } -LePage >> asMarkdownFile [ +LePage >> asMarkdownFileWIthMetadataWrappers [ | folder | folder := self storage. ^ MarkupFile exportAsFileOn: folder / self markdownFileName containing: self asMarkdownWithMetadataWrappers contents @@ -71,13 +72,15 @@ LePage >> asMarkdownFile [ LePage >> asMarkdownWithMetadataWrappers [ | bodyStream markdown | bodyStream := '' writeStream. - bodyStream - nextPutAll: '# ', self title; cr; cr. + "bodyStream + nextPut: Character lf; + nextPutAll: '# ', self title; cr; cr." self preorderTraversal do: [ :snippet | bodyStream nextPutAll: snippet asMarkdownWithMetadataWrappers ]. markdown := Markdown new - contents: bodyStream contents demoteMarkdownHeaders; - metadata: (self metadata at: 'original' ifAbsentPut: Dictionary new). + contents: bodyStream contents promoteMarkdownHeaders; + title: self title; + metadata: self metadata. ^ markdown ] @@ -237,7 +240,7 @@ LePage >> notebookMetadataSnippet [ | response | response := LeTextSnippet new fromString: ''. response parent: self. - (self optionAt: 'HedgeDoc') ifNil: [ ^ response ]. + self optionAt: 'HedgeDoc' ifAbsent: [ ^ response ]. (response extra) at: 'HedgeDoc' put: (self optionAt: 'HedgeDoc'). ^ response diff --git a/src/MiniDocs/LeTextualSnippet.extension.st b/src/MiniDocs/LeTextualSnippet.extension.st index dcd75d5..565f349 100644 --- a/src/MiniDocs/LeTextualSnippet.extension.st +++ b/src/MiniDocs/LeTextualSnippet.extension.st @@ -34,13 +34,12 @@ LeTextualSnippet >> asMarkdownWithMetadataWrappers [ | output | output := '' writeStream. output - nextPutAll: '
'; lf; + nextPutAll: self metadataDiv; nextPutAll: self markdownCustomOpener; nextPutAll: self contentAsStringCustomized; lf; nextPutAll: self markdownCustomCloser; nextPutAll: '
'; lf; lf. - ^ output contents + ^ output contents withInternetLineEndings ] { #category : #'*MiniDocs' } diff --git a/src/MiniDocs/Markdown.class.st b/src/MiniDocs/Markdown.class.st index c155ec9..6ed9e62 100644 --- a/src/MiniDocs/Markdown.class.st +++ b/src/MiniDocs/Markdown.class.st @@ -73,8 +73,8 @@ Markdown >> contents [ nextPutAll: '---'; cr; nextPutAll: self metadataAsYAML; cr; nextPutAll: '---'; cr; - nextPutAll: self body. - ^ response contents + nextPutAll: (self body ifNil: [ '' ]). + ^ response contents withInternetLineEndings ] { #category : #accessing } @@ -142,7 +142,7 @@ Markdown >> exportMetadataAsYaml [ { #category : #accessing } Markdown >> file [ - ^ file ifNil: [ file := FileLocator temp / 'temporalMarkdeep.md.html' ] + ^ file ifNil: [ file := FileLocator temp / 'temporalMarkdeep.md' ] ] { #category : #accessing } diff --git a/src/MiniDocs/OrderedDictionary.extension.st b/src/MiniDocs/OrderedDictionary.extension.st index e1693b8..28f7956 100644 --- a/src/MiniDocs/OrderedDictionary.extension.st +++ b/src/MiniDocs/OrderedDictionary.extension.st @@ -17,6 +17,11 @@ OrderedDictionary >> asLepiterSnippet [ ^ response ] +{ #category : #'*MiniDocs' } +OrderedDictionary >> asYAML [ + ^ (YQ jsonToYaml: self) accentedCharactersCorrection. +] + { #category : #'*MiniDocs' } OrderedDictionary >> errata [ ^ self at: 'errata' ifAbsentPut: [ OrderedCollection new]