Fixing conversion from PubPub footnotes links to Markdeep's.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2022-10-23 09:30:53 -05:00
parent 0a6dccba99
commit 1770fc89cc

View File

@ -132,7 +132,7 @@ Markdeep >> exportAsFile [
| newFile | | newFile |
self markdownFile ifNil: [ self inform: 'Define an input Markdown file or use #exportAsFileOn: instead.' ]. self markdownFile ifNil: [ self inform: 'Define an input Markdown file or use #exportAsFileOn: instead.' ].
newFile := (self markdownFile file fullName, '.html') asFileReference. newFile := (self markdownFile file fullName, '.html') asFileReference.
self exportAsFileOn: newFile. ^ self exportAsFileOn: newFile.
] ]
{ #category : #persistence } { #category : #persistence }
@ -288,28 +288,6 @@ Markdeep >> processMarkdownFor: aFileReference [
self metadata: markdownContent yamlMetadata self metadata: markdownContent yamlMetadata
] ]
{ #category : #accessing }
Markdeep >> pubPubFootnoteLinks [
| footnotes sanitized footnotesText |
footnotes := OrderedDictionary new.
self pubPubFootnoteRawLinks do: [:link | | footnote|
footnote := self pubPubFootnoteMetadataFromString: link second.
footnote ifNotNil: [ | toReplace |
footnotes at: link first put: footnote.
toReplace := '[', link first, ']', '{', link second, '}'.
sanitized := self body copyReplaceAll: toReplace with: '[^', link first, ']'
]
].
footnotesText := '' writeStream.
footnotes keysAndValuesDo: [:k :v |
footnotesText
nextPutAll: '[^', k, ']: ';
nextPutAll: (v at: 'data-value')
].
self pubPubFootnotesText.
^ {footnotes . sanitized . footnotesText contents } third
]
{ #category : #accessing } { #category : #accessing }
Markdeep >> pubPubFootnoteMetadataFromString: string [ Markdeep >> pubPubFootnoteMetadataFromString: string [
| sanitized footnoteData | | sanitized footnoteData |
@ -325,7 +303,7 @@ Markdeep >> pubPubFootnoteMetadataFromString: string [
sanitized := sanitized contents copyReplaceAll: '.footnote ' with: ''. sanitized := sanitized contents copyReplaceAll: '.footnote ' with: ''.
sanitized := sanitized copyReplaceAll: 'type=' with: 'type: '. sanitized := sanitized copyReplaceAll: 'type=' with: 'type: '.
sanitized := sanitized copyReplaceAll: 'value=' with: 'value: '. sanitized := sanitized copyReplaceAll: 'value=' with: 'value: '.
footnoteData := { 'id' -> string lines first } asDictionary. footnoteData := { 'id' -> string lines first allButFirst } asDictionary.
footnoteData addAll: (MiniDocs yamlToJson: sanitized). footnoteData addAll: (MiniDocs yamlToJson: sanitized).
^ footnoteData ^ footnoteData
] ]
@ -340,8 +318,8 @@ Markdeep >> pubPubFootnoteRawLinks [
{ #category : #accessing } { #category : #accessing }
Markdeep >> pubPubFootnotesLinesRange [ Markdeep >> pubPubFootnotesLinesRange [
| beginningLine endingLine | | beginningLine endingLine |
beginningLine := self body lines size + 1. beginningLine := self contents lines size + 1.
self body lines doWithIndex: [:line :i | self contents lines doWithIndex: [:line :i |
(line beginsWith: '::: {.pub-notes}') ifTrue: [ beginningLine := i ]. (line beginsWith: '::: {.pub-notes}') ifTrue: [ beginningLine := i ].
(i > beginningLine and: [ line beginsWith: ':::' ]) (i > beginningLine and: [ line beginsWith: ':::' ])
ifTrue: [ ifTrue: [
@ -353,7 +331,39 @@ Markdeep >> pubPubFootnotesLinesRange [
{ #category : #accessing } { #category : #accessing }
Markdeep >> pubPubFootnotesText [ Markdeep >> pubPubFootnotesText [
^ self pubPubFootnotesLinesRange | footnotesLines output |
footnotesLines := self contents lines
copyFrom: self pubPubFootnotesLinesRange first + 3
to: self pubPubFootnotesLinesRange second - 1.
output := '' writeStream.
footnotesLines do: [:line |
output
nextPutAll: line;
nextPutAll: String crlf.
].
^ output contents allButLast
]
{ #category : #accessing }
Markdeep >> pubPubFootnotesToMarkdeep [
| footnotes sanitized cleanedFootnotesText |
footnotes := OrderedDictionary new.
self pubPubFootnoteRawLinks do: [:link | | footnote|
footnote := self pubPubFootnoteMetadataFromString: link second.
footnote ifNotNil: [ | toReplace |
footnotes at: (footnote at: 'id') put: footnote.
toReplace := '[', link first, ']', '{', link second, '}'.
sanitized := self body copyReplaceAll: toReplace with: '[^', (footnote at: 'id'), ']'
]
].
cleanedFootnotesText := '' writeStream.
footnotes keysAndValuesDo: [:k :v |
cleanedFootnotesText
nextPutAll: '[^', k, ']: ';
nextPutAll: (v at: 'data-value')
].
"^ {footnotes . sanitized copyReplaceAll: self pubPubFootnotesText with: cleanedFootnotesText contents }."
self body: (sanitized copyReplaceAll: self pubPubFootnotesText with: cleanedFootnotesText contents)
] ]
{ #category : #accessing } { #category : #accessing }