2022-09-21 17:40:05 +00:00
|
|
|
Extension { #name : #String }
|
|
|
|
|
2024-01-03 19:35:46 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> accentedCharactersCorrection [
|
|
|
|
| modified corrections |
|
|
|
|
corrections := {
|
|
|
|
'ó' -> 'ó' . 'ú' -> 'ú' . 'ñ' -> 'ñ' .
|
|
|
|
'Ã' -> 'í' . 'á' -> 'á' . 'é' -> 'é' . 'â' -> $' asString} asDictionary.
|
|
|
|
modified := self copy.
|
|
|
|
corrections keysAndValuesDo: [ :k :v |
|
|
|
|
modified := modified copyReplaceAll: k with: v
|
|
|
|
].
|
|
|
|
^ modified
|
|
|
|
]
|
|
|
|
|
2022-09-21 17:40:05 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> asDashedLowercase [
|
|
|
|
"I convert phrases like 'This is a phrase' into 'this-is-a-phrase'."
|
|
|
|
|
|
|
|
^ '-' join: (self substrings collect: [:each | each asLowercase ])
|
|
|
|
]
|
2022-11-21 19:19:12 +00:00
|
|
|
|
2024-03-25 16:16:53 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> deleteYAMLMetadata [
|
|
|
|
| newContents |
|
|
|
|
self detectYAMLMetadata ifFalse: [ ^ self ].
|
|
|
|
newContents := '' writeStream.
|
|
|
|
(self lines copyFrom: self yamlMetadataClosingLineNumber + 1 to: self lines size) do: [ :line |
|
|
|
|
newContents nextPutAll: line; lf;lf ].
|
|
|
|
^ newContents contents.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> detectYAMLMetadata [
|
|
|
|
| lines |
|
|
|
|
lines := self lines.
|
|
|
|
^ self startsWithYAMLMetadataDelimiter
|
|
|
|
and: [ lines allButFirst
|
|
|
|
detect: [ :currentLine | currentLine beginsWith: self class yamlMetadataDelimiter ]
|
|
|
|
ifFound: [ ^ true ] ifNone: [ ^ false ] ]
|
|
|
|
]
|
|
|
|
|
2022-11-21 19:19:12 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> romanizeAccents [
|
|
|
|
| modified corrections |
|
|
|
|
corrections := {
|
|
|
|
'ó' -> 'o' . 'ú' -> 'u' . 'ñ' -> 'n' .
|
|
|
|
'í' -> 'i' . 'á' -> 'a' . 'é' -> 'e' } asDictionary.
|
|
|
|
modified := self copy.
|
|
|
|
corrections keysAndValuesDo: [ :k :v |
|
|
|
|
modified := modified copyReplaceAll: k with: v
|
|
|
|
].
|
|
|
|
^ modified
|
|
|
|
]
|
2023-11-01 14:25:49 +00:00
|
|
|
|
2024-03-25 16:16:53 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> startsWithYAMLMetadataDelimiter [
|
|
|
|
self lines ifEmpty: [^false].
|
|
|
|
^ self lines first beginsWith: self class yamlMetadataDelimiter
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2023-11-01 14:25:49 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> withoutXMLTagDelimiters [
|
|
|
|
^ self copyWithoutAll: #($< $>)
|
|
|
|
]
|
2024-03-25 16:16:53 +00:00
|
|
|
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> yamlMetadata [
|
|
|
|
^ (YAML2JSON fromString: self yamlMetadataString)
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> yamlMetadataClosingLineNumber [
|
|
|
|
"I return the line where the closing of the YAML metadata occurs or 0 if no closing is found."
|
|
|
|
self startsWithYAMLMetadataDelimiter ifFalse: [ ^ self ].
|
|
|
|
self lines allButFirst doWithIndex: [ :currentLine :i |
|
|
|
|
(currentLine beginsWith: self class yamlMetadataDelimiter) ifTrue: [ ^ i + 1 ]]
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String class >> yamlMetadataDelimiter [
|
|
|
|
^ '---'
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> yamlMetadataString [
|
|
|
|
| output yamlLines |
|
|
|
|
self detectYAMLMetadata ifFalse: [ ^nil ].
|
|
|
|
self lines ifEmpty: [ ^nil ].
|
|
|
|
yamlLines := self lines copyFrom: 2 to: self yamlMetadataClosingLineNumber - 1.
|
|
|
|
output := '' writeStream.
|
|
|
|
yamlLines do: [ :line |
|
|
|
|
output
|
|
|
|
nextPutAll: line;
|
|
|
|
nextPut: Character lf. ].
|
|
|
|
^ output contents
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
String >> yamlMetadataStringWithDelimiters [
|
|
|
|
| output |
|
|
|
|
self yamlMetadataString ifNil: [ ^ nil ].
|
|
|
|
output := String new writeStream.
|
|
|
|
output nextPutAll: self class yamlMetadataDelimiter; cr.
|
|
|
|
output nextPutAll: self yamlMetadataString.
|
|
|
|
output nextPutAll: self class yamlMetadataDelimiter; cr.
|
|
|
|
^ output contents.
|
|
|
|
]
|