From 57ae88b304193dc17b57a59e943b821f13e190bd Mon Sep 17 00:00:00 2001 From: Gloria Meneses Date: Sat, 26 Aug 2017 20:43:40 +0000 Subject: [PATCH] htmlToMarkdownSubtree functionality added. --- .../Grafoscopio/GrafoscopioNode.class.st | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/repository/Grafoscopio/GrafoscopioNode.class.st b/repository/Grafoscopio/GrafoscopioNode.class.st index 2c53f42..09ef202 100644 --- a/repository/Grafoscopio/GrafoscopioNode.class.st +++ b/repository/Grafoscopio/GrafoscopioNode.class.st @@ -190,7 +190,7 @@ GrafoscopioNode >> becomeDefaultTestTree [ header: 'Arbol principal'. node1 := self class new header: 'Markup'; - body: 'I am just a node with markup'; + body: 'I am just a node with markup'; tagAs: 'text'; links: 'temp.md'; level: 1. @@ -199,18 +199,18 @@ GrafoscopioNode >> becomeDefaultTestTree [ tagAs: 'código'; body: '(ConfigurationOfGrafoscopio>>#version14:) sourceCode'. node3 := self class new - header: 'Child'; + header: '%invisible'; tagAs: 'text'; - body: 'Just testing'. + body: 'Just testing'. node1 addNode: node3. node4 := self class new header: 'Something'; tagAs: 'text'; - body: 'else'. + body: '

else

'. node1 addNode: node4. + node1 addNode: node2. self - addNode: node1; - addNode: node2. + addNode: node1. ] { #category : #initialization } @@ -502,16 +502,29 @@ GrafoscopioNode >> headers [ ^ headers := self children collect: [:currentNode | currentNode header ] ] -{ #category : #'as yet unclassified' } +{ #category : #operation } GrafoscopioNode >> htmlToMarkdown [ "I convert the node body from HTML format to Pandoc's Markdown." | htmlFile | + + (self isTaggedAs: 'código' ) ifTrue: [ ^self ]. + ((self headerStartsWith: '%invisible') or:[self hasAncestorHeaderWith: '%invisible']) + ifTrue: [ ^self ]. + htmlFile := FileLocator temp asFileReference / 'body.html'. htmlFile ensureDelete. htmlFile ensureCreateFile. htmlFile writeStreamDo: [:stream | stream nextPutAll: self body]. + self body: (PipeableOSProcess command: 'pandoc -f html -t markdown --atx-headers ', htmlFile fullName) output. - "htmlFile ensureDelete." + htmlFile ensureDelete. + +] + +{ #category : #operation } +GrafoscopioNode >> htmlToMarkdownSubtree [ + "I convert self and childern nodes body from HTML format to Pandoc's Markdown." + self preorderTraversal do: [ :each | each htmlToMarkdown ] ] { #category : #accessing }