Improving Markdown with metadata file exportation.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2024-11-16 18:03:04 -05:00
parent b89b3755f7
commit e73cbbb72a
4 changed files with 21 additions and 14 deletions

View File

@ -3,7 +3,7 @@ Extension { #name : #LePage }
{ #category : #'*MiniDocs' } { #category : #'*MiniDocs' }
LePage >> asHtmlFile [ LePage >> asHtmlFile [
self asMarkdownFile. self asMarkdownFileWIthMetadataWrappers.
self defaultPandocTemplate exists self defaultPandocTemplate exists
ifFalse: [ MarkupFile installTemplate: 'https://mutabit.com/repos.fossil/mutabit/doc/trunk/plantillas/Pandoc/clean-menu-mod.html' into: self defaultPandocTemplate parent ]. 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' } { #category : #'*MiniDocs' }
LePage >> asMarkdown [ LePage >> asMarkdown [
"PENDING: to debug the output."
| bodyStream markdown | | bodyStream markdown |
bodyStream := '' writeStream. bodyStream := '' writeStream.
bodyStream bodyStream
@ -55,13 +56,13 @@ LePage >> asMarkdown [
self preorderTraversal self preorderTraversal
do: [ :snippet | bodyStream nextPutAll: snippet asMarkdown ]. do: [ :snippet | bodyStream nextPutAll: snippet asMarkdown ].
markdown := Markdown new markdown := Markdown new
contents: bodyStream contents demoteMarkdownHeaders; contents: bodyStream contents promoteMarkdownHeaders;
metadata: (self metadata at: 'original' ifAbsentPut: Dictionary new). metadata: (self metadata at: 'original' ifAbsentPut: Dictionary new).
^ markdown ^ markdown
] ]
{ #category : #'*MiniDocs' } { #category : #'*MiniDocs' }
LePage >> asMarkdownFile [ LePage >> asMarkdownFileWIthMetadataWrappers [
| folder | | folder |
folder := self storage. folder := self storage.
^ MarkupFile exportAsFileOn: folder / self markdownFileName containing: self asMarkdownWithMetadataWrappers contents ^ MarkupFile exportAsFileOn: folder / self markdownFileName containing: self asMarkdownWithMetadataWrappers contents
@ -71,13 +72,15 @@ LePage >> asMarkdownFile [
LePage >> asMarkdownWithMetadataWrappers [ LePage >> asMarkdownWithMetadataWrappers [
| bodyStream markdown | | bodyStream markdown |
bodyStream := '' writeStream. bodyStream := '' writeStream.
bodyStream "bodyStream
nextPutAll: '# ', self title; cr; cr. nextPut: Character lf;
nextPutAll: '# ', self title; cr; cr."
self preorderTraversal self preorderTraversal
do: [ :snippet | bodyStream nextPutAll: snippet asMarkdownWithMetadataWrappers ]. do: [ :snippet | bodyStream nextPutAll: snippet asMarkdownWithMetadataWrappers ].
markdown := Markdown new markdown := Markdown new
contents: bodyStream contents demoteMarkdownHeaders; contents: bodyStream contents promoteMarkdownHeaders;
metadata: (self metadata at: 'original' ifAbsentPut: Dictionary new). title: self title;
metadata: self metadata.
^ markdown ^ markdown
] ]
@ -237,7 +240,7 @@ LePage >> notebookMetadataSnippet [
| response | | response |
response := LeTextSnippet new fromString: '<!-- See this snippet source code for this notebook''s metadata -->'. response := LeTextSnippet new fromString: '<!-- See this snippet source code for this notebook''s metadata -->'.
response parent: self. response parent: self.
(self optionAt: 'HedgeDoc') ifNil: [ ^ response ]. self optionAt: 'HedgeDoc' ifAbsent: [ ^ response ].
(response extra) (response extra)
at: 'HedgeDoc' put: (self optionAt: 'HedgeDoc'). at: 'HedgeDoc' put: (self optionAt: 'HedgeDoc').
^ response ^ response

View File

@ -34,13 +34,12 @@ LeTextualSnippet >> asMarkdownWithMetadataWrappers [
| output | | output |
output := '' writeStream. output := '' writeStream.
output output
nextPutAll: '<div st-class="', self class asString, '"'; lf; nextPutAll: self metadataDiv;
nextPutAll: ' st-data="', (STON toString: self metadata), '">'; lf;
nextPutAll: self markdownCustomOpener; nextPutAll: self markdownCustomOpener;
nextPutAll: self contentAsStringCustomized; lf; nextPutAll: self contentAsStringCustomized; lf;
nextPutAll: self markdownCustomCloser; nextPutAll: self markdownCustomCloser;
nextPutAll: '</div>'; lf; lf. nextPutAll: '</div>'; lf; lf.
^ output contents ^ output contents withInternetLineEndings
] ]
{ #category : #'*MiniDocs' } { #category : #'*MiniDocs' }

View File

@ -73,8 +73,8 @@ Markdown >> contents [
nextPutAll: '---'; cr; nextPutAll: '---'; cr;
nextPutAll: self metadataAsYAML; cr; nextPutAll: self metadataAsYAML; cr;
nextPutAll: '---'; cr; nextPutAll: '---'; cr;
nextPutAll: self body. nextPutAll: (self body ifNil: [ '' ]).
^ response contents ^ response contents withInternetLineEndings
] ]
{ #category : #accessing } { #category : #accessing }
@ -142,7 +142,7 @@ Markdown >> exportMetadataAsYaml [
{ #category : #accessing } { #category : #accessing }
Markdown >> file [ Markdown >> file [
^ file ifNil: [ file := FileLocator temp / 'temporalMarkdeep.md.html' ] ^ file ifNil: [ file := FileLocator temp / 'temporalMarkdeep.md' ]
] ]
{ #category : #accessing } { #category : #accessing }

View File

@ -17,6 +17,11 @@ OrderedDictionary >> asLepiterSnippet [
^ response ^ response
] ]
{ #category : #'*MiniDocs' }
OrderedDictionary >> asYAML [
^ (YQ jsonToYaml: self) accentedCharactersCorrection.
]
{ #category : #'*MiniDocs' } { #category : #'*MiniDocs' }
OrderedDictionary >> errata [ OrderedDictionary >> errata [
^ self at: 'errata' ifAbsentPut: [ OrderedCollection new] ^ self at: 'errata' ifAbsentPut: [ OrderedCollection new]