Finally, refactoring GrafoscopioNode>>markdownContent to a pretty readable version. May be there is more refactoring to be done, but now one of the key and older algorithms was untangled. :-)
This commit is contained in:
parent
751f60c3df
commit
ad07fbe0b9
@ -267,6 +267,13 @@ GrafoscopioNode >> bodyAsCode [
|
||||
^ codeBody contents
|
||||
]
|
||||
|
||||
{ #category : #exporting }
|
||||
GrafoscopioNode >> bodyAsMarkdownInto: aStream [
|
||||
"I export the header as markdown using the level inside the tree to determine hierarchy
|
||||
and replacing all line endings to make them Internet friendly".
|
||||
self embeddedNodes ifNotNil: [ aStream nextPutAll: (self embedNodes contents withInternetLineEndings); crlf; crlf].
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
GrafoscopioNode >> children [
|
||||
"Returns the receivers list of children"
|
||||
@ -427,6 +434,16 @@ GrafoscopioNode >> flatten [
|
||||
]
|
||||
]
|
||||
|
||||
{ #category : #exporting }
|
||||
GrafoscopioNode >> footnoteAsMarkdownInto: aStream [
|
||||
"I export a node with %footnode in its header for valid Pandoc's markdown
|
||||
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.
|
||||
aStream nextPutAll: (self body contents withInternetLineEndings); lf; lf.
|
||||
|
||||
]
|
||||
|
||||
{ #category : #exporting }
|
||||
GrafoscopioNode >> hasAncestorHeaderWith: aSpecialWord [
|
||||
"Looks if the receptor node has an ancestor with a header with 'aSpecialWord' as the only or the first word"
|
||||
@ -467,6 +484,15 @@ GrafoscopioNode >> header: anObject [
|
||||
]
|
||||
|
||||
{ #category : #exporting }
|
||||
GrafoscopioNode >> headerAsMarkdownInto: aStream [
|
||||
"I export the header as markdown using the level inside the tree to determine hierarchy
|
||||
and replacing all line endings to make them Internet friendly"
|
||||
self level timesRepeat: [ aStream nextPutAll: '#' ].
|
||||
aStream nextPutAll: ' '.
|
||||
aStream nextPutAll: (self header copyReplaceTokens: #cr with: #lf); crlf; crlf.
|
||||
]
|
||||
|
||||
{ #category : #'custom markup' }
|
||||
GrafoscopioNode >> headerStartsWith: aString [
|
||||
^ (self header findString: aString) = 1
|
||||
]
|
||||
@ -576,44 +602,23 @@ GrafoscopioNode >> margins [
|
||||
|
||||
{ #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 temporalBody |
|
||||
markdown := '' writeStream.
|
||||
"I extract 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, that use %keywords in its header or body I convert them into proper markup"
|
||||
| markdownStream |
|
||||
markdownStream := '' writeStream.
|
||||
(self class specialWords includes: self header) 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.
|
||||
temporalBody := self body asString.
|
||||
self embeddedNodes ifNotNil: [
|
||||
(temporalBody includesSubstring: '%embed-all')
|
||||
ifFalse: [temporalBody := self embedNodes ]
|
||||
ifTrue: [
|
||||
self embeddedNodes 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 headerAsMarkdownInto: markdownStream.
|
||||
self bodyAsMarkdownInto: markdownStream].
|
||||
(self headerStartsWith: '%idea')
|
||||
ifTrue: [
|
||||
temporalBody := self body string.
|
||||
self embeddedNodes ifNotNil: [
|
||||
self embeddedNodes do: [ :each |
|
||||
each tags = 'código'
|
||||
ifFalse: [temporalBody := temporalBody copyReplaceAll: (each header) with: each body]
|
||||
ifTrue: [temporalBody := temporalBody copyReplaceAll: (each header) with: each bodyAsCode]]].
|
||||
markdown nextPutAll: (temporalBody contents withUnixLineEndings); lf; lf.
|
||||
].
|
||||
ifTrue: [self bodyAsMarkdownInto: markdownStream].
|
||||
(self headerStartsWith: '%footnote')
|
||||
ifTrue: [
|
||||
markdown nextPutAll: ('[^',(self header copyReplaceAll: '%footnote ' with: ''),']: ' ); lf.
|
||||
markdown nextPutAll: (self body contents withInternetLineEndings); lf; lf. ].
|
||||
ifTrue: [ self footnoteAsMarkdownInto: markdownStream ].
|
||||
((self tags = 'código') and: [(self hasAncestorHeaderWith: '%invisible') not & (self headerStartsWith: '%embed') not ])
|
||||
ifTrue: [ self exportCodeBlockTo: markdown ].
|
||||
^ markdown contents
|
||||
ifTrue: [ self exportCodeBlockTo: markdownStream ].
|
||||
^ markdownStream contents
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
|
Loading…
Reference in New Issue
Block a user