Repackaging and moving from Grafoscopio-Utils.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2022-07-16 12:29:57 -05:00
parent b6514c136d
commit 28e21b5e79
9 changed files with 189 additions and 10 deletions

View File

@ -1 +0,0 @@
Package { #name : #Markdeep }

View File

@ -1,6 +1,6 @@
Extension { #name : #LePage }
{ #category : #'*Markdeep' }
{ #category : #'*MiniDocs' }
LePage >> asMarkdeep [
| bodyStream markdeep |
bodyStream := '' writeStream.
@ -29,21 +29,21 @@ LePage >> asMarkdeep [
^ markdeep.
]
{ #category : #'*Markdeep' }
{ #category : #'*MiniDocs' }
LePage >> asMarkdeepFile [
| folder |
folder := self options at: 'storage' ifAbsent: [ FileLocator temp ].
^ self asMarkdeep exportAsFileOn: folder / self markdeepFileName
]
{ #category : #'*Markdeep' }
{ #category : #'*MiniDocs' }
LePage >> markdeepFileName [
| sanitized |
sanitized := self title asDashedLowercase copyWithoutAll: #($/).
^ sanitized, '--',(self uidString copyFrom: 1 to: 5), '.md.html'.
]
{ #category : #'*Markdeep' }
{ #category : #'*MiniDocs' }
LePage >> preorderTraversal [
| output |
output := OrderedCollection new.

View File

@ -1,6 +1,6 @@
Extension { #name : #LeSnippet }
{ #category : #'*Markdeep' }
{ #category : #'*MiniDocs' }
LeSnippet class >> fromMetaMarkdeep: div [
| className metadata snippet |
className := (div xpath: '@st-class') stringValue.

View File

@ -1,11 +1,11 @@
Extension { #name : #LeTextualSnippet }
{ #category : #'*Markdeep' }
{ #category : #'*MiniDocs' }
LeTextualSnippet >> markdeepCustomCloser [
^ ''
]
{ #category : #'*Markdeep' }
{ #category : #'*MiniDocs' }
LeTextualSnippet >> markdeepCustomOpener [
^ ''
]

View File

@ -0,0 +1,13 @@
"
Please describe the package using the class comment of the included manifest class. The manifest class also includes other additional metadata for the package. These meta data are used by other tools such as the SmalllintManifestChecker and the critics Browser
"
Class {
#name : #ManifestMiniDocs,
#superclass : #PackageManifest,
#category : #'MiniDocs-Manifest'
}
{ #category : #'code-critics' }
ManifestMiniDocs class >> ruleExcessiveVariablesRuleV1FalsePositive [
^ #(#(#(#RGClassDefinition #(#Markdeep)) #'2022-07-16T12:24:34.695032-05:00') )
]

View File

@ -16,7 +16,7 @@ Class {
'navTop',
'options'
],
#category : #Markdeep
#category : #MiniDocs
}
{ #category : #'as yet unclassified' }

View File

@ -0,0 +1,166 @@
"
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 : #MiniDocs
}
{ #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 ]]
]

View File

@ -7,7 +7,7 @@ Class {
#instVars : [
'file'
],
#category : #Markdeep
#category : #MiniDocs
}
{ #category : #persistence }

1
src/MiniDocs/package.st Normal file
View File

@ -0,0 +1 @@
Package { #name : #MiniDocs }