" I model a Mardeep file as described in https://casual-effects.com/markdeep/ " Class { #name : #Markdeep, #superclass : #Markdown, #instVars : [ 'comments', 'tail', 'language', 'config', 'head', 'navTop', 'options' ], #category : #'MiniDocs-Core' } { #category : #'as yet unclassified' } Markdeep class >> fromMarkdownFile: aFileReference [ ^ self new fromMarkdownFile: aFileReference. ] { #category : #accessing } Markdeep class >> fromPubPubTOC: orderedDictionary folder: folder index: ordinalPossitive [ | contentSection testFile | contentSection := orderedDictionary associations at: ordinalPossitive. testFile := folder / (contentSection key,'--', contentSection value),'md'. ^ self new fromMarkdownFile: testFile. ] { #category : #accessing } Markdeep >> asMarkdown [ ^ Markdown new metadata: self metadata; body: self body; file: self markdownFile ] { #category : #'instance creation' } Markdeep >> authors [ self metadata at: 'authors' ifAbsentPut: [ Dictionary new ]. "self metadata at: 'authors' ifNotEmpty: [:k | ^ '**', k, '**' ] " ^ ''. ] { #category : #'instance creation' } Markdeep >> authorsString [ self authors ifEmpty: [ ^ '' ] ifNotEmpty: [ ^ ' ', self authors ] ] { #category : #accessing } Markdeep >> body [ ^ body ifNil: [^ '' ] ] { #category : #accessing } Markdeep >> body: anObject [ body := anObject ] { #category : #accessing } Markdeep >> bodyReplaceAll: original with: replacement [ self body: (self body copyReplaceAll: original with: replacement) ] { #category : #accessing } Markdeep >> cleanMetadata [ metadata := nil ] { #category : #accessing } Markdeep >> commentPubPubDelimiters [ | commented openners | openners := #('::: {.pub-body-component}' '::: pub-body-component' '::: {.editor .Prosemirror}' '::: {.pub-notes}'). commented := self body. openners do: [:openner | commented := commented copyReplaceAll: openner with: '' ]. commented := commented copyReplaceAll: '::: ' with: ' '. self body: commented ] { #category : #accessing } Markdeep >> comments [ ^ comments ifNil: [ ^ comments := true ] ] { #category : #accessing } Markdeep >> comments: aBoolean [ "I tell if comments are enabled by default or not." comments := aBoolean ] { #category : #utilities } Markdeep >> commentsProvider [ "I return the url of the default service that provides annotation support. I am used to add such support in the contents of the Markdeep page." ^ 'https://hypothes.is' ] { #category : #utilities } Markdeep >> commentsProviderStrings [ "I associate a comments service provider with the string that is required to be added to the document to enable such provider." | providers | providers := Dictionary new. providers at: 'https://hypothes.is' put: ' '. ^ providers ] { #category : #utilities } Markdeep >> commentsSupport [ "I enable comments of the page." self comments ifFalse: [ ^ self ]. ^ self commentsProviderStrings at: self commentsProvider ] { #category : #accessing } Markdeep >> config [ | configFile | configFile := self folder / 'config.ston'. configFile exists ifTrue: [ ^ config := STON fromString: configFile contents ]. ^ config ifNil: [ config := Dictionary new] ] { #category : #accessing } Markdeep >> config: aDictionary [ config := aDictionary ] { #category : #'instance creation' } Markdeep >> contents [ | output | self title ifNil: [ ^ self body ]. output := '' writeStream. output nextPutAll: self headContents; lf; lf; nextPutAll: ' **', self title trimmed accentedCharactersCorrection, '**'; lf; nextPutAll: self authorsString ; lf; nextPutAll: '', self version; lf; nextPutAll: self navTop; lf; lf; nextPutAll: self body; lf; lf; nextPutAll: self tail; lf; lf; lf; lf; nextPutAll: self commentsSupport. ^ output contents. ] { #category : #accessing } Markdeep >> converPubPubFootnoteBetween: footnote and: nextFootnote in: footnotesArray [ | currentNoteIndex nextNoteIndex response noteLines | currentNoteIndex := footnotesArray indexOf: '[^',footnote, ']: '. nextNoteIndex := footnotesArray indexOf: '[^',nextFootnote, ']: '. noteLines := footnotesArray copyFrom: currentNoteIndex to: nextNoteIndex - 1. response := '' writeStream. noteLines do: [:line | line ifNotEmpty: [ response nextPutAll: line, String lf ] "ifEmpty: [ response nextPutAll: ' ' ]?" ]. response nextPutAll: String lf. ^ response contents ] { #category : #accessing } Markdeep >> extractTitleFrom: docTree [ | tempTitle | tempTitle := ((docTree children detect: [ :node | node className = 'PPCMIndentedCode' ]) children detect: [ :subnode | subnode text trimmed beginsWith: '**' ]) text trimmed. self title: (tempTitle copyFrom: 3 to: tempTitle size - 2). ^ tempTitle ] { #category : #accessing } Markdeep >> extractYamlMetadataFrom: documentTree [ | yamlComment response | yamlComment := documentTree children detect: [:node | node className = 'PPCMHtmlBlock' and: [node text trimmed beginsWith: ''). ] ]. newBodyLines := (beforeFootnotes copyWithAll: (#('# Footnotes' '') copyWithAll:(reformated lines copyWithAll: afterFootnotes))). response := '' writeStream. newBodyLines do: [:line | response nextPutAll: line, String lf ]. self body: response contents. ] { #category : #accessing } Markdeep >> replaceBackslashBreaklines [ self bodyReplaceAll: '\ ' with: '
' ] { #category : #accessing } Markdeep >> replaceEscapedCharacters [ self title: (self title copyReplaceAll: '\#' with: '#'); body: (self body copyReplaceAll: '\#' with: '#'); body: (self body copyReplaceAll: '\[' with: '['); body: (self body copyReplaceAll: '\]' with: ']'); body: (self body copyReplaceAll: '\*' with: '*') ] { #category : #accessing } Markdeep >> replacePubPubFootnotesIdentifiers [ | footnotes sanitized parsedLinks linkIdentifiers | 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 ] ] { #category : #accessing } Markdeep >> tail [ "I enable the document tail, which, in turn, enables a Markdeep document" | output | output := '' writeStream. output nextPutAll: ''; lf; lf; nextPutAll: ''; lf; nextPutAll: ''; lf; nextPutAll: self markdeepScriptTag; lf; nextPutAll: ''. ^ output contents ] { #category : #accessing } Markdeep >> tail: anObject [ tail := anObject ] { #category : #accessing } Markdeep >> title [ ^ title ] { #category : #accessing } Markdeep >> title: anObject [ title := anObject ] { #category : #accessing } Markdeep >> tocStyle [ ^ self options at: 'tocStyle' ifAbsent: [ 'short' ] ] { #category : #accessing } Markdeep >> tocStyle: aString [ "A string can be: 'auto' 'none' 'short' 'medium' or 'long'" self options at: 'tocStyle' put: aString ] { #category : #'instance creation' } Markdeep >> version [ self metadata at: 'version' ifPresent: [:value | ^ 'v',value ]. ^ '' ]