Repackaging to MiniDocs

This commit is contained in:
Offray Vladimir Luna Cárdenas 2022-07-25 18:50:51 -05:00
parent 4dd31c6770
commit 3bfa6b633e
3 changed files with 0 additions and 216 deletions

View File

@ -35,25 +35,6 @@ LePage >> fromMarkdeepUrl: aString [
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> metadata [
^ self options at: 'metadata' ifAbsentPut: [ self metadataInit]
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> metadataInit [
^ OrderedDictionary new
at: 'id' put: self uidString;
at: 'title' put: self contentAsString;
at: 'created' put: self createTime asString;
at: 'modified' put: self latestEditTime asString;
at: 'creator' put: self createEmail asString;
at: 'modifier' put: self editEmail asString;
yourself
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> navTop [
| topNavFile |
@ -63,11 +44,6 @@ LePage >> navTop [
ifTrue: [ ^ topNavFile contents ]
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> options [
^ options
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> populateChildrenFrom: docTreeDivs [
docTreeDivs doWithIndex: [:div :i | | snippetTemp parent "surrogate" |
@ -77,14 +53,6 @@ LePage >> populateChildrenFrom: docTreeDivs [
]
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> preorderTraversal [
| output |
output := OrderedCollection new.
self withDeepCollect: [:each | each allChildrenBreadthFirstDo: [:child | output add: child ] ].
^ output.
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePage >> removeSnippetsMetadata [
self preorderTraversal do: [ :snippet |

View File

@ -11,21 +11,3 @@ LePharoSnippet >> contentFrom: markdeepDiv [
].
self code: sanitized contents allButLast.
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePharoSnippet >> markdeepCustomCloser [
^ String streamContents: [:stream |
stream
nextPutAll: '~~~'; lf;
nextPutAll: '</script>'; lf.
]
]
{ #category : #'*Grafoscopio-Utils-Core' }
LePharoSnippet >> markdeepCustomOpener [
^ String streamContents: [:stream |
stream
nextPutAll: '<script type="preformatted">'; lf;
nextPutAll: '~~~ Smalltalk'; lf
]
]

View File

@ -1,166 +0,0 @@
"
I model a Markdown document.
At some point the idea is to have a full native parser implemented to deal
with my syntax, but meanwhile I will be collaborating with external parsers,
particularly the ones provided by Pandoc and/or Lunamark.
"
Class {
#name : #Markdown,
#superclass : #Object,
#instVars : [
'contents',
'file'
],
#category : #'Grafoscopio-Utils'
}
{ #category : #'instance creation' }
Markdown class >> fromFile: aFileReference [
^ self new fromFile: aFileReference
]
{ #category : #utilities }
Markdown class >> yamlMetadataDelimiter [
^ '---'
]
{ #category : #operation }
Markdown >> commentYAMLMetadata [
| newContents |
self detectYAMLMetadata ifFalse: [ ^ self ].
newContents := '' writeStream.
newContents nextPutAll: '<!--@yaml:'; crlf.
newContents nextPutAll: self extractYAMLMetadata.
newContents nextPutAll: String cr.
newContents nextPutAll: '-->'; crlf.
(self lines copyFrom: self yamlMetadataClosingLineNumber + 2 to: self lines size) do: [ :line |
newContents nextPutAll: line; crlf ].
self contents: newContents contents.
^ self contents
]
{ #category : #utilities }
Markdown >> containsYAMLMetadataClosing [
^ self yamlMetadataClosingLineNumber > 0
]
{ #category : #accessing }
Markdown >> contents [
^ contents
]
{ #category : #accessing }
Markdown >> contents: anObject [
contents := anObject
]
{ #category : #utilities }
Markdown >> detectYAMLMetadata [
| lines |
lines := self lines.
^ self startsWithYAMLMetadataDelimiter
and: [ lines allButFirst
detect: [ :currentLine | currentLine beginsWith: self class yamlMetadataDelimiter ]
ifFound: [ ^ true ] ifNone: [ ^ false ] ]
]
{ #category : #operation }
Markdown >> exportMetadataAsJson [
"TBD: Lua scripts should be checked and installed when missing. Maybe a shared location
in '.local/share/Grafoscopio/Scripts' should be developed in the near future."
| output luaScript |
luaScript := FileLocator home / '.local/share/Brea/scripts/meta-to-json.lua'.
Smalltalk platformName = 'unix' ifTrue: [
OSSUnixSubprocess new
workingDirectory: self file parent fullName;
command: 'pandoc';
arguments: { '--lua-filter=', luaScript fullName . self file basename };
redirectStdout;
redirectStdin;
runAndWaitOnExitDo: [ :process :outString :errString |
output := process isSuccess
ifTrue: [ outString ]
ifFalse: [ errString ]
]].
^ output correctAccentedCharacters
]
{ #category : #operation }
Markdown >> exportMetadataAsYaml [
| exportedFile |
exportedFile := FileLocator temp / 'metadata.yaml'.
MarkupFile exportAsFileOn: exportedFile containing: self yamlMetadataAsString.
^ exportedFile
]
{ #category : #operation }
Markdown >> extractYAMLMetadata [
| output yamlLines |
self detectYAMLMetadata ifFalse: [ ^ nil ].
yamlLines := self lines copyFrom: 2 to: (self yamlMetadataClosingLineNumber).
output := '' writeStream.
yamlLines do: [ :line |
output
nextPutAll: line;
nextPut: Character cr. ].
^ output contents
]
{ #category : #accessing }
Markdown >> file [
^ file
]
{ #category : #accessing }
Markdown >> file: aFileReference [
"I store the origen/destination of the Markdown contents."
file := aFileReference
]
{ #category : #'instance creation' }
Markdown >> fromFile: aFileReference [
self contents: aFileReference contents.
self file: aFileReference
]
{ #category : #utilities }
Markdown >> lines [
^ self contents lines.
]
{ #category : #accessing }
Markdown >> metadata [
| rawMeta |
rawMeta := PPYAMLGrammar new parse: self extractYAMLMetadata.
rawMeta associationsDo: [ :assoc |
assoc value = 'false' ifTrue: [ assoc value: false ].
assoc value = 'true' ifTrue: [ assoc value: true ] ].
^ rawMeta
]
{ #category : #utilities }
Markdown >> startsWithYAMLMetadataDelimiter [
^ self lines first beginsWith: self class yamlMetadataDelimiter
]
{ #category : #utilities }
Markdown >> yamlMetadataAsString [
| output |
self extractYAMLMetadata ifNil: [ ^ nil ].
output := String new writeStream.
output nextPutAll: self class yamlMetadataDelimiter; cr.
output nextPutAll: self extractYAMLMetadata.
output nextPutAll: self class yamlMetadataDelimiter; cr.
^ output contents.
]
{ #category : #utilities }
Markdown >> yamlMetadataClosingLineNumber [
"I return the line where the closing of the YAML metadata occurs or 0 if no closing is found."
self startsWithYAMLMetadataDelimiter ifFalse: [ ^ self ].
self lines allButFirst doWithIndex: [ :currentLine :i |
(currentLine beginsWith: self class yamlMetadataDelimiter) ifTrue: [ ^ i + 1 ]]
]