Footnotes improved identifiers partial implementaiton.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2023-05-09 21:56:19 -05:00
parent a3741918c9
commit e20cca500e

View File

@ -293,6 +293,10 @@ Markdeep >> pubPubFootnoteMetadataFromString: string [
altString := altString copyReplaceAll: ' node-type='
with: '
node-type= '.
altString := altString copyReplaceAll: ' data-value=' with: '
data-value='.
altString := altString copyReplaceAll: ' date-structured-value=' with: '
date-structured-value= '.
altString lines allButFirstDo: [:line |
(line beginsWith: '>')
ifTrue: [ altLine := line allButFirst ]
@ -320,7 +324,7 @@ Markdeep >> pubPubFootnotesLinesRange [
| beginningLine endingLine |
beginningLine := self contents lines size + 1.
self contents lines doWithIndex: [:line :i |
(line beginsWith: '::: {.pub-notes}') ifTrue: [ beginningLine := i ].
(line includesSubstring: '::: {.pub-notes}') ifTrue: [ beginningLine := i ].
(i > beginningLine and: [ line beginsWith: ':::' ])
ifTrue: [
endingLine := i.
@ -344,30 +348,6 @@ Markdeep >> pubPubFootnotesText [
^ output contents allButLast
]
{ #category : #accessing }
Markdeep >> pubPubFootnotesToMarkdeep [
| footnotes sanitized cleanedFootnotesText parsedLinks |
footnotes := OrderedDictionary new.
parsedLinks := self pubPubFootnoteRawLinks.
parsedLinks ifEmpty: [ ^self ].
sanitized := self body.
parsedLinks do: [:link | | footnote |
footnote := self pubPubFootnoteMetadataFromString: link second.
footnote ifNotNil: [ | toReplace |
footnotes at: (footnote at: 'id') put: footnote.
toReplace := '[', link first, ']{', link second, '}'.
sanitized := sanitized copyReplaceAll: toReplace with: '[^', (footnote at: 'id'), ']'
]
].
cleanedFootnotesText := '' writeStream.
footnotes keysAndValuesDo: [:k :v |
cleanedFootnotesText
nextPutAll: '[^', k, ']: ';
nextPutAll: (v at: 'data-value'), String lf, String lf.
].
self body: (sanitized copyReplaceAll: self pubPubFootnotesText with: cleanedFootnotesText contents)
]
{ #category : #accessing }
Markdeep >> pubPubImageLinks [
^ self selectPubPubLinksWithSize: 3
@ -429,6 +409,24 @@ Markdeep >> removeCCByLicenseDiv [
self body: (self body copyReplaceAll: licenseDiv with: '')
]
{ #category : #accessing }
Markdeep >> renamePubPubFootnotes [
| footnotesLines footnotesIDs toReplace |
footnotesLines := self contents lines
copyFrom: self pubPubFootnotesLinesRange first
to: self pubPubFootnotesLinesRange second.
footnotesIDs := self replacePubPubFootnotesIdentifiers.
toReplace := footnotesLines select: [:line |
(line includesSubstring: ' [[]{.pub-note-content-component}]{#fn-')
].
toReplace doWithIndex: [:replacement :i | | index |
index := footnotesLines indexOf: replacement.
footnotesLines at: index put: '[^', (footnotesIDs at: i),']: '
].
^ footnotesLines
]
{ #category : #accessing }
Markdeep >> replaceBackslashBreaklines [
self bodyReplaceAll: '\
@ -436,6 +434,25 @@ Markdeep >> replaceBackslashBreaklines [
'
]
{ #category : #accessing }
Markdeep >> replacePubPubFootnotesIdentifiers [
| footnotes sanitized parsedLinks linkIdentifiers footnotesLines |
footnotes := OrderedDictionary new.
parsedLinks := self pubPubFootnoteRawLinks.
parsedLinks ifEmpty: [ ^self ].
sanitized := self body.
linkIdentifiers := OrderedCollection new.
parsedLinks do: [:link | | id currentLinkText |
id := (link second splitOn: '.footnote') first trimmed.
linkIdentifiers add: id.
currentLinkText := '[', link first, ']{#',link second,'}'.
sanitized := sanitized copyReplaceAll: currentLinkText with: '[^', id, ']'
].
self body: sanitized.
^ linkIdentifiers
]
{ #category : #accessing }
Markdeep >> selectPubPubLinksWithSize: naturalNumber [
^ self pubPubRawLinks select: [ :each | each size = naturalNumber ]