Sanitizing YAML dictionaries.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2024-12-15 12:49:12 -05:00
parent 6825d9f242
commit 60294a40b9
3 changed files with 22 additions and 4 deletions

View File

@ -166,7 +166,7 @@ Markdown >> fromString: markdownString [
bodyTemp nextPutAll: paragraph; cr; cr
].
self body: bodyTemp contents withInternetLineEndings.
yamlMetadataRaw
(yamlMetadataRaw sanitizeMultilineValuesWith: markdownString)
ifNotNil: [
self metadata
ifEmpty: [ self metadata: yamlMetadataRaw ]

View File

@ -64,12 +64,20 @@ OrderedDictionary >> replaceWithUniqueNilsAndBooleansStartingAt: anInteger [
{ #category : #'*MiniDocs' }
OrderedDictionary >> sanitizeMultilineValuesWith: aString [
| toSanitize |
| toSanitize response |
toSanitize := OrderedCollection new.
response := OrderedCollection new.
self keysAndValuesDo: [:k :v |
(v isString and: [v lines size > 1]) ifTrue: [ toSanitize add: k ]
(v isString and: [v lines size > 1])
ifTrue: [
aString lines
detect: [:line | line includesSubstring: k ]
ifFound: [:line | | sanitized|
sanitized := (line withoutPrefix: k, ':'), String cr,
v indentedWithExtraSpaces: 4.
self at: k put: sanitized ]
]
].
^ toSanitize
]
{ #category : #'*MiniDocs' }

View File

@ -105,6 +105,16 @@ String >> detectYAMLMetadata [
ifFound: [ ^ true ] ifNone: [ ^ false ] ]
]
{ #category : #'*MiniDocs' }
String >> indentedWithExtraSpaces: spaceNumber [
| response indent |
response := '' writeStream.
indent := String new.
spaceNumber timesRepeat: [ indent := indent, ' ' ].
self lines do: [:line | response nextPutAll: indent, line, String lf ].
^ response contents
]
{ #category : #'*MiniDocs' }
String >> markdownHeaders [
| response headers |