First version of %embed nodes support. They allow to replace text in their parents with the content of that nodes.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2014-11-01 17:33:47 +00:00 committed by SantiagoBragagnolo
parent fd7e42ebc7
commit 4960eacbf2
2 changed files with 20 additions and 16 deletions

View File

@ -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.
]

View File

@ -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
]