From dc218111e60377c002ff6e57f5d1f17f6b09564a Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Sun, 14 May 2023 11:59:09 -0500 Subject: [PATCH] Footnotes replacement done (minor bugs with last footnote still to be fixed). --- src/MiniDocs/Markdeep.class.st | 59 ++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/src/MiniDocs/Markdeep.class.st b/src/MiniDocs/Markdeep.class.st index e8e7a80..9cbb507 100644 --- a/src/MiniDocs/Markdeep.class.st +++ b/src/MiniDocs/Markdeep.class.st @@ -399,6 +399,32 @@ Markdeep >> pubPubRawLinks [ ^ (parser parse: self body) ] +{ #category : #accessing } +Markdeep >> reformatPubPubFootnotes [ + | footnotesLines footnotesIDs toReplace response | + footnotesLines := self contents lines + copyFrom: self pubPubFootnotesLinesRangeForContents first + to: self pubPubFootnotesLinesRangeForContents 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),']: ' + ]. + response := '' writeStream. + footnotesIDs allButLast doWithIndex: [:footnote :i | + response + nextPutAll: + (self + converPubPubFootnoteBetween: footnote + and: (footnotesIDs at: i + 1) + in: footnotesLines) + ]. + ^ response contents +] + { #category : #accessing } Markdeep >> removeAlternativeImagesArray [ | replacements | @@ -437,28 +463,21 @@ Markdeep >> removeCCByLicenseDiv [ { #category : #accessing } Markdeep >> renamePubPubFootnotes [ - | footnotesLines footnotesIDs toReplace response | - footnotesLines := self contents lines - copyFrom: self pubPubFootnotesLinesRangeForContents first - to: self pubPubFootnotesLinesRangeForContents 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),']: ' - ]. + | reformated bodyLines beforeFootnotes afterFootnotes newBodyLines response | + reformated := self reformatPubPubFootnotes. + bodyLines := self body lines. + beforeFootnotes := bodyLines copyFrom: 1 to: self pubPubFootnotesLinesRangeForBody first . + afterFootnotes := bodyLines copyFrom: self pubPubFootnotesLinesRangeForBody second to: bodyLines size. + newBodyLines := + (beforeFootnotes copyWithAll: + (#('# Footnotes' '') + copyWithAll:(reformated lines + copyWithAll: afterFootnotes))). response := '' writeStream. - footnotesIDs allButLast doWithIndex: [:footnote :i | - response - nextPutAll: - (self - converPubPubFootnoteBetween: footnote - and: (footnotesIDs at: i + 1) - in: footnotesLines) + newBodyLines do: [:line | + response nextPutAll: line, String lf ]. - ^ response contents + self body: response contents. ] { #category : #accessing }