Created
February 8, 2018 04:17
-
-
Save msr1k/7d299445fbc7788287e255594f05b7eb to your computer and use it in GitHub Desktop.
Convert FreeMind's *.mm file into text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rexml/document' | |
class Mm2Txt | |
def self.convert(filename, out=STDOUT) | |
contents = File.open(filename, 'r', &:read) | |
doc = REXML::Document.new(contents) | |
Impl.traverse(0, doc.elements['//map/node'], out) | |
end | |
class Impl | |
def self.is_node_element(elem) | |
elem.class == REXML::Element && elem.name == 'node' | |
end | |
def self.traverse(depth, node, out) | |
out.write(" " * (depth * 4)) | |
out.write("#{node.attributes['TEXT'].to_s}\n") | |
node.elements.select{ |e| is_node_element(e) }.each do |e| | |
traverse(depth + 1, e, out) | |
end | |
end | |
end | |
end | |
if $0 == __FILE__ | |
def usage | |
puts "ruby mm2txt.rb target_mm_file_name" | |
exit | |
end | |
usage() if ARGV.empty? | |
Mm2Txt.convert(ARGV[0]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment