From 6f9f6285d51f466df80427bfa430a7ed93fef39a Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Sat, 1 Nov 2014 17:33:47 +0000 Subject: [PATCH] First version of %embed nodes support. They allow to replace text in their parents with the content of that nodes. --- .../Grafoscopio/GrafoscopioBrowser.class.st | 4 +-- .../Grafoscopio/GrafoscopioNode.class.st | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/repository/Grafoscopio/GrafoscopioBrowser.class.st b/repository/Grafoscopio/GrafoscopioBrowser.class.st index 040cbbe..5452253 100644 --- a/repository/Grafoscopio/GrafoscopioBrowser.class.st +++ b/repository/Grafoscopio/GrafoscopioBrowser.class.st @@ -423,8 +423,8 @@ GrafoscopioBrowser >> updateSystem [ (ConfigurationOfCitezen project latestVersion: #development) load. Gofer new - smalltalkhubUser: 'Offray' project: 'Ubakye'; - package: 'Ubakye'; + smalltalkhubUser: 'Offray' project: 'Grafoscopio'; + package: 'Grafoscopio'; load. ] diff --git a/repository/Grafoscopio/GrafoscopioNode.class.st b/repository/Grafoscopio/GrafoscopioNode.class.st index 765d98b..fd1206b 100644 --- a/repository/Grafoscopio/GrafoscopioNode.class.st +++ b/repository/Grafoscopio/GrafoscopioNode.class.st @@ -80,7 +80,7 @@ GrafoscopioNode >> addNodeAfter [ ] -{ #category : #'as yet unclassified' } +{ #category : #exporting } GrafoscopioNode >> asMarkdown [ "Exports children of the curren node as pandoc markdown, using special nodes for config options and bibliography." @@ -93,7 +93,7 @@ GrafoscopioNode >> asMarkdown [ ] -{ #category : #'as yet unclassified' } +{ #category : #exporting } GrafoscopioNode >> asSton [ "Exports current tree as STON format" | stonOutput | @@ -104,7 +104,7 @@ GrafoscopioNode >> asSton [ ] -{ #category : #'as yet unclassified' } +{ #category : #initialization } GrafoscopioNode >> becomeDefaultTree [ | node1 node2 node3 | self level: 0. @@ -247,24 +247,24 @@ GrafoscopioNode >> level: anInteger [ level := anInteger ] -{ #category : #'as yet unclassified' } +{ #category : #exporting } GrafoscopioNode >> markdownContent [ "Extracts the markdown of a node using body as content, header as title and level as hierarchical level of the title. If special nodes types are present, converts them into proper markup to be embedded inside markdown" | markdown configDict specialWords embedNodes temporalBody | markdown := '' writeStream. - specialWords := #('#config' '#abstract' '#invisible' '#idea' '#footnote' 'nuevoNodo' '%embed'). + specialWords := #('%config' '%abstract' '%invisible' '%idea' '%footnote' 'nuevoNodo' '%embed'). (self level > 0) & (specialWords includes: self header) not & (specialWords includes: ((self header findTokens: $ ) at: 1)) not ifTrue: [ self level timesRepeat: [ markdown nextPutAll: '#' ]. markdown nextPutAll: ' '. markdown nextPutAll: (self header copyReplaceTokens: #cr with: #lf); lf; lf. - embedNodes := self headers select: [:each | ((each findTokens: $ ) at: 1) = '%embed']. + embedNodes := self children select: [:each | ((each header findTokens: $ ) at: 1) = '%embed']. temporalBody := self body. - embedNodes ifNotNil: [ ]. - markdown nextPutAll: (self body contents withUnixLineEndings); lf; lf]. + embedNodes ifNotNil: [ embedNodes do: [ :each | temporalBody := temporalBody copyReplaceAll: (each header) with: each body]]. + markdown nextPutAll: (temporalBody contents withUnixLineEndings); lf; lf]. - (self header = '#config') + (self header = '%config') ifTrue: [ configDict := STON fromString: (self body). markdown nextPutAll: '---'; lf. @@ -273,15 +273,19 @@ GrafoscopioNode >> markdownContent [ markdown nextPutAll: 'bibliography: ', (configDict at: 'bibliography'); lf. markdown nextPutAll: 'abstract: ', '|'; lf; nextPutAll: (configDict at: 'abstract'); lf. markdown nextPutAll: '---'; lf. ]. - ((self header findString: '#idea') = 1) - ifTrue: [markdown nextPutAll: (self body contents withInternetLineEndings); lf; lf. ]. - ((self header findString: '#footnote') = 1) + ((self header findString: '%idea') = 1) + ifTrue: ["markdown nextPutAll: (self body contents withInternetLineEndings); lf; lf." + embedNodes := self children select: [:each | ((each header findTokens: $ ) at: 1) = '%embed']. + temporalBody := self body. + embedNodes ifNotNil: [ embedNodes do: [ :each | temporalBody := temporalBody copyReplaceAll: (each header) with: each body]]. + markdown nextPutAll: (temporalBody contents withUnixLineEndings); lf; lf. + ]. + ((self header findString: '%footnote') = 1) ifTrue: [ markdown nextPutAll: ('[^',(self header copyReplaceAll: '#footnote ' with: ''),']: ' ); lf. markdown nextPutAll: (self body contents withInternetLineEndings); lf; lf. ]. ((self header findString: '%embed') = 1) - ifTrue: "[markdown nextPutAll: (self body contents withInternetLineEndings); lf; lf. ]." - [markdown nextPutAll: (((self parent body) copyReplaceAll: (self header) with: (self body)) contents withInternetLineEndings); lf; lf. ]. + ifTrue: [ ]. ^markdown contents ]