Skip to content

Commit b55331e

Browse files
committed
v1.10 Indented Text output
1 parent 27dd57a commit b55331e

2 files changed

Lines changed: 65 additions & 3 deletions

File tree

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ To a very limited extent the format is documented [here](https://www.toketaware.
4141
* [HTML Output](#htmloutput)
4242
* [Freemind And OPML XML Output](#freemindandopmlxmloutput)
4343
* [GraphViz .dot Format](#graphviz.dotformat)
44-
* [iThoughts CSV File Format](#ithoughtscsvfileformat)
44+
* [Indented Text](#indentedtext)
45+
* [iThoughts CSV File Format](#ithoughtscsvfileformat)
4546
* [Command Files](#commandfiles)
4647
* [Test Files](#testfiles)
4748
* [iThoughts Shape Names](#ithoughtsshapenames)
@@ -470,6 +471,32 @@ You can use the dot command (part of GraphViz) to turn this into a PNG graphic:
470471

471472
In the above example the parameter `vertical` was used to align the root nodes next to each other, with descendants down the page. \ If you specify any other value, for example 'horizontal' or '.' the alignment will be horizontal. (You can use `v` for short, for `vertical`.)
472473

474+
#### Indented Text
475+
476+
You can write out the data as a text file where indentation is used to denote levels in the tree hierarchy. \
477+
Use the `indented` command to write out the text in this format. \
478+
There are numerous options for how to indent the text:
479+
480+
* Code `original` to use the same indentation characters as on input. (This will only work if you read in an indented-text file; Otherwise the indentation will be an empty string.)
481+
482+
* Code `tab` to use the tab character to indent.
483+
484+
* Code `space:n` to use n spaces for each indentation level.
485+
486+
* Code `.` as a shorthand to indent using two spaces for each level.
487+
488+
* Code any other characters to use them for indentation.
489+
490+
Here are two examples of usage:
491+
492+
filterCSV < input.csv > output.txt indented space:4
493+
494+
will write out a file where four space characters are used for each level of indentation.
495+
496+
filterCSV < input.csv > output.txt indented "--"
497+
498+
will write out a file where two dashes are used for each level of indentation.
499+
473500
### iThoughts CSV File Format
474501

475502
The CSV format that iThoughts understands has a tree-like structure, within a table. As well as the tree of nodes, colour, position, node shape and other attributes of a node can be specified in the CSV file. To a very limited extent the format is documented [here](https://www.toketaware.com/ithoughts-howto-csv). A better way to understand the format is to export a mind map from iThoughts as CSV and look at the resulting file.

filterCSV

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ import xml.etree.ElementTree as ElementTree
3434

3535
# from CSVTree import CSVTree
3636

37-
filterCSV_level = "1.9"
38-
filterCSV_date = "15 August, 2020"
37+
filterCSV_level = "1.10"
38+
filterCSV_date = "16 August, 2020"
39+
40+
inputIndentCharacters = ""
3941

4042

4143
class streamHandler:
@@ -315,6 +317,7 @@ class TreeReader:
315317
return self.ensureMandatoryColumns(csvRows) + (output,)
316318

317319
def readMarkdownOrTextTree(self, inputFile):
320+
global inputIndentCharacters
318321
output = []
319322

320323
# Build array of rows
@@ -330,6 +333,7 @@ class TreeReader:
330333

331334
# Save the indentation whitespace
332335
indentCharacters = line[0:indentLength]
336+
inputIndentCharacters = indentCharacters
333337

334338
# Print the detected indentation - so user can debug
335339
output.append(
@@ -1559,6 +1563,36 @@ class CSVTree:
15591563
for childNode in self.childNodes:
15601564
childNode.repairSubtreeLevels(parentLevel + 1)
15611565

1566+
def exportToIndentedText(self, actionsList):
1567+
indentationType = actionsList[0].lower()
1568+
if indentationType == "tab":
1569+
indentationCharacters = "\t"
1570+
if indentationType == "original":
1571+
indentationCharacters = inputIndentCharacters
1572+
elif indentationType == ".":
1573+
indentationCharacters = " "
1574+
elif indentationType.startswith("space:"):
1575+
spaceCount = int(indentationType[6:])
1576+
indentationCharacters = " " * spaceCount
1577+
else:
1578+
indentationCharacters = indentationType
1579+
1580+
return self._exportToIndentedText(indentationCharacters)
1581+
1582+
def _exportToIndentedText(self, indentationCharacters):
1583+
output = []
1584+
1585+
level = int(self.data["level"])
1586+
1587+
if level > -1:
1588+
indentationText = indentationCharacters * level
1589+
output.append(indentationText + self.data["cell"])
1590+
1591+
for childNode in self.childNodes:
1592+
output += childNode._exportToIndentedText(indentationCharacters)
1593+
1594+
return output
1595+
15621596
def exportToMarkdown(self, actionsList):
15631597
# Get the number of heading levels to allow before going to nested bulleted
15641598
# lists
@@ -2467,6 +2501,7 @@ manual.
24672501
"hspread": csvTree.doHorizontalSpread,
24682502
"html": csvTree.exportToHTML,
24692503
"markdown": csvTree.exportToMarkdown,
2504+
"indented": csvTree.exportToIndentedText,
24702505
"promote": csvTree.promoteLevel,
24712506
"stats": csvTree.writeStatistics,
24722507
"vspread": csvTree.doVerticalSpread,

0 commit comments

Comments
 (0)