From 21641e9399c10757702b84af1720fca26869a79f Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Wed, 3 Oct 2018 11:11:10 +0000 Subject: [PATCH] Improving Unix (Mac, Gnu/Linux) Pandoc integration with new librarie. --- .../Grafoscopio/GrafoscopioNotebook.class.st | 12 ++++----- repository/Grafoscopio/Pandoc.class.st | 26 ++++++++++++++++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/repository/Grafoscopio/GrafoscopioNotebook.class.st b/repository/Grafoscopio/GrafoscopioNotebook.class.st index 6b98eae..f02783b 100644 --- a/repository/Grafoscopio/GrafoscopioNotebook.class.st +++ b/repository/Grafoscopio/GrafoscopioNotebook.class.st @@ -541,6 +541,12 @@ GrafoscopioNotebook >> notebookSubMenu [ name: 'Import images'; icon: (Smalltalk ui icons iconNamed: #processBrowser); action: [ self importImages ] ]. + group + addItem: [ :item | + item + name: 'See images list'; + icon: (Smalltalk ui icons iconNamed: #processBrowser); + action: [ self listImagesUI ] ]. group addItem: [ :item | item @@ -583,12 +589,6 @@ GrafoscopioNotebook >> notebookSubMenu [ name: 'See pdf'; icon: (Smalltalk ui icons iconNamed: #smallInspectIt); action: [ self inform: 'To be implemented...' ] ]. - group - addItem: [ :item | - item - name: 'See images list'; - icon: (Smalltalk ui icons iconNamed: #processBrowser); - action: [ self listImagesUI ] ]. group addItem: [ :item | item diff --git a/repository/Grafoscopio/Pandoc.class.st b/repository/Grafoscopio/Pandoc.class.st index 0e03cfc..4a174f7 100644 --- a/repository/Grafoscopio/Pandoc.class.st +++ b/repository/Grafoscopio/Pandoc.class.st @@ -40,6 +40,27 @@ Pandoc class >> executableLocation [ 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 : #'as yet unclassified' } Pandoc class >> listImagesFrom: aFileReference [ "I provide a list of all images contained in aFile." @@ -48,10 +69,9 @@ Pandoc class >> listImagesFrom: aFileReference [ filter exists ifFalse: [ self downloadLuaFilters ]. commandString := 'pandoc ', aFileReference fullName, ' --lua-filter=',filter fullName. Smalltalk platformName = 'unix' - ifTrue: [ outputString := (PipeableOSProcess waitForCommand: commandString ) output ]. + ifTrue: [ ^ self extractImagesInUnixFor: aFileReference withFilter: filter ]. Smalltalk platformName = 'Win32' - ifTrue: [ WindowsProcess ]. - ^ ((Soup fromString: outputString) findAllTags: 'td') collect: [ :each | each next ] + ifTrue: [ self ]. ] { #category : #utility }