From 1770fc89cc78c1f0889395fa5a3a508b302307d8 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Sun, 23 Oct 2022 09:30:53 -0500 Subject: [PATCH] Fixing conversion from PubPub footnotes links to Markdeep's. --- src/MiniDocs/Markdeep.class.st | 64 ++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/MiniDocs/Markdeep.class.st b/src/MiniDocs/Markdeep.class.st index 185ee30..03185ad 100644 --- a/src/MiniDocs/Markdeep.class.st +++ b/src/MiniDocs/Markdeep.class.st @@ -132,7 +132,7 @@ Markdeep >> exportAsFile [ | newFile | self markdownFile ifNil: [ self inform: 'Define an input Markdown file or use #exportAsFileOn: instead.' ]. newFile := (self markdownFile file fullName, '.html') asFileReference. - self exportAsFileOn: newFile. + ^ self exportAsFileOn: newFile. ] { #category : #persistence } @@ -288,28 +288,6 @@ Markdeep >> processMarkdownFor: aFileReference [ 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 } Markdeep >> pubPubFootnoteMetadataFromString: string [ | sanitized footnoteData | @@ -325,7 +303,7 @@ Markdeep >> pubPubFootnoteMetadataFromString: string [ sanitized := sanitized contents copyReplaceAll: '.footnote ' with: ''. sanitized := sanitized copyReplaceAll: 'type=' with: 'type: '. 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 ] @@ -340,8 +318,8 @@ Markdeep >> pubPubFootnoteRawLinks [ { #category : #accessing } Markdeep >> pubPubFootnotesLinesRange [ | beginningLine endingLine | - beginningLine := self body lines size + 1. - self body lines doWithIndex: [:line :i | + beginningLine := self contents lines size + 1. + self contents lines doWithIndex: [:line :i | (line beginsWith: '::: {.pub-notes}') ifTrue: [ beginningLine := i ]. (i > beginningLine and: [ line beginsWith: ':::' ]) ifTrue: [ @@ -353,7 +331,39 @@ Markdeep >> pubPubFootnotesLinesRange [ { #category : #accessing } 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 }