2021-02-23 16:55:45 +00:00
|
|
|
"
|
|
|
|
I model a Mardeep file as described in https://casual-effects.com/markdeep/
|
|
|
|
"
|
|
|
|
Class {
|
|
|
|
#name : #Markdeep,
|
|
|
|
#superclass : #Object,
|
|
|
|
#instVars : [
|
2022-01-24 01:38:07 +00:00
|
|
|
'title',
|
|
|
|
'body',
|
2021-02-23 16:55:45 +00:00
|
|
|
'tocStyle',
|
|
|
|
'comments',
|
|
|
|
'header',
|
|
|
|
'tail',
|
|
|
|
'language',
|
2022-01-28 23:53:07 +00:00
|
|
|
'config',
|
|
|
|
'metadata'
|
2021-02-23 16:55:45 +00:00
|
|
|
],
|
2022-01-22 15:23:56 +00:00
|
|
|
#category : #'Grafoscopio-Utils-Core'
|
2021-02-23 16:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ #category : #'as yet unclassified' }
|
|
|
|
Markdeep class >> fromMarkdownFile: aFileReference [
|
|
|
|
^ self new fromMarkdownFile: aFileReference.
|
|
|
|
]
|
|
|
|
|
2022-01-28 23:53:07 +00:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
Markdeep >> authors [
|
|
|
|
^ self metadata at: 'authors' ifAbsent: [ ^'' ]
|
|
|
|
]
|
|
|
|
|
2021-02-23 16:55:45 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> body [
|
|
|
|
^ body
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> body: anObject [
|
|
|
|
body := anObject
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #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: '<!-- Hypothesis -->
|
|
|
|
<script src="https://hypothes.is/embed.js" async></script>'.
|
|
|
|
^ providers
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #utilities }
|
|
|
|
Markdeep >> commentsSupport [
|
|
|
|
"I enable comments of the page."
|
|
|
|
|
|
|
|
self comments ifFalse: [ ^ self ].
|
|
|
|
^ self commentsProviderStrings at: self commentsProvider
|
|
|
|
]
|
|
|
|
|
2022-01-24 01:38:07 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> config [
|
|
|
|
|
|
|
|
^ config
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> config: aDictionary [
|
|
|
|
|
|
|
|
config := aDictionary
|
|
|
|
]
|
|
|
|
|
2021-02-23 16:55:45 +00:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
Markdeep >> contents [
|
|
|
|
| output |
|
|
|
|
output := '' writeStream.
|
|
|
|
output
|
2022-01-27 14:23:34 +00:00
|
|
|
nextPutAll: self headerContents; lf; lf;
|
2022-01-28 23:53:07 +00:00
|
|
|
nextPutAll: ' **', self title, '**'; lf;
|
|
|
|
nextPutAll: ' **', self authors, '**'; lf;
|
|
|
|
nextPutAll: ' ', self version; lf; lf;
|
2022-01-24 01:38:07 +00:00
|
|
|
nextPutAll: self body; lf; lf;
|
|
|
|
nextPutAll: self tail; lf; lf; lf; lf;
|
2021-02-23 16:55:45 +00:00
|
|
|
nextPutAll: self commentsSupport.
|
|
|
|
^ output contents.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #persistence }
|
|
|
|
Markdeep >> exportAsFile [
|
|
|
|
| newFile |
|
|
|
|
self markdownFile ifNil: [ self inform: 'Define an input Markdown file or use #exportAsFileOn: instead.' ].
|
|
|
|
newFile := (self markdownFile fullName, '.html') asFileReference.
|
|
|
|
self exportAsFileOn: newFile.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #persistence }
|
|
|
|
Markdeep >> exportAsFileOn: aFileReference [
|
2022-01-27 14:23:34 +00:00
|
|
|
aFileReference ensureDelete.
|
2021-02-23 16:55:45 +00:00
|
|
|
aFileReference exists ifFalse: [ aFileReference ensureCreateFile ].
|
|
|
|
aFileReference writeStreamDo: [ :stream |
|
|
|
|
stream nextPutAll: self contents ].
|
2022-01-24 01:38:07 +00:00
|
|
|
self inform: 'Exported as: ', String cr, aFileReference fullName.
|
|
|
|
^ aFileReference
|
2021-02-23 16:55:45 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #utilities }
|
|
|
|
Markdeep >> fontAwesomeHeader [
|
|
|
|
"I enable the font awesome support in the document header"
|
|
|
|
|
2022-01-27 14:23:34 +00:00
|
|
|
^ '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">'
|
2021-02-23 16:55:45 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
Markdeep >> fromMarkdownFile: aFileReference [
|
|
|
|
"I create a Markdeep document from a given Markdown file."
|
|
|
|
self processMarkdownFor: aFileReference.
|
|
|
|
^ self.
|
|
|
|
]
|
|
|
|
|
2022-01-24 01:38:07 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> gtTextFor: aView [
|
|
|
|
<gtView>
|
|
|
|
^ aView textEditor
|
|
|
|
title: 'Text';
|
|
|
|
text: [ self contents ]
|
|
|
|
]
|
|
|
|
|
2021-02-23 16:55:45 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> header [
|
2022-01-27 14:23:34 +00:00
|
|
|
^ header ifNil: [header := OrderedCollection new.
|
|
|
|
header add: self fontAwesomeHeader; yourself ]
|
2021-02-23 16:55:45 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
2022-01-27 14:23:34 +00:00
|
|
|
Markdeep >> header: anOrderedCollection [
|
|
|
|
header := anOrderedCollection
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
Markdeep >> headerContents [
|
|
|
|
| output |
|
|
|
|
output := '' writeStream.
|
|
|
|
self header do: [:line |
|
|
|
|
output nextPutAll: line; lf ].
|
|
|
|
^ output contents.
|
2021-02-23 16:55:45 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> language [
|
|
|
|
^ language
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> language: anObject [
|
|
|
|
language := anObject
|
|
|
|
]
|
|
|
|
|
2022-01-24 01:38:07 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> markdeepScriptTag [
|
|
|
|
^ '<script src="markdeep.min.js" charset="utf-8"></script>
|
|
|
|
<script
|
|
|
|
src="https://casual-effects.com/markdeep/latest/markdeep.min.js?"
|
|
|
|
charset="utf-8">
|
|
|
|
</script>'
|
|
|
|
]
|
|
|
|
|
2021-02-23 16:55:45 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> markdownFile [
|
2022-01-24 01:38:07 +00:00
|
|
|
^ self config at: 'markdownFile'
|
2021-02-23 16:55:45 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> markdownFile: aFileReference [
|
2022-01-24 01:38:07 +00:00
|
|
|
"Where the Mardown file associated with me is stored. Used for sync. and import/export purposes."
|
|
|
|
self config at: 'markdownFile' put: aFileReference
|
|
|
|
]
|
|
|
|
|
2022-01-28 23:53:07 +00:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
Markdeep >> metadata [
|
|
|
|
^ metadata ifNil: [ metadata := OrderedDictionary new ]
|
|
|
|
]
|
|
|
|
|
2022-01-24 01:38:07 +00:00
|
|
|
{ #category : #printing }
|
|
|
|
Markdeep >> printOn: aStream [
|
|
|
|
|
|
|
|
super printOn: aStream.
|
|
|
|
aStream
|
|
|
|
nextPutAll: '( ', self title, ' )'
|
2021-02-23 16:55:45 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
Markdeep >> processMarkdownFor: aFileReference [
|
|
|
|
"comment stating purpose of message"
|
|
|
|
| markdownContent |
|
|
|
|
self markdownFile: aFileReference.
|
|
|
|
markdownContent := Markdown fromFile: aFileReference.
|
|
|
|
self body: (markdownContent commentYAMLMetadata contents).
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> tail [
|
|
|
|
"I enable the document tail, which, in turn, enables a Markdeep document"
|
2022-01-24 01:38:07 +00:00
|
|
|
| output |
|
|
|
|
output := '' writeStream.
|
|
|
|
output
|
|
|
|
nextPutAll: '<!-- Markdeep: -->'; lf; lf;
|
|
|
|
nextPutAll: '<style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style>'; lf;
|
|
|
|
nextPutAll: '<script>window.markdeepOptions = {tocStyle: "', self tocStyle,'"}</script>'; lf;
|
|
|
|
nextPutAll: self markdeepScriptTag; lf;
|
|
|
|
nextPutAll: '<!--<script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>-->'.
|
|
|
|
^ output contents
|
2021-02-23 16:55:45 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> tail: anObject [
|
|
|
|
tail := anObject
|
|
|
|
]
|
|
|
|
|
2022-01-24 01:38:07 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> title [
|
|
|
|
|
|
|
|
^ title
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> title: anObject [
|
|
|
|
|
|
|
|
title := anObject
|
|
|
|
]
|
|
|
|
|
2021-02-23 16:55:45 +00:00
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> tocStyle [
|
2022-01-24 01:38:07 +00:00
|
|
|
^ tocStyle ifNil: [ tocStyle := 'short' ]
|
2021-02-23 16:55:45 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
Markdeep >> tocStyle: anObject [
|
|
|
|
tocStyle := anObject
|
|
|
|
]
|
2022-01-28 23:53:07 +00:00
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
Markdeep >> version [
|
|
|
|
| semVer |
|
|
|
|
semVer := self metadata at: 'version' ifAbsent: [ ^'' ].
|
|
|
|
^ 'v', semVer
|
|
|
|
]
|