Moving core functionality to GrafoscopioUtils.
This commit is contained in:
parent
b46e554b5e
commit
67b27d20b3
@ -59,7 +59,7 @@ GrafoscopioDocs >> initialize [
|
||||
self
|
||||
addDocument: 'Docs/Es/Tutoriales/tutorial.ston';
|
||||
addDocument: 'Docs/En/Books/Manual/manual.ston';
|
||||
addDocument: 'Docs/En/Books/Manual/manual.pdf';
|
||||
addDocument: 'uv/Docs/En/Books/Manual/manual.pdf';
|
||||
addDocument: 'Docs/En/Books/DataActivism/techniques-for-datactivism.ston';
|
||||
addDocument: 'Docs/En/dev-notes.ston';
|
||||
addDocument: 'Docs/En/Books/SpecIUFramework/spec-ui-framework.ston'.
|
||||
|
@ -814,11 +814,11 @@ GrafoscopioNotebook >> saveToFileUI [
|
||||
| file |
|
||||
|
||||
file := UIManager default
|
||||
chooseForSaveFileReference: 'Export notebook to file as...'
|
||||
chooseForSaveFileReference: 'Save notebook to file as...'
|
||||
extensions: #('ston')
|
||||
path: (workingFile ifNotNil: [ workingFile parent ] ifNil: [ FileLocator documents ] ).
|
||||
file
|
||||
ifNil: [ self inform: 'Export cancelled'. ^ self ]
|
||||
ifNil: [ self inform: 'Saving to file cancelled'. ^ self ]
|
||||
ifNotNil:[self saveToFile: file].
|
||||
]
|
||||
|
||||
|
@ -1,112 +0,0 @@
|
||||
"
|
||||
I model the interaction between Pandoc and Grafoscopio.
|
||||
"
|
||||
Class {
|
||||
#name : #Pandoc,
|
||||
#superclass : #Object,
|
||||
#classInstVars : [
|
||||
'executable'
|
||||
],
|
||||
#category : #'Grafoscopio-Model'
|
||||
}
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
Pandoc class >> downloadLuaFilters [
|
||||
self luaFilters do: [ :filter | | filterUrl |
|
||||
filterUrl := filter asUrl.
|
||||
(FileLocator temp asFileReference / (filterUrl segments last)) exists
|
||||
ifFalse: [
|
||||
ZnClient new
|
||||
url: filterUrl;
|
||||
downloadTo: FileLocator temp ] ]
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
Pandoc class >> executable [
|
||||
^ executable ifNil: [ self executableLocation ]
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
Pandoc class >> executable: aFileReference [
|
||||
executable := aFileReference
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
Pandoc class >> executableLocation [
|
||||
| location |
|
||||
location := '/usr/bin/pandoc'.
|
||||
location asFileReference exists
|
||||
ifTrue: [ ^ location ]
|
||||
ifFalse: [ self definePandocExecutable ]
|
||||
]
|
||||
|
||||
{ #category : #utility }
|
||||
Pandoc class >> extractImagesInUnixFor: aFileReference withFilter: aLuaFilter [
|
||||
"I use Pandoc Lua scripting capabilities to extract al images links in aFileReference"
|
||||
|
||||
OSSUnixSubprocess new
|
||||
command: 'pandoc';
|
||||
arguments: {aFileReference fullName . '--lua-filter=',aLuaFilter fullName };
|
||||
redirectStdout;
|
||||
redirectStderr;
|
||||
runAndWaitOnExitDo: [ :process :outString :errString |
|
||||
process isSuccess
|
||||
ifTrue: [
|
||||
^ ((Soup fromString: outString) findAllTags: 'td') collect: [ :each | each next ] ]
|
||||
ifFalse: [
|
||||
"OSSUnixProcessExitStatus has a nice #printOn: "
|
||||
Transcript show: 'Command exit with error status: ', process exitStatusInterpreter printString; cr.
|
||||
Transcript show: 'Stderr contents: ', errString.
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
{ #category : #converters }
|
||||
Pandoc class >> htmlToMarkdown: inputFile [
|
||||
|
||||
| outputFile |
|
||||
outputFile := FileLocator temp / 'body.md'.
|
||||
outputFile ensureDelete.
|
||||
outputFile ensureCreateFile.
|
||||
OSSUnixSubprocess new
|
||||
command: 'pandoc';
|
||||
arguments: {'-f'. 'html'. '-t'. 'markdown'. '--atx-headers'. inputFile fullName.
|
||||
'--output'. outputFile fullName };
|
||||
redirectStdout;
|
||||
redirectStderr;
|
||||
runAndWaitOnExitDo: [ :process :outString :errString |
|
||||
process isSuccess
|
||||
ifTrue: [ ^ outputFile contents ]
|
||||
ifFalse: [ ^inputFile contents ]
|
||||
]
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
Pandoc class >> listImagesFrom: aFileReference [
|
||||
"I provide a list of all images contained in aFile."
|
||||
| filter commandString outputString |
|
||||
filter := FileLocator temp asFileReference / 'image-links.lua'.
|
||||
filter exists ifFalse: [ self downloadLuaFilters ].
|
||||
commandString := 'pandoc ', aFileReference fullName, ' --lua-filter=',filter fullName.
|
||||
Smalltalk platformName = 'unix'
|
||||
ifTrue: [ ^ self extractImagesInUnixFor: aFileReference withFilter: filter ].
|
||||
Smalltalk platformName = 'Win32'
|
||||
ifTrue: [ self ].
|
||||
]
|
||||
|
||||
{ #category : #utility }
|
||||
Pandoc class >> luaFilters [
|
||||
"I define the location of set of scripts, that allows to change the default behaviour of Pandoc
|
||||
and/or the processing of supported markup languages.
|
||||
|
||||
For more information about Lua filters see:
|
||||
|
||||
https://pandoc.org/lua-filters.html
|
||||
"
|
||||
|
||||
| filters |
|
||||
filters := OrderedCollection new.
|
||||
filters
|
||||
add: 'http://mutabit.com/repos.fossil/dataweek/doc/tip/Artefactos/Scripts/image-links.lua'.
|
||||
^ filters
|
||||
]
|
Loading…
Reference in New Issue
Block a user