The task was to import several hundred small HTML files into a Freemind mindmap, so that each HTML file would occupy one node for its file name afterwards, and one child node below this for its textual content.

The solution that I used prepares the content in a way that pasting it into freemind creates the desired effect. This means to use one line per node, indenting lines by two spaces relative to the preceding line in order to create a subnode, and to use full HTML documents with <html>, <head> and <body> (all in one line!) in order to create HTML nodes.

Instructions for this solution:

  1. Remove all line breaks from the source HTML files by executing these commands:
    1. cd dir-with-html-files/;
    2. for file in *; do paste –serial –delimiters=’ ‘ $file > ${file/.html/.oneline.html}; done
    3. mkdir ../dir-with-oneline-html-files/;
    4. mv *.oneline.html ../dir-with-oneline-html-files/;
  2. Concatenate all “one-line” HTML files into one:
    1. cd ../dir-with-oneline-html-files/;
    2. cat * >../FileContents.txt;
  3. Create a file containing the file names of all files you want to import:
    1. ls -x1 >../FileNames.txt
  4. Check that your file with file names and file contents have the same number of lines. If not, one of your HTML source files might not have ended in newline so that the following file was placed on the same line when concatenating. Then, you would need to correct that and re-create FileContents.txt.
  5. Edit the file with the list of filenames with Search&Replace in a text editor to make them fit as your node titles.
  6. Create a file containing file names and contents in columns, separated by a special character that is found nowhere else in the files:
    1. paste –delimiters=’ł’ FileNames.txt FileContents.txt >FileNamesAndContents.txt;
  7. Open this last file in a text editor and:
    1. [optional] Replace two spaces by one space until this is no longer possible. This eliminates unnecessary spaced which can have crept in by replacing line breaks with spaces above.
    2. Replace all special separation characters with a line break followed by two spaces each.
  8. Also with the text editor, eliminate some peculiarities that Freemind does not like:
    1. Eliminate “http-equiv=”Content-Type”” from meta tags. If you do not, the content of the whole document will not be shown in Freemind, and even the HTML source view in Freemind will show it as empty.
    2. Remove all xmlns attributes from the HTML tag. If you do not, the content of the whole document will be shown as source.
    3. Remove all <!DOCTYPE > XML processing directives. If you do not, the content of the whole document will be shown as source.
  9. Copy the content of the whole file as text from your text editor and paste it into Freemind while you have selected the desired parent node of the new content. Be sure to select the correct character encoding in your text editor first, because Freemind will insert it in the encoding you selected before copying (it seems that the character encoding is available as metadata for clipboard content).

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>