123 lines
3.5 KiB
Smalltalk
123 lines
3.5 KiB
Smalltalk
Extension { #name : #LePictureSnippet }
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePictureSnippet >> asMarkdeep [
|
|
| output curatedCaption captionLines |
|
|
captionLines := self caption lines.
|
|
(captionLines size <= 1)
|
|
ifTrue: [ curatedCaption := caption ]
|
|
ifFalse: [
|
|
curatedCaption := WriteStream on: ''.
|
|
curatedCaption nextPutAll: captionLines first.
|
|
captionLines allButFirstDo: [:line |
|
|
curatedCaption nextPutAll: ' ', line.
|
|
curatedCaption := curatedCaption contents.
|
|
]
|
|
].
|
|
output := WriteStream on: ''.
|
|
output
|
|
nextPutAll: self metadataDiv;
|
|
nextPutAll: '![ ', curatedCaption ,' ](', self urlString, ')';
|
|
nextPut: Character lf;
|
|
nextPutAll: '</div>';
|
|
nextPut: Character lf;
|
|
nextPut: Character lf.
|
|
^ output contents
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePictureSnippet >> asMarkdownWithMetadataWrappers [
|
|
^ self asMarkdeep
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePictureSnippet >> contentFrom: markdeepDiv [
|
|
| caption width |
|
|
caption := markdeepDiv contentString.
|
|
width := (markdeepDiv // 'img' @ 'width') stringValue.
|
|
self
|
|
optionAt: 'caption' put: caption;
|
|
optionAt: 'width' put: width.
|
|
self urlString: (markdeepDiv // 'img' @ 'src') stringValue.
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePictureSnippet >> fromMarkdeep: markdeepDiv [
|
|
^ markdeepDiv asSnippetDictionary asLepiterSnippet
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePictureSnippet >> fromString: aStringArray [
|
|
"aStringArray should contain as first element the sanitized string and
|
|
as second the full original image Link string, which may contains links in the description."
|
|
| args urlTemp |
|
|
|
|
args := aStringArray second splitOn: ']('.
|
|
urlTemp := args last.
|
|
urlTemp := urlTemp copyFrom: 1 to: urlTemp size - 1.
|
|
self caption: aStringArray first.
|
|
self urlString: urlTemp.
|
|
^ self
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePictureSnippet >> metadata [
|
|
^ self metadataInit
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePictureSnippet >> metadataDiv [
|
|
| output |
|
|
output := WriteStream on: ''.
|
|
output
|
|
nextPutAll: '<div st-class="' , self class greaseString , '"';
|
|
nextPut: Character lf;
|
|
nextPutAll: ' st-data="' , (STON toStringPretty: self metadata) , '">';
|
|
nextPut: Character lf.
|
|
^ output contents withInternetLineEndings.
|
|
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePictureSnippet >> metadataInit [
|
|
| surrogate |
|
|
self parent
|
|
ifNil: [ surrogate := nil]
|
|
ifNotNil: [ surrogate := self parent uidString ].
|
|
^ OrderedDictionary new
|
|
at: 'id' put: self uidString;
|
|
at: 'parent' put: surrogate;
|
|
at: 'url' put: '<!--',self contentAsString, '-->';
|
|
at: 'created' put: self createTime asString;
|
|
at: 'modified' put: self latestEditTime asString;
|
|
at: 'creator' put: self createEmail asString withoutXMLTagDelimiters;
|
|
at: 'modifier' put: self editEmail asString withoutXMLTagDelimiters;
|
|
yourself
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePictureSnippet >> metadataUpdate [
|
|
| surrogate |
|
|
self parent
|
|
ifNil: [ surrogate := nil]
|
|
ifNotNil: [ surrogate := self parent uidString ].
|
|
^ OrderedDictionary new
|
|
at: 'id' put: self uidString;
|
|
at: 'parent' put: surrogate;
|
|
at: 'created' put: self createTime asString;
|
|
at: 'modified' put: self latestEditTime asString;
|
|
at: 'creator' put: self createEmail asString withoutXMLTagDelimiters;
|
|
at: 'modifier' put: self editEmail asString withoutXMLTagDelimiters;
|
|
yourself
|
|
]
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
LePictureSnippet >> sanitizeMetadata [
|
|
self metadata keysAndValuesDo: [:k :v |
|
|
(v includesAny: #($< $>))
|
|
ifTrue: [
|
|
self metadata at: k put: (v copyWithoutAll: #($< $>))
|
|
]
|
|
]
|
|
]
|