content: property pTitle : "Toggle TaskPaper ← → FoldingText"
  property pVer : "0.03"
  property pAuthor : "Rob Trew"
  
  -- DRAFT script for experimentally toggling the front document in FoldingText back and forth
  -- between Taskpaper (Project+Task) format, and FoldingText (Heading+List) format
  
  property pblnToggleTodo : true
  
  property pstrTProject : "//matches ':\\s*$'"
  property pstrHeading : "//@type=heading"
  property pstrTodoHeadings : "//@type=heading and @mode=todo"
  
  tell application "FoldingText"
  	set oDoc to front document
  	tell oDoc
  		set lstNodes to read nodes at path pstrTProject
  		if length of lstNodes > 0 then -- TASKPAPER → FOLDINGTEXT
  			-- CHANGE THE NODE TYPE TO HEADING
  			update nodes at path pstrTProject with changes {|type|:"heading"}
  			set dlm to my text item delimiters
  			repeat with oNode in lstNodes
  				set {strID, lngLevel} to {|id|, level} of oNode
  				
  				-- REMOVE THE COLON
  				set my text item delimiters to ":"
  				set lstText to text items of |text| of oNode
  				set my text item delimiters to ""
  				set strText to (items 1 thru -2 of lstText) as string
  				if pblnToggleTodo then set strText to strText & ".todo"
  				update nodes at path "//@id=" & strID with changes {|text|:strText}
  				
  				-- INDENT CHILDREN WITH ONE LESS TAB THAN THE HASH COUNT (MOVING THEIR SUB-TREES WITH THEM)
  				my SetChildIndent(oDoc, strID, lngLevel)
  			end repeat
  			set my text item delimiters to dlm
  		else -- FOLDINGTEXT → TASKPAPER
  			set lstNodes to read nodes at path pstrHeading
  			repeat with oNode in (read nodes at path pstrHeading)
  				set {strID, lngLevel, strText} to {|id|, level, |text|} of oNode
  				
  				-- ADD THE COLON
  				update nodes at path "//@id=" & strID with changes {|text|:strText & ":"}
  				
  				-- INDENT CHILDREN ONE LEVEL DEEPER THAN THE PARENT (MOVING THEIR SUB-TREES WITH THEM)
  				my SetChildIndent(oDoc, strID, lngLevel + 1)
  			end repeat
  			
  			-- REMOVE THE LEADING HASH CHARACTERS
  			if pblnToggleTodo then update nodes at path pstrTodoHeadings with changes {mode:""}
  			update nodes at path pstrHeading with changes {|type|:"body"}
  		end if
  	end tell
  end tell
  
  -- SET LEVEL OF CHILDREN (MOVING THEIR SUB-TREES WITH THEM)
  on SetChildIndent(oDoc, strID, lngLevel)
  	tell application "FoldingText"
  		tell oDoc
  			repeat with oChild in read nodes at path "//@id=" & strID & "/@type!=empty"
  				set lngDelta to (lngLevel - (level of oChild))
  				if lngDelta ≠ 0 then
  					repeat with oSub in (read nodes at path "//@id=" & |id| of oChild & "/descendant-or-self::@type!=empty")
  						update nodes at path "//@id=" & (|id| of oSub) with changes {level:((level of oSub) + lngDelta)}
  					end repeat
  				end if
  			end repeat
  		end tell
  	end tell
  end SetChildIndent
  
  