Improving %embed nodes. Still it is an obfuscate code, that should be modularized and improved,

but it seems working as a temporal solution.
This commit is contained in:
Offray Vladimir Luna Cárdenas 2017-02-14 16:20:52 +00:00
parent b289c02708
commit 7f53ac841e

View File

@ -255,6 +255,18 @@ GrafoscopioNode >> body: anObject [
body := anObject body := anObject
] ]
{ #category : #exporting }
GrafoscopioNode >> bodyAsCode [
"I return the node body with proper decorators added to show them as raw code"
| codeBody |
codeBody := '' writeStream.
codeBody
nextPutAll: ('~~~'); lf;
nextPutAll: (self body contents asString withInternetLineEndings); lf;
nextPutAll: ('~~~'); lf.
^codeBody contents
]
{ #category : #accessing } { #category : #accessing }
GrafoscopioNode >> children [ GrafoscopioNode >> children [
"Returns the receivers list of children" "Returns the receivers list of children"
@ -419,6 +431,11 @@ GrafoscopioNode >> header: anObject [
header := anObject header := anObject
] ]
{ #category : #exporting }
GrafoscopioNode >> headerStartsWith: aString [
^ (self header findString: aString) = 1
]
{ #category : #accessing } { #category : #accessing }
GrafoscopioNode >> headers [ GrafoscopioNode >> headers [
"I returns the headers of the receiver children" "I returns the headers of the receiver children"
@ -526,47 +543,46 @@ GrafoscopioNode >> margins [
GrafoscopioNode >> markdownContent [ GrafoscopioNode >> markdownContent [
"Extracts the markdown of a node using body as content, header as title and level as hierarchical level of the title. "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" If special nodes types are present, converts them into proper markup to be embedded inside markdown"
| markdown embedNodes temporalBody invisibleChildren | | markdown embedNodes temporalBody |
markdown := '' writeStream. markdown := '' writeStream.
(self class specialWords includes: self header) not & (self class specialWords includes: self header) not &
(self class specialWords includes: ((self header findTokens: $ ) at: 1)) not & (self tags = 'código') not (self class specialWords includes: ((self header findTokens: $ ) at: 1)) not & (self tags ~= 'código') &
(self hasAncestorHeaderWith: '%invisible') not
ifTrue: [ ifTrue: [
self level timesRepeat: [ markdown nextPutAll: '#' ]. self level timesRepeat: [ markdown nextPutAll: '#' ].
markdown nextPutAll: ' '. markdown nextPutAll: ' '.
markdown nextPutAll: (self header copyReplaceTokens: #cr with: #lf); crlf; crlf. markdown nextPutAll: (self header copyReplaceTokens: #cr with: #lf); crlf; crlf.
embedNodes := self children select: [:each | ((each header findTokens: $ ) at: 1) = '%embed']. embedNodes := self children select: [:each | each headerStartsWith: '%embed'].
temporalBody := self body asString. temporalBody := self body asString.
embedNodes ifNotNil: [ embedNodes ifNotNil: [
(temporalBody includesSubstring: '%embed-all') (temporalBody includesSubstring: '%embed-all')
ifFalse: [embedNodes do: [ :each | temporalBody := temporalBody copyReplaceAll: (each header) with: each body]] ifFalse: [
embedNodes do: [ :each |
each tags = 'código'
ifFalse: [temporalBody := temporalBody copyReplaceAll: (each header) with: each body]
ifTrue: [temporalBody := temporalBody copyReplaceAll: (each header) with: each bodyAsCode]]]
ifTrue: [ ifTrue: [
embedNodes do: embedNodes do: [ :each |
[ :each | temporalBody := temporalBody copyReplaceAll: '%embed-all' with: (each body, temporalBody := temporalBody copyReplaceAll: '%embed-all' with: (each body, (String with: Character cr),
(String with: Character cr),
'%embed-all')]. '%embed-all')].
temporalBody := temporalBody copyReplaceAll: '%embed-all' with: '' temporalBody := temporalBody copyReplaceAll: '%embed-all' with: ''
] ]
]. ].
markdown nextPutAll: (temporalBody contents withInternetLineEndings ); crlf; crlf]. markdown nextPutAll: (temporalBody contents withInternetLineEndings ); crlf; crlf].
((self header findString: '%idea') = 1) (self headerStartsWith: '%idea')
ifTrue: [ ifTrue: [
embedNodes := self children select: [:each | ((each header findTokens: $ ) at: 1) = '%embed']. embedNodes := self children select: [:each | each headerStartsWith: '%embed'].
temporalBody := self body. temporalBody := self body.
embedNodes ifNotNil: [ embedNodes do: [ :each | temporalBody := temporalBody copyReplaceAll: (each header) with: each body]]. embedNodes ifNotNil: [ embedNodes do: [ :each | temporalBody := temporalBody copyReplaceAll: (each header) with: each body]].
markdown nextPutAll: (temporalBody contents withUnixLineEndings); lf; lf. markdown nextPutAll: (temporalBody contents withUnixLineEndings); lf; lf.
]. ].
((self header findString: '%footnote') = 1) (self headerStartsWith: '%footnote')
ifTrue: [ ifTrue: [
markdown nextPutAll: ('[^',(self header copyReplaceAll: '%footnote ' with: ''),']: ' ); lf. markdown nextPutAll: ('[^',(self header copyReplaceAll: '%footnote ' with: ''),']: ' ); lf.
markdown nextPutAll: (self body contents withInternetLineEndings); lf; lf. ]. markdown nextPutAll: (self body contents withInternetLineEndings); lf; lf. ].
((self header findString: '%embed') = 1) ((self tags = 'código') and: [(self hasAncestorHeaderWith: '%invisible') not & (self headerStartsWith: '%embed') not ])
ifTrue: [ ]. ifTrue: [ self exportCodeBlockTo: markdown ].
((self header findString: '%invisible') = 1) ^ markdown contents
ifTrue: [
invisibleChildren := self children.
invisibleChildren ifNotNil: [ ] ].
((self tags = 'código') and: [ (self hasAncestorHeaderWith: '%invisible') not ]) ifTrue: [ self exportCodeBlockTo: markdown ].
^markdown contents
] ]
{ #category : #accessing } { #category : #accessing }