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 committed by SantiagoBragagnolo
parent 8537f8890a
commit 04253b70d5
1 changed files with 35 additions and 19 deletions

View File

@ -255,6 +255,18 @@ GrafoscopioNode >> 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 }
GrafoscopioNode >> children [
"Returns the receivers list of children"
@ -419,6 +431,11 @@ GrafoscopioNode >> header: anObject [
header := anObject
]
{ #category : #exporting }
GrafoscopioNode >> headerStartsWith: aString [
^ (self header findString: aString) = 1
]
{ #category : #accessing }
GrafoscopioNode >> headers [
"I returns the headers of the receiver children"
@ -526,47 +543,46 @@ GrafoscopioNode >> margins [
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 embedNodes temporalBody invisibleChildren |
| markdown embedNodes temporalBody |
markdown := '' writeStream.
(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: [
self level timesRepeat: [ markdown nextPutAll: '#' ].
markdown nextPutAll: ' '.
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.
embedNodes ifNotNil: [
(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: [
embedNodes do:
[ :each | temporalBody := temporalBody copyReplaceAll: '%embed-all' with: (each body,
(String with: Character cr),
embedNodes do: [ :each |
temporalBody := temporalBody copyReplaceAll: '%embed-all' with: (each body, (String with: Character cr),
'%embed-all')].
temporalBody := temporalBody copyReplaceAll: '%embed-all' with: ''
]
].
markdown nextPutAll: (temporalBody contents withInternetLineEndings ); crlf; crlf].
((self header findString: '%idea') = 1)
(self headerStartsWith: '%idea')
ifTrue: [
embedNodes := self children select: [:each | ((each header findTokens: $ ) at: 1) = '%embed'].
embedNodes := self children select: [:each | each headerStartsWith: '%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)
(self headerStartsWith: '%footnote')
ifTrue: [
markdown nextPutAll: ('[^',(self header copyReplaceAll: '%footnote ' with: ''),']: ' ); lf.
markdown nextPutAll: (self body contents withInternetLineEndings); lf; lf. ].
((self header findString: '%embed') = 1)
ifTrue: [ ].
((self header findString: '%invisible') = 1)
ifTrue: [
invisibleChildren := self children.
invisibleChildren ifNotNil: [ ] ].
((self tags = 'código') and: [ (self hasAncestorHeaderWith: '%invisible') not ]) ifTrue: [ self exportCodeBlockTo: markdown ].
^markdown contents
markdown nextPutAll: (self body contents withInternetLineEndings); lf; lf. ].
((self tags = 'código') and: [(self hasAncestorHeaderWith: '%invisible') not & (self headerStartsWith: '%embed') not ])
ifTrue: [ self exportCodeBlockTo: markdown ].
^ markdown contents
]
{ #category : #accessing }