From e20cca500e13ca9479823e7add759b897e39ea8e Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Tue, 9 May 2023 21:56:19 -0500 Subject: [PATCH] Footnotes improved identifiers partial implementaiton. --- src/MiniDocs/Markdeep.class.st | 67 +++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/src/MiniDocs/Markdeep.class.st b/src/MiniDocs/Markdeep.class.st index 13a02d2..d60ef7b 100644 --- a/src/MiniDocs/Markdeep.class.st +++ b/src/MiniDocs/Markdeep.class.st @@ -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 ]