Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
67900c95
Commit
67900c95
authored
Sep 21, 2015
by
hy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加Text2Children转换方法,向text protocol中增加一个Node2Text方法
parent
23788395
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
2 deletions
+118
-2
data.js
src/core/data.js
+89
-0
text.js
src/protocol/text.js
+29
-2
No files found.
src/core/data.js
View file @
67900c95
...
@@ -99,6 +99,95 @@ define(function(require, exports, module) {
...
@@ -99,6 +99,95 @@ define(function(require, exports, module) {
return
node
;
return
node
;
},
},
/**
* function Text2Children(MinderNode, String)
* @param {MinderNode} node 要导入数据的节点
* @param {String} text 导入的text数据
* @Desc: 用于批量插入子节点,并不会修改被插入的父节点
* @Editor: Naixor
* @Date: 2015.9.21
* @example: 用于批量导入如下类型的节点
* 234
* 3456346 asadf
* 12312414
* wereww
* 12314
* 1231412
* 13123
*/
Text2Children
:
function
(
node
,
text
)
{
if
(
!
(
node
instanceof
kityminder
.
Node
))
{
return
;
// throw new Error('Json2Children::node is not a kityminder.Node type!');
};
var
children
=
[],
jsonMap
=
{},
level
=
0
;
var
LINE_SPLITTER
=
/
\r
|
\n
|
\r\n
/
,
TAB_REGEXP
=
/^
(\t
|
\x
20
{4})
/
;
var
lines
=
text
.
split
(
LINE_SPLITTER
),
line
=
''
,
jsonNode
,
i
=
0
;
var
minder
=
this
;
function
isEmpty
(
line
)
{
return
line
===
""
&&
!
/
\S
/
.
test
(
line
);
}
function
getNode
(
line
)
{
return
{
data
:
{
text
:
line
.
replace
(
/^
(\t
|
\x
20
{4})
+/
,
''
).
replace
(
/
(\t
|
\x
20
{4})
+$/
,
''
)
},
children
:
[]
}
}
function
getLevel
(
text
)
{
var
level
=
0
;
while
(
TAB_REGEXP
.
test
(
text
))
{
text
=
text
.
replace
(
TAB_REGEXP
,
''
);
level
++
;
}
return
level
;
}
function
addChild
(
parent
,
node
)
{
parent
.
children
.
push
(
node
);
}
function
importChildren
(
node
,
children
)
{
for
(
var
i
=
0
,
l
=
children
.
length
;
i
<
l
;
i
++
)
{
var
childNode
=
minder
.
createNode
(
null
,
node
);
childNode
.
setData
(
'text'
,
children
[
i
].
data
.
text
||
''
);
importChildren
(
childNode
,
children
[
i
].
children
);
}
}
while
((
line
=
lines
[
i
++
])
!==
undefined
)
{
line
=
line
.
replace
(
/ /g
,
''
);
if
(
isEmpty
(
line
))
continue
;
level
=
getLevel
(
line
);
jsonNode
=
getNode
(
line
);
if
(
level
===
0
)
{
jsonMap
=
{};
children
.
push
(
jsonNode
);
jsonMap
[
0
]
=
children
[
children
.
length
-
1
];
}
else
{
if
(
!
jsonMap
[
level
-
1
])
{
throw
new
Error
(
'Invalid local format'
);
};
addChild
(
jsonMap
[
level
-
1
],
jsonNode
);
jsonMap
[
level
]
=
jsonNode
;
}
}
importChildren
(
node
,
children
);
minder
.
refresh
();
},
/**
/**
* @method importJson()
* @method importJson()
* @for Minder
* @for Minder
...
...
src/protocol/text.js
View file @
67900c95
...
@@ -24,8 +24,8 @@ define(function(require, exports, module) {
...
@@ -24,8 +24,8 @@ define(function(require, exports, module) {
}
}
}
else
{
}
else
{
return
{
return
{
REGEXP
:
/^
(\t
|
\x
20
\x
20
\x
20
\x
20
)
/
,
REGEXP
:
/^
(\t
|
\x
20
{4}
)
/
,
DELETE
:
/^
(\t
|
\x
20
\x
20
\x
20
\x
20
)
+/
DELETE
:
/^
(\t
|
\x
20
{4}
)
+/
}
}
}
}
})(
Browser
);
})(
Browser
);
...
@@ -105,6 +105,29 @@ define(function(require, exports, module) {
...
@@ -105,6 +105,29 @@ define(function(require, exports, module) {
return
json
;
return
json
;
}
}
/**
* @Desc: 增加一个将当前选中节点转换成text的方法
* @Editor: Naixor
* @Date: 2015.9.21
*/
function
Node2Text
(
node
)
{
function
exportNode
(
node
)
{
var
exported
=
{};
exported
.
data
=
node
.
getData
();
var
childNodes
=
node
.
getChildren
();
exported
.
children
=
[];
for
(
var
i
=
0
;
i
<
childNodes
.
length
;
i
++
)
{
exported
.
children
.
push
(
exportNode
(
childNodes
[
i
]));
}
return
exported
;
}
if
(
!
node
)
return
;
if
(
/^
\s
*$/
.
test
(
node
.
data
.
text
))
{
node
.
data
.
text
=
"分支主题"
;
}
return
encode
({
root
:
exportNode
(
node
)
});
}
data
.
registerProtocol
(
'text'
,
module
.
exports
=
{
data
.
registerProtocol
(
'text'
,
module
.
exports
=
{
fileDescription
:
'大纲文本'
,
fileDescription
:
'大纲文本'
,
fileExtension
:
'.txt'
,
fileExtension
:
'.txt'
,
...
@@ -117,6 +140,10 @@ define(function(require, exports, module) {
...
@@ -117,6 +140,10 @@ define(function(require, exports, module) {
decode
:
function
(
local
)
{
decode
:
function
(
local
)
{
return
decode
(
local
);
return
decode
(
local
);
},
Node2Text
:
function
(
node
)
{
return
Node2Text
(
node
);
}
}
});
});
});
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment