diff --git a/repository/Grafoscopio/GrafoscopioNode.class.st b/repository/Grafoscopio/GrafoscopioNode.class.st index 704492d..133f693 100644 --- a/repository/Grafoscopio/GrafoscopioNode.class.st +++ b/repository/Grafoscopio/GrafoscopioNode.class.st @@ -329,22 +329,6 @@ GrafoscopioNode >> demote [ ] -{ #category : #'as yet unclassified' } -GrafoscopioNode >> downloadImagesInto: folder [ - "comment stating purpose of message" - - self extractHtmlImages do: [ :each | |localFolder path| - path:=''. - (each directory substrings: '/') do: [ :eachDirectory | - path:= path , '/' , eachDirectory . - (folder / path) ensureCreateDirectory ]. - localFolder := (folder / each directory). - (localFolder / each lastPathSegment) exists ifFalse: [ - ZnClient new - url: each ; - downloadTo: localFolder . ]] -] - { #category : #'custom markup' } GrafoscopioNode >> embedAll [ "This is just a previous part of the messy markDownContent. The %embed-all keyword should be revaluated. @@ -437,27 +421,17 @@ GrafoscopioNode >> exportPreambleTo: aStream [ { #category : #'as yet unclassified' } GrafoscopioNode >> extractHtmlImages [ "comment stating purpose of message" - |imgSoup imgHost imgList src folders| + |imgSoup imgHost imgList folders| imgList := Set new. imgSoup := Soup fromString: self body. imgHost:= self links last asUrl removeLastPathSegment. folders:= Set new. - (imgSoup findAllTags: 'img') do: [ :each| + (imgSoup findAllTags: 'img') do: [ :each|| src | src := (each attributeAt: 'src') asUrl. (src host) ifNil: [ src := imgHost addPathSegments: src pathSegments ]. imgList add: src. - "folders add: src directory." - "OSProcess waitForCommand: 'wget ', (each attributeAt: 'src')." - "imgHost := self links last removeLastPathSegment." - - "imgPath:= ((each attributeAt: 'src') asUrl). " - "ZnEasy getJpeg: (imgHost , imgPath) asUrl." - - "OSProcess waitForCommand: ('mkdir ', imgPath)." - - "Transcript show: ' wget ', imgPath , '/',(each attributeAt: 'src'). " - ]. + ]. ^imgList . ] diff --git a/repository/Grafoscopio/GrafoscopioNotebook.class.st b/repository/Grafoscopio/GrafoscopioNotebook.class.st index 37dd168..02bd8de 100644 --- a/repository/Grafoscopio/GrafoscopioNotebook.class.st +++ b/repository/Grafoscopio/GrafoscopioNotebook.class.st @@ -296,7 +296,6 @@ GrafoscopioNotebook >> header: anObject [ { #category : #operation } GrafoscopioNotebook >> htmlToMarkdown [ - self imagesList: self currentNodeContent extractHtmlImages. self currentNodeContent htmlToMarkdown. self updateBodyFor: self currentNode ] @@ -318,6 +317,12 @@ GrafoscopioNotebook >> imagesList: anObject [ imagesList := anObject ] +{ #category : #'as yet unclassified' } +GrafoscopioNotebook >> importImages [ + self imagesList: (Pandoc listImagesFrom: self markdownFile). + self inform: 'All notebook images has been imported.', String cr, 'Now you can list and download them.' +] + { #category : #operation } GrafoscopioNotebook >> importLinkContent [ "I see if a node header is an url located at 'http://ws.stfx.eu', wich means that is a shared @@ -522,18 +527,18 @@ GrafoscopioNotebook >> notebookSubMenu [ name: 'Save as...'; icon: (Smalltalk ui icons iconNamed: #smallSaveAs); action: [ self saveToFileUI ] ]. - group - addItem: [ :item | - item - name: 'Extract images'; - icon: (Smalltalk ui icons iconNamed: #processBrowser); - action: [ self extractImages ] ]. group addItem: [ :item | item name: 'Import images'; icon: (Smalltalk ui icons iconNamed: #processBrowser); action: [ self importImages ] ]. + group + addItem: [ :item | + item + name: 'Download images'; + icon: (Smalltalk ui icons iconNamed: #processBrowser); + action: [ self downloadImages ] ]. group addItem: [ :item | item @@ -1003,7 +1008,7 @@ GrafoscopioNotebook >> updateBodyFor: aNodeContainer [ self buildWithSpecLayout: self class defaultSpec ] -{ #category : #'editing nodes' } +{ #category : #operation } GrafoscopioNotebook >> visitNodeLink [ tree highlightedItem content visitLastLink. diff --git a/repository/Grafoscopio/Pandoc.class.st b/repository/Grafoscopio/Pandoc.class.st index 196e6ce..0e03cfc 100644 --- a/repository/Grafoscopio/Pandoc.class.st +++ b/repository/Grafoscopio/Pandoc.class.st @@ -10,6 +10,17 @@ Class { #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 ] @@ -29,6 +40,20 @@ Pandoc class >> executableLocation [ ifFalse: [ self definePandocExecutable ] ] +{ #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: [ outputString := (PipeableOSProcess waitForCommand: commandString ) output ]. + Smalltalk platformName = 'Win32' + ifTrue: [ WindowsProcess ]. + ^ ((Soup fromString: outputString) findAllTags: 'td') collect: [ :each | each next ] +] + { #category : #utility } Pandoc class >> luaFilters [ "I define the location of set of scripts, that allows to change the default behaviour of Pandoc @@ -42,5 +67,6 @@ Pandoc class >> luaFilters [ | filters | filters := OrderedCollection new. filters - add: 'http://mutabit.com/repos.fossil/dataweek/doc/tip/Artefactos/Scripts/links.lua' + add: 'http://mutabit.com/repos.fossil/dataweek/doc/tip/Artefactos/Scripts/image-links.lua'. + ^ filters ]