Improving Markdown objects reading from files.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2024-03-25 11:44:16 -05:00
parent 0185c741a1
commit 80afb07c77
3 changed files with 16 additions and 19 deletions

View File

@ -62,7 +62,7 @@ Markdown >> contents [
response response
nextPutAll: '---'; cr; nextPutAll: '---'; cr;
nextPutAll: self metadataAsYAML; cr; nextPutAll: self metadataAsYAML; cr;
nextPutAll: '---'; cr; nextPutAll: '---'; cr; cr;
nextPutAll: self body. nextPutAll: self body.
^ response contents ^ response contents
] ]
@ -72,16 +72,6 @@ Markdown >> contents: aString [
body := aString body := aString
] ]
{ #category : #accessing }
Markdown >> contentsWithoutYAMLMetadata [
| newContents |
self detectYAMLMetadata ifFalse: [ ^ self ].
newContents := '' writeStream.
(self lines copyFrom: self yamlMetadataClosingLineNumber + 2 to: self lines size) do: [ :line |
newContents nextPutAll: line; cr ].
^ newContents contents.
]
{ #category : #accessing } { #category : #accessing }
Markdown >> documentTree [ Markdown >> documentTree [
| parser| | parser|
@ -153,17 +143,14 @@ Markdown >> file: aFileReference [
{ #category : #'instance creation' } { #category : #'instance creation' }
Markdown >> fromFile: aFileReference [ Markdown >> fromFile: aFileReference [
self contents: aFileReference contents. self fromString: aFileReference contents.
self file: aFileReference. self file: aFileReference.
self yamlMetadata.
self body: self contentsWithoutYAMLMetadata
] ]
{ #category : #'instance creation' } { #category : #'instance creation' }
Markdown >> fromString: markdownString [ Markdown >> fromString: markdownString [
self contents: markdownString. self metadata: markdownString yamlMetadata.
self yamlMetadata. self body: markdownString contentsWithoutYAMLMetadata
self contents: self contentsWithoutYAMLMetadata
] ]
{ #category : #accessing } { #category : #accessing }

View File

@ -16,8 +16,8 @@ MarkupFile class >> exportAsFileOn: aFileReferenceOrFileName containing: anObjec
file := aFileReferenceOrFileName asFileReference. file := aFileReferenceOrFileName asFileReference.
file ensureDelete. file ensureDelete.
file exists ifFalse: [ file ensureCreateFile ]. file exists ifFalse: [ file ensureCreateFile ].
anObject className = String (#('String' 'ByteString' 'WideString') includes: anObject className )
ifTrue: [ preprocessed := anObject withInternetLineEndings ] ifTrue: [ preprocessed := anObject ]
ifFalse: [preprocessed := STON toStringPretty: anObject ]. ifFalse: [preprocessed := STON toStringPretty: anObject ].
file writeStreamDo: [ :stream | file writeStreamDo: [ :stream |
stream nextPutAll: preprocessed ]. stream nextPutAll: preprocessed ].

View File

@ -20,6 +20,16 @@ String >> asDashedLowercase [
^ '-' join: (self substrings collect: [:each | each asLowercase ]) ^ '-' join: (self substrings collect: [:each | each asLowercase ])
] ]
{ #category : #'*MiniDocs' }
String >> contentsWithoutYAMLMetadata [
| newContents |
self detectYAMLMetadata ifFalse: [ ^ self ].
newContents := '' writeStream.
(self lines copyFrom: self yamlMetadataClosingLineNumber + 2 to: self lines size) do: [ :line |
newContents nextPutAll: line; cr ].
^ newContents contents.
]
{ #category : #'*MiniDocs' } { #category : #'*MiniDocs' }
String >> deleteYAMLMetadata [ String >> deleteYAMLMetadata [
| newContents | | newContents |