From c03e827e50e7ce5456e93cede1217a7cc9c91db7 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Thu, 20 Apr 2017 17:39:48 +0000 Subject: [PATCH] Fixing preliminary support for outputs of code nodes inside the notebook. For the moment output is not stored in the notebook also, just invoked on demand using a %keyword. --- .../Grafoscopio/GrafoscopioNode.class.st | 31 ++++++++++++++++--- .../Grafoscopio/GrafoscopioNotebook.class.st | 7 +++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/repository/Grafoscopio/GrafoscopioNode.class.st b/repository/Grafoscopio/GrafoscopioNode.class.st index 1560e8e..e371cea 100644 --- a/repository/Grafoscopio/GrafoscopioNode.class.st +++ b/repository/Grafoscopio/GrafoscopioNode.class.st @@ -380,7 +380,26 @@ GrafoscopioNode >> exportCodeBlockTo: aStream [ ] { #category : #exporting } -GrafoscopioNode >> exportDecoratedCodeBlockTo: aStream [ +GrafoscopioNode >> exportCodeNodeTo: aStream [ + "I convert the content of a node taged as 'código' (code) as pandoc markdown and put it + into aStream." + (self headerStartsWith: '%output') + ifTrue: [ self exportCodeOutputTo: aStream ] + ifFalse: [ self exportCodeBlockTo: aStream ] +] + +{ #category : #exporting } +GrafoscopioNode >> exportCodeOutputTo: aStream [ + "I convert the output of a node taged as 'código' (code) as pandoc markdown and put it + into aStream." + aStream nextPutAll: ('~~~{.numberLines}'); lf. + aStream nextPutAll: ((Compiler evaluate: self body) asString withInternetLineEndings); lf. + aStream nextPutAll: ('~~~'); lf;lf. + ^aStream contents +] + +{ #category : #exporting } +GrafoscopioNode >> exportLaTeXCodeBlockTo: aStream [ "I convert the content of a node taged as 'código' (code) as pandoc markdown and put it into aStream. The code block is decorated with LaTeX commands for proper syntax highlighting using pygments. @@ -421,7 +440,8 @@ GrafoscopioNode >> footnoteAsMarkdownInto: aStream [ and replace all line endings to make them Internet friendly. Maybe I should include the condition about my own header, instead of leaving it to markdownCotent..." aStream nextPutAll: ('[^',(self header copyReplaceAll: '%footnote ' with: ''),']: ' ); lf. - self body contents withInternetLineEndings linesDo: [ :line | aStream nextPutAll: ' ', line; lf ]. + self body contents withInternetLineEndings + linesDo: [ :line | aStream nextPutAll: ' ', line; lf ]. aStream nextPutAll: String lf. ] @@ -611,7 +631,7 @@ GrafoscopioNode >> markdownContent [ (self headerStartsWith: '%footnote') ifTrue: [ self footnoteAsMarkdownInto: markdownStream ]. ((self tags = 'código') and: [(self hasAncestorHeaderWith: '%invisible') not & (self headerStartsWith: '%embed') not ]) - ifTrue: [ self exportCodeBlockTo: markdownStream ]. + ifTrue: [ self exportCodeNodeTo: markdownStream ]. ^ markdownStream contents ] @@ -702,10 +722,11 @@ GrafoscopioNode >> preorderTraversal [ ^ nodesInPreorder. ] -{ #category : #'as yet unclassified' } +{ #category : #accessing } GrafoscopioNode >> processOutput [ (self headerStartsWith: '%output') - ifTrue: [ self output: (Compiler evaluate: self body) ] + ifFalse: [ ^ self ]. + ^ self output: (Compiler evaluate: self body) ] { #category : #movement } diff --git a/repository/Grafoscopio/GrafoscopioNotebook.class.st b/repository/Grafoscopio/GrafoscopioNotebook.class.st index b0a0991..ab572e3 100644 --- a/repository/Grafoscopio/GrafoscopioNotebook.class.st +++ b/repository/Grafoscopio/GrafoscopioNotebook.class.st @@ -64,9 +64,9 @@ GrafoscopioNotebook >> autoSaveBodyOf: aNode [ playground := body body glmPres. playground onChangeOfPort: #text - act: [ :x | aNode body: x entity value content ]; + act: [ :x | aNode body: x entity value content ]"; onChangeOfPort: #activePresentation - act: [ aNode output: aNode processOutput ] + act: [ aNode output: aNode processOutput ]" ] { #category : #accessing } @@ -173,7 +173,8 @@ GrafoscopioNotebook >> exportNode: aGrafoscopioNode asMarkdownIn: aFile [ aFile exists ifTrue: [ aFile delete ]. aFile ensureCreateFile; - writeStreamDo: [:stream | stream nextPutAll: aGrafoscopioNode asMarkdown] + writeStreamDo: [:stream | stream nextPutAll: aGrafoscopioNode asMarkdown]. + self inform: 'Exported as: ', String cr, aFile fullName ] { #category : #api }