xmindoc 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +1 -0
- data/bin/xmindoc +5 -0
- data/lib/xmindoc.rb +164 -0
- data/lib/xmindoc/content.xsl +158 -0
- data/lib/xmindoc/exporter.rb +83 -0
- data/lib/xmindoc/parser.rb +60 -0
- data/lib/xmindoc/version.rb +3 -0
- data/samples/test1.md +32 -0
- data/samples/test1.org +38 -0
- data/samples/test1.png +0 -0
- data/samples/test1.xmind +0 -0
- data/samples/test2.md +44 -0
- data/samples/test2.org +51 -0
- data/samples/test2.png +0 -0
- data/samples/test2.xmind +0 -0
- data/xmindoc.gemspec +26 -0
- metadata +111 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Yuki Fujiwara
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Xmindoc
|
2
|
+
|
3
|
+
Exports XMind Mindmap to any documents with Pandoc.
|
4
|
+
|
5
|
+
Copyright (c) 2013 Yuki Fujiwara \<sky.y.0079@gmail.com\>
|
6
|
+
|
7
|
+
|
8
|
+
* XMind (English): <http://www.xmind.net/>
|
9
|
+
* XMind (Japanese): <http://jp.xmind.net/>
|
10
|
+
|
11
|
+
|
12
|
+
## Requirement
|
13
|
+
* Ruby 1.9.3 or above
|
14
|
+
* Pandoc 1.9.4.2 or above
|
15
|
+
* See installation: <http://johnmacfarlane.net/pandoc/installing.html>
|
16
|
+
* You can choose either:
|
17
|
+
* cabal install (with Haskell Platform, I prefer personally) or
|
18
|
+
* Pandoc Package Installer (without Haskell Platform)
|
19
|
+
|
20
|
+
|
21
|
+
## Install
|
22
|
+
### libiconv
|
23
|
+
#### Mac (Homebrew)
|
24
|
+
|
25
|
+
$ brew tap homebrew/dupes
|
26
|
+
$ brew install libiconv
|
27
|
+
$ brew link --force libiconv
|
28
|
+
|
29
|
+
#### Linux
|
30
|
+
|
31
|
+
$ wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
|
32
|
+
$ tar zxvf libiconv-1.14.tar.gz
|
33
|
+
$ cd libiconv-1.14
|
34
|
+
$ ./configure
|
35
|
+
$ make
|
36
|
+
$ su -
|
37
|
+
# make install
|
38
|
+
|
39
|
+
### Xmindoc
|
40
|
+
$ gem install xmindoc
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
Usage: xmindoc [options] input.xmind
|
45
|
+
-o, --output FILE Output Filename
|
46
|
+
-t, --to=FORMAT Output formats: markdown, org, html, latex, rst, ...
|
47
|
+
-w, --write=FORMAT Output formats: markdown, org, html, latex, rst, ...
|
48
|
+
--pandoc-options=OPTIONS Pandoc options (Use double quotes like "--atx-headers")
|
49
|
+
-h, --help Display this screen
|
50
|
+
|
51
|
+
* For detail of formats and Pandoc options: See [Pandoc User's Guide](http://johnmacfarlane.net/pandoc/README.html)
|
52
|
+
|
53
|
+
|
54
|
+
## Examples
|
55
|
+
Sample files are in `samples/` directory.
|
56
|
+
|
57
|
+
### Example 1 (Japanese: 寿限無)
|
58
|
+
xmindoc -t markdown -o test1.md samples/test1.xmind --pandoc-options="--atx-headers"
|
59
|
+
|
60
|
+
* It makes a file "test1.md" as in Markdown (ATX-headered) style.
|
61
|
+
|
62
|
+
#### Example files
|
63
|
+
|
64
|
+
* Original XMind file: test1.xmind (test1.png as image)
|
65
|
+
* Sample Result (Org File): test1.org
|
66
|
+
* Sample Result (Markdown File): test1.md
|
67
|
+
* "--atx-headers": use `#` and `##` as `<h1>` and `<h2>` header output
|
68
|
+
|
69
|
+
|
70
|
+
### Example 2 (English: Lorem Ipsum)
|
71
|
+
xmindoc -t org -o test2.org samples/test2.xmind
|
72
|
+
|
73
|
+
* It makes a file "test2.org" in Org style.
|
74
|
+
|
75
|
+
#### Example files
|
76
|
+
|
77
|
+
* Original XMind file: test2.xmind (test2.png as image)
|
78
|
+
* Result (Org File): test2.org
|
79
|
+
* Result (Markdown File): test2.md
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/xmindoc
ADDED
data/lib/xmindoc.rb
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "xmindoc/version"
|
3
|
+
|
4
|
+
require "optparse"
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
# my libraries
|
8
|
+
require "xmindoc/exporter"
|
9
|
+
require "xmindoc/parser"
|
10
|
+
|
11
|
+
|
12
|
+
module Xmindoc
|
13
|
+
DEBUG = false
|
14
|
+
|
15
|
+
class Core
|
16
|
+
attr_reader :result
|
17
|
+
|
18
|
+
def initialize(option)
|
19
|
+
@option = option
|
20
|
+
@parser = Parser.new(option[:file_input])
|
21
|
+
@exporter = Exporter.new(option)
|
22
|
+
@result = ""
|
23
|
+
end
|
24
|
+
|
25
|
+
# Parse and transform: XML -> HTML
|
26
|
+
def xml_to_html()
|
27
|
+
@parser.parse()
|
28
|
+
@exporter.html = @parser.html_output
|
29
|
+
return @exporter.html
|
30
|
+
end
|
31
|
+
|
32
|
+
# Export with Pandoc: HTML -> Markdown, Org, ...
|
33
|
+
def html_to_pandoc()
|
34
|
+
@exporter.export()
|
35
|
+
@result = @exporter.result
|
36
|
+
return @result
|
37
|
+
end
|
38
|
+
|
39
|
+
# Convert and process XML with Pandoc at once
|
40
|
+
def convert()
|
41
|
+
xml_to_html()
|
42
|
+
html_to_pandoc()
|
43
|
+
|
44
|
+
|
45
|
+
if @option[:file_output] == ""
|
46
|
+
# Without -o option
|
47
|
+
puts @result
|
48
|
+
else
|
49
|
+
# Using option: -o filename
|
50
|
+
File.open(@option[:file_output],"w") do |f|
|
51
|
+
f.write(@result)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
return @result
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Command
|
60
|
+
attr_reader :option, :argv
|
61
|
+
|
62
|
+
def initialize(argv)
|
63
|
+
@argv = argv
|
64
|
+
@option = { }
|
65
|
+
@option[:format_from] = 'html' # fixed
|
66
|
+
@option[:format_to] = 'markdown' # default
|
67
|
+
@option[:file_input] = '' # XMind file (.xmind)
|
68
|
+
@option[:file_output] = '' # [option]
|
69
|
+
end
|
70
|
+
|
71
|
+
# Parse command line options
|
72
|
+
def parse()
|
73
|
+
# Option Parser of optparse
|
74
|
+
opt = OptionParser.new
|
75
|
+
script_name = File.basename($0)
|
76
|
+
opt.banner = "Usage: #{script_name} [options] input.xmind"
|
77
|
+
|
78
|
+
#
|
79
|
+
# Option Settings
|
80
|
+
#
|
81
|
+
|
82
|
+
# Output
|
83
|
+
opt.on('-o FILE','--output FILE','Output Filename') {|v| @option[:file_output] = v }
|
84
|
+
|
85
|
+
# Format(Output)
|
86
|
+
output_formats_short = %w(markdown org html latex rst plain)
|
87
|
+
output_formats_long = %w(native json html html5 html+lhs html5+lhs s5 slidy slideous dzslides docbook opendocument latex latex+lhs beamer beamer+lhs context texinfo man markdown markdown+lhs plain rst rst+lhs mediawiki textile rtf org asciidoc odt docx epub)
|
88
|
+
str_output_formats = "Output formats: " + output_formats_short.join(', ') + ", ... \n\t\t\t\t\t(for other formats: see \"pandoc --help\")"
|
89
|
+
|
90
|
+
opt.on('-t FORMAT','--to=FORMAT',str_output_formats) {|v| @option[:format_to] = v }
|
91
|
+
opt.on('-w FORMAT','--write=FORMAT',str_output_formats) {|v| @option[:format_to] = v }
|
92
|
+
|
93
|
+
# Other options for Pandoc
|
94
|
+
str_pandoc_options = "Pandoc options (Use double quotes like \"--atx-headers\")\n\t\t\t\t\t(for other options: see \"pandoc --help\")"
|
95
|
+
opt.on('--pandoc-options=OPTIONS',str_pandoc_options) {|v| @option[:pandoc_options] = v }
|
96
|
+
|
97
|
+
# Help
|
98
|
+
opt.on( '-h', '--help', 'Display this screen' ) do
|
99
|
+
puts opt
|
100
|
+
exit
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
# Do parsing
|
105
|
+
begin
|
106
|
+
pp @argv if DEBUG
|
107
|
+
opt.permute!(@argv)
|
108
|
+
rescue => e
|
109
|
+
# Catch exception when an option is wrong
|
110
|
+
puts opt
|
111
|
+
abort(e)
|
112
|
+
end
|
113
|
+
|
114
|
+
## Check whether ARGV is null
|
115
|
+
if @argv.length == 0
|
116
|
+
# Show help
|
117
|
+
puts opt
|
118
|
+
exit
|
119
|
+
end
|
120
|
+
|
121
|
+
print "argv: " if DEBUG
|
122
|
+
pp @argv if DEBUG
|
123
|
+
|
124
|
+
@option[:file_input] = @argv.pop
|
125
|
+
|
126
|
+
## Check whether the filename ends with ".xmind"
|
127
|
+
if not (@option[:file_input] =~ /^.*\.xmind$/)
|
128
|
+
puts opt
|
129
|
+
abort("ERROR: filename should end with \".xmind\"")
|
130
|
+
end
|
131
|
+
|
132
|
+
# Check format
|
133
|
+
if not output_formats_long.include?(@option[:format_to])
|
134
|
+
puts opt
|
135
|
+
abort("ERROR: wrong output format: "+ @option[:format_to])
|
136
|
+
end
|
137
|
+
|
138
|
+
end # def parse()
|
139
|
+
end
|
140
|
+
|
141
|
+
class Exec
|
142
|
+
def initialize(argv)
|
143
|
+
@argv = argv
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.run(argv)
|
147
|
+
new(argv).execute
|
148
|
+
end
|
149
|
+
|
150
|
+
def execute
|
151
|
+
command = Xmindoc::Command.new(@argv)
|
152
|
+
command.parse()
|
153
|
+
|
154
|
+
core = Xmindoc::Core.new(command.option)
|
155
|
+
core.convert()
|
156
|
+
|
157
|
+
# (debug) Confirm options
|
158
|
+
if Xmindoc::DEBUG
|
159
|
+
print 'option: '
|
160
|
+
pp command.option
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
|
3
|
+
<xsl:stylesheet
|
4
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
5
|
+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
6
|
+
xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs"
|
7
|
+
xmlns:xmind="urn:xmind:xmap:xmlns:content:2.0"
|
8
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
9
|
+
version="2.0">
|
10
|
+
|
11
|
+
<xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="no" indent="yes"
|
12
|
+
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
|
13
|
+
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
|
14
|
+
/>
|
15
|
+
|
16
|
+
|
17
|
+
<!-- Named Templates -->
|
18
|
+
<xsl:template name="double_blank">
|
19
|
+
<xsl:text>
|
20
|
+
</xsl:text>
|
21
|
+
</xsl:template>
|
22
|
+
|
23
|
+
<xsl:template name="output">
|
24
|
+
<xsl:choose>
|
25
|
+
<xsl:when test="@xlink:href">
|
26
|
+
<a>
|
27
|
+
<xsl:attribute name="href">
|
28
|
+
<xsl:value-of select="@xlink:href"/>
|
29
|
+
</xsl:attribute>
|
30
|
+
<xsl:value-of select="xmind:title"/>
|
31
|
+
</a>
|
32
|
+
</xsl:when>
|
33
|
+
<xsl:otherwise>
|
34
|
+
<xsl:value-of select="xmind:title"/>
|
35
|
+
</xsl:otherwise>
|
36
|
+
</xsl:choose>
|
37
|
+
|
38
|
+
|
39
|
+
<xsl:if test="@xlink:href">
|
40
|
+
|
41
|
+
|
42
|
+
</xsl:if>
|
43
|
+
</xsl:template>
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
<!-- Templates -->
|
48
|
+
|
49
|
+
<!-- Surpress unnecessarry strings -->
|
50
|
+
<xsl:template match="xmind:title" xmlns:ns1="urn:xmind:xmap:xmlns:content:2.0"></xsl:template>
|
51
|
+
|
52
|
+
<xsl:template match="xmind:xmap-content" xmlns:ns1="urn:xmind:xmap:xmlns:content:2.0">
|
53
|
+
<html>
|
54
|
+
<head>
|
55
|
+
<title>
|
56
|
+
<xsl:value-of select="xmind:sheet/xmind:topic/xmind:title"/>
|
57
|
+
</title>
|
58
|
+
</head>
|
59
|
+
|
60
|
+
<body>
|
61
|
+
<xsl:for-each select="xmind:sheet">
|
62
|
+
<h1>
|
63
|
+
<xsl:value-of select="xmind:topic/xmind:title"/>
|
64
|
+
</h1>
|
65
|
+
<!-- <xsl:apply-templates select="$map_h2"/> -->
|
66
|
+
<xsl:apply-templates/>
|
67
|
+
</xsl:for-each>
|
68
|
+
|
69
|
+
<xsl:call-template name="double_blank"/>
|
70
|
+
</body>
|
71
|
+
</html>
|
72
|
+
</xsl:template>
|
73
|
+
|
74
|
+
|
75
|
+
<!-- h2 -->
|
76
|
+
<xsl:template match="//xmind:topics[count(ancestor-or-self::xmind:topics)=1]" xmlns:ns1="urn:xmind:xmap:xmlns:content:2.0">
|
77
|
+
<!-- <xsl:template match="//xmind:topics" xmlns:ns1="urn:xmind:xmap:xmlns:content:2.0">-->
|
78
|
+
<xsl:for-each select="xmind:topic">
|
79
|
+
<xsl:call-template name="double_blank"/>
|
80
|
+
<xsl:call-template name="double_blank"/>
|
81
|
+
<h2>
|
82
|
+
<xsl:call-template name="output"></xsl:call-template>
|
83
|
+
</h2>
|
84
|
+
<xsl:apply-templates/>
|
85
|
+
</xsl:for-each>
|
86
|
+
</xsl:template>
|
87
|
+
|
88
|
+
<!-- h3 -->
|
89
|
+
<xsl:template match="//xmind:topics[count(ancestor-or-self::xmind:topics)=2]" xmlns:ns1="urn:xmind:xmap:xmlns:content:2.0">
|
90
|
+
<xsl:for-each select="xmind:topic">
|
91
|
+
<!-- <xsl:call-template name="double_blank"/>-->
|
92
|
+
<h3>
|
93
|
+
<xsl:call-template name="output"></xsl:call-template>
|
94
|
+
</h3>
|
95
|
+
<xsl:apply-templates/>
|
96
|
+
</xsl:for-each>
|
97
|
+
</xsl:template>
|
98
|
+
|
99
|
+
<!-- h4 -->
|
100
|
+
<xsl:template match="//xmind:topics[count(ancestor-or-self::xmind:topics)=3]" xmlns:ns1="urn:xmind:xmap:xmlns:content:2.0">
|
101
|
+
<xsl:for-each select="xmind:topic">
|
102
|
+
<!-- <xsl:call-template name="double_blank"/>-->
|
103
|
+
<h4>
|
104
|
+
<xsl:call-template name="output"></xsl:call-template>
|
105
|
+
</h4>
|
106
|
+
<xsl:apply-templates/>
|
107
|
+
</xsl:for-each>
|
108
|
+
</xsl:template>
|
109
|
+
|
110
|
+
<!-- h5 -->
|
111
|
+
<xsl:template match="//xmind:topics[count(ancestor-or-self::xmind:topics)=4]" xmlns:ns1="urn:xmind:xmap:xmlns:content:2.0">
|
112
|
+
<xsl:for-each select="xmind:topic">
|
113
|
+
<!-- <xsl:call-template name="double_blank"/>-->
|
114
|
+
<h5>
|
115
|
+
<xsl:call-template name="output"></xsl:call-template>
|
116
|
+
</h5>
|
117
|
+
<xsl:apply-templates/>
|
118
|
+
</xsl:for-each>
|
119
|
+
</xsl:template>
|
120
|
+
|
121
|
+
<!-- h6 -->
|
122
|
+
<xsl:template match="//xmind:topics[count(ancestor-or-self::xmind:topics)=5]" xmlns:ns1="urn:xmind:xmap:xmlns:content:2.0">
|
123
|
+
<xsl:for-each select="xmind:topic">
|
124
|
+
<!-- <xsl:call-template name="double_blank"/>-->
|
125
|
+
<h6>
|
126
|
+
<xsl:call-template name="output"></xsl:call-template>
|
127
|
+
</h6>
|
128
|
+
<xsl:apply-templates/>
|
129
|
+
</xsl:for-each>
|
130
|
+
</xsl:template>
|
131
|
+
|
132
|
+
<!-- list: ul -->
|
133
|
+
<xsl:template match="//xmind:topics[count(ancestor-or-self::xmind:topics)>=6]" xmlns:ns1="urn:xmind:xmap:xmlns:content:2.0">
|
134
|
+
<ul>
|
135
|
+
<xsl:for-each select="xmind:topic">
|
136
|
+
<!-- <xsl:call-template name="double_blank"/>-->
|
137
|
+
<li>
|
138
|
+
<xsl:call-template name="output"></xsl:call-template>
|
139
|
+
<xsl:apply-templates/>
|
140
|
+
</li>
|
141
|
+
</xsl:for-each>
|
142
|
+
</ul>
|
143
|
+
</xsl:template>
|
144
|
+
|
145
|
+
|
146
|
+
<!-- tmp -->
|
147
|
+
<!-- <xsl:template match="//xmind:topics" xmlns:ns1="urn:xmind:xmap:xmlns:content:2.0">
|
148
|
+
<xsl:call-template name="double_blank"/> count(ancestor-or-self::xmind:topics) = <xsl:value-of
|
149
|
+
select="count(ancestor-or-self::xmind:topics)"/>
|
150
|
+
<xsl:call-template name="double_blank"/>
|
151
|
+
<xsl:for-each select="xmind:topic">
|
152
|
+
<h2>
|
153
|
+
<xsl:call-template name="output"></xsl:call-template>
|
154
|
+
</h2> <xsl:apply-templates/> </xsl:for-each>
|
155
|
+
</xsl:template>-->
|
156
|
+
|
157
|
+
|
158
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
require 'pp'
|
5
|
+
require 'open3'
|
6
|
+
|
7
|
+
module Xmindoc
|
8
|
+
|
9
|
+
# Export a HTML to any filetypes with Pandoc
|
10
|
+
# Original Source: pandoc-ruby
|
11
|
+
# https://github.com/alphabetum/pandoc-ruby/blob/master/lib/pandoc-ruby.rb
|
12
|
+
class Exporter
|
13
|
+
attr_reader :result
|
14
|
+
attr_accessor :html
|
15
|
+
|
16
|
+
@@bin_path = nil
|
17
|
+
|
18
|
+
EXECUTABLES = %W[
|
19
|
+
pandoc
|
20
|
+
markdown2pdf
|
21
|
+
html2markdown
|
22
|
+
hsmarkdown
|
23
|
+
]
|
24
|
+
|
25
|
+
def self.bin_path=(path)
|
26
|
+
@@bin_path = path
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(option, html='')
|
30
|
+
@html = html
|
31
|
+
@option = option
|
32
|
+
@result = ''
|
33
|
+
@executable = 'pandoc'
|
34
|
+
print @target
|
35
|
+
end
|
36
|
+
|
37
|
+
def export()
|
38
|
+
@target = @html
|
39
|
+
executable = @@bin_path ? File.join(@@bin_path, @executable) : @executable
|
40
|
+
options = "--standalone --from #{@option[:format_from]} --to #{@option[:format_to]} #{@option[:pandoc_options]}"
|
41
|
+
command = executable + " " + options
|
42
|
+
puts command if DEBUG
|
43
|
+
@result = execute(command)
|
44
|
+
|
45
|
+
# @converter = PandocRuby.new(@html,
|
46
|
+
# :standalone,
|
47
|
+
# :from => @option[:format_from],
|
48
|
+
# :to => @option[:format_to])
|
49
|
+
# @result = @converter.convert
|
50
|
+
|
51
|
+
return @result
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def execute(command)
|
56
|
+
output = ''
|
57
|
+
Open3::popen3(command) do |stdin, stdout, stderr|
|
58
|
+
stdin.puts @target
|
59
|
+
stdin.close
|
60
|
+
output = stdout.read.strip
|
61
|
+
end
|
62
|
+
output
|
63
|
+
end
|
64
|
+
|
65
|
+
end # class Exporter
|
66
|
+
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
# ## main
|
71
|
+
# if __FILE__ == $PROGRAM_NAME
|
72
|
+
# option = { }
|
73
|
+
# option[:format_from] = 'html' # fixed
|
74
|
+
# option[:format_to] = 'markdown' # default
|
75
|
+
|
76
|
+
# File.open("data/12.07.16_MOrgDown_idea/content.html") do |f|
|
77
|
+
# exporter = XMorgDown::Exporter.new(option, f.read)
|
78
|
+
# exporter.export()
|
79
|
+
# puts exporter.result
|
80
|
+
|
81
|
+
# end
|
82
|
+
|
83
|
+
# end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
# Add current path to load path
|
5
|
+
# https://github.com/komagata/lokka/blob/master/init.rb
|
6
|
+
$:.unshift File.dirname(__FILE__)
|
7
|
+
|
8
|
+
require 'pp'
|
9
|
+
require 'zipruby'
|
10
|
+
require 'nokogiri'
|
11
|
+
|
12
|
+
SRC_DIR = File.dirname(__FILE__)
|
13
|
+
|
14
|
+
module Xmindoc
|
15
|
+
|
16
|
+
class Parser
|
17
|
+
attr_accessor :file_xmind
|
18
|
+
attr_reader :xml_content, :html_output
|
19
|
+
CONTENT_XML_FILE = "content.xml"
|
20
|
+
XSLT_FILE = "#{SRC_DIR}/content.xsl"
|
21
|
+
|
22
|
+
def initialize(file_xmind)
|
23
|
+
Dir::chdir(".")
|
24
|
+
@file_xmind = file_xmind
|
25
|
+
@xslt = File.read(XSLT_FILE)
|
26
|
+
@nokogiri_xslt = Nokogiri::XSLT(@xslt)
|
27
|
+
@xml_content = ''
|
28
|
+
@html_output = ''
|
29
|
+
end
|
30
|
+
|
31
|
+
## Parse a XMind XML and convert it to html
|
32
|
+
def parse()
|
33
|
+
## Read XMind file as a zip file
|
34
|
+
Zip::Archive.open(@file_xmind) do |ar|
|
35
|
+
ar.fopen(CONTENT_XML_FILE) do |f|
|
36
|
+
@xml_content = f.read
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
## Parse XMind XML with Nokogiri and XSLT
|
41
|
+
nokogiri_xml = Nokogiri::XML(@xml_content)
|
42
|
+
@html_output = @nokogiri_xslt.apply_to(nokogiri_xml).to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# ## main
|
53
|
+
# if __FILE__ == $PROGRAM_NAME
|
54
|
+
# ## for test
|
55
|
+
# file_xmind = "/Users/yuki/Dropbox/Projects/app_dev/MOrgDown/data/12.07.16_MOrgDown_idea.xmind"
|
56
|
+
# parser = XMorgDown::Parser.new(file_xmind)
|
57
|
+
# parser.parse()
|
58
|
+
#
|
59
|
+
#
|
60
|
+
# end
|
data/samples/test1.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
% Test Map
|
2
|
+
%
|
3
|
+
%
|
4
|
+
|
5
|
+
# Test Map
|
6
|
+
|
7
|
+
## 寿限無
|
8
|
+
|
9
|
+
### 寿限無
|
10
|
+
|
11
|
+
#### 五劫の擦り切れ
|
12
|
+
|
13
|
+
##### 海砂利水魚の
|
14
|
+
|
15
|
+
###### 水行末
|
16
|
+
|
17
|
+
- 食う寝る処に住む処
|
18
|
+
- やぶら小路の藪柑子
|
19
|
+
- パイポ
|
20
|
+
- シューリンガンのグーリンダイ
|
21
|
+
- グーリンダイの
|
22
|
+
- ポンポコピーの
|
23
|
+
- ポンポコナーの
|
24
|
+
- 長久命の
|
25
|
+
- 長助
|
26
|
+
|
27
|
+
- パイポ
|
28
|
+
- パイポのシューリンガン
|
29
|
+
|
30
|
+
###### 雲来末
|
31
|
+
|
32
|
+
###### 風来末
|
data/samples/test1.org
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#+TITLE: Test Map
|
2
|
+
|
3
|
+
* Test Map
|
4
|
+
|
5
|
+
** 寿限無
|
6
|
+
|
7
|
+
*** 寿限無
|
8
|
+
|
9
|
+
**** 五劫の擦り切れ
|
10
|
+
|
11
|
+
***** 海砂利水魚の
|
12
|
+
|
13
|
+
****** 水行末
|
14
|
+
|
15
|
+
- 食う寝る処に住む処
|
16
|
+
|
17
|
+
- やぶら小路の藪柑子
|
18
|
+
|
19
|
+
- パイポ
|
20
|
+
|
21
|
+
- シューリンガンのグーリンダイ
|
22
|
+
|
23
|
+
- グーリンダイの
|
24
|
+
|
25
|
+
- ポンポコピーの
|
26
|
+
|
27
|
+
- ポンポコナーの
|
28
|
+
|
29
|
+
- 長久命の
|
30
|
+
|
31
|
+
- 長助
|
32
|
+
|
33
|
+
- パイポ
|
34
|
+
- パイポのシューリンガン
|
35
|
+
|
36
|
+
****** 雲来末
|
37
|
+
|
38
|
+
****** 風来末
|
data/samples/test1.png
ADDED
Binary file
|
data/samples/test1.xmind
ADDED
Binary file
|
data/samples/test2.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
% Test Map 2
|
2
|
+
%
|
3
|
+
%
|
4
|
+
|
5
|
+
# Test Map 2
|
6
|
+
|
7
|
+
## Lorem
|
8
|
+
|
9
|
+
### ipsum
|
10
|
+
|
11
|
+
#### dolor
|
12
|
+
|
13
|
+
##### sit
|
14
|
+
|
15
|
+
###### amet,
|
16
|
+
|
17
|
+
- consetetur
|
18
|
+
- sadipscing
|
19
|
+
- elitr,
|
20
|
+
|
21
|
+
## sed
|
22
|
+
|
23
|
+
### diam
|
24
|
+
|
25
|
+
#### nonumy
|
26
|
+
|
27
|
+
##### eirmod
|
28
|
+
|
29
|
+
###### tempor
|
30
|
+
|
31
|
+
- invidunt
|
32
|
+
- ut
|
33
|
+
- labore
|
34
|
+
- et
|
35
|
+
- dolore
|
36
|
+
- magna
|
37
|
+
- aliquyam
|
38
|
+
- erat,
|
39
|
+
|
40
|
+
## sed
|
41
|
+
|
42
|
+
### diam
|
43
|
+
|
44
|
+
#### voluptua.
|
data/samples/test2.org
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#+TITLE: Test Map 2
|
2
|
+
|
3
|
+
* Test Map 2
|
4
|
+
|
5
|
+
** Lorem
|
6
|
+
|
7
|
+
*** ipsum
|
8
|
+
|
9
|
+
**** dolor
|
10
|
+
|
11
|
+
***** sit
|
12
|
+
|
13
|
+
****** amet,
|
14
|
+
|
15
|
+
- consetetur
|
16
|
+
|
17
|
+
- sadipscing
|
18
|
+
|
19
|
+
- elitr,
|
20
|
+
|
21
|
+
** sed
|
22
|
+
|
23
|
+
*** diam
|
24
|
+
|
25
|
+
**** nonumy
|
26
|
+
|
27
|
+
***** eirmod
|
28
|
+
|
29
|
+
****** tempor
|
30
|
+
|
31
|
+
- invidunt
|
32
|
+
|
33
|
+
- ut
|
34
|
+
|
35
|
+
- labore
|
36
|
+
|
37
|
+
- et
|
38
|
+
|
39
|
+
- dolore
|
40
|
+
|
41
|
+
- magna
|
42
|
+
|
43
|
+
- aliquyam
|
44
|
+
|
45
|
+
- erat,
|
46
|
+
|
47
|
+
** sed
|
48
|
+
|
49
|
+
*** diam
|
50
|
+
|
51
|
+
**** voluptua.
|
data/samples/test2.png
ADDED
Binary file
|
data/samples/test2.xmind
ADDED
Binary file
|
data/xmindoc.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "xmindoc/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "xmindoc"
|
7
|
+
s.version = Xmindoc::VERSION
|
8
|
+
s.authors = ["Yuki Fujiwara"]
|
9
|
+
s.email = ["sky.y.0079@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Exports XMind Mindmap to any documents with Pandoc.}
|
12
|
+
s.description = %q{Exports XMind Mindmap to any documents with Pandoc.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "xmindoc"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "nokogiri"
|
23
|
+
s.add_development_dependency "zipruby"
|
24
|
+
s.add_runtime_dependency "nokogiri"
|
25
|
+
s.add_runtime_dependency "zipruby"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xmindoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yuki Fujiwara
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-10 00:00:00.000000000 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
requirement: &2152173840 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2152173840
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: zipruby
|
28
|
+
requirement: &2152173140 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2152173140
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: nokogiri
|
39
|
+
requirement: &2152172400 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2152172400
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: zipruby
|
50
|
+
requirement: &2152171940 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2152171940
|
59
|
+
description: Exports XMind Mindmap to any documents with Pandoc.
|
60
|
+
email:
|
61
|
+
- sky.y.0079@gmail.com
|
62
|
+
executables:
|
63
|
+
- xmindoc
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/xmindoc
|
72
|
+
- lib/xmindoc.rb
|
73
|
+
- lib/xmindoc/content.xsl
|
74
|
+
- lib/xmindoc/exporter.rb
|
75
|
+
- lib/xmindoc/parser.rb
|
76
|
+
- lib/xmindoc/version.rb
|
77
|
+
- samples/test1.md
|
78
|
+
- samples/test1.org
|
79
|
+
- samples/test1.png
|
80
|
+
- samples/test1.xmind
|
81
|
+
- samples/test2.md
|
82
|
+
- samples/test2.org
|
83
|
+
- samples/test2.png
|
84
|
+
- samples/test2.xmind
|
85
|
+
- xmindoc.gemspec
|
86
|
+
has_rdoc: true
|
87
|
+
homepage: ''
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project: xmindoc
|
107
|
+
rubygems_version: 1.6.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Exports XMind Mindmap to any documents with Pandoc.
|
111
|
+
test_files: []
|