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
7dd590f0
Commit
7dd590f0
authored
Jan 16, 2016
by
hy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug #194
parent
c1546cdd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
5 deletions
+93
-5
text.js
src/protocol/text.js
+93
-5
No files found.
src/protocol/text.js
View file @
7dd590f0
...
@@ -9,7 +9,6 @@ define(function(require, exports, module) {
...
@@ -9,7 +9,6 @@ define(function(require, exports, module) {
*/
*/
var
LINE_ENDING
=
'
\
r'
,
var
LINE_ENDING
=
'
\
r'
,
LINE_ENDING_SPLITER
=
/
\r\n
|
\r
|
\n
/
,
LINE_ENDING_SPLITER
=
/
\r\n
|
\r
|
\n
/
,
TAB_CHAR
=
'
\
t'
,
TAB_CHAR
=
(
function
(
Browser
)
{
TAB_CHAR
=
(
function
(
Browser
)
{
if
(
Browser
.
gecko
)
{
if
(
Browser
.
gecko
)
{
return
{
return
{
...
@@ -36,11 +35,100 @@ define(function(require, exports, module) {
...
@@ -36,11 +35,100 @@ define(function(require, exports, module) {
return
result
;
return
result
;
}
}
/**
* 对节点text中的换行符进行处理
* @method encodeWrap
* @param {String} nodeText MinderNode.data.text
* @return {String} \n -> '\n'; \\n -> '\\n'
*/
function
encodeWrap
(
nodeText
)
{
if
(
!
nodeText
)
{
return
''
;
}
var
textArr
=
[],
WRAP_TEXT
=
[
'
\
\'
, '
n
'];
for (var i = 0, j = 0, l = nodeText.length; i < l; i++) {
if (nodeText[i] === '
\
n
' || nodeText[i] === '
\
r
') {
textArr.push('
\\
n
');
j = 0;
continue;
}
if (nodeText[i] === WRAP_TEXT[j]) {
j++;
if (j === 2) {
j = 0;
textArr.push('
\\\\
n
');
}
continue;
}
switch (j) {
case 0: {
textArr.push(nodeText[i]);
break;
}
case 1: {
textArr.push(nodeText[i-1], nodeText[i]);
}
}
j = 0;
}
return textArr.join('');
}
/**
* 将文本内容中的'
\
n
'和'
\\
n
'分别转换成
\
n和
\\
n
* @method decodeWrap
* @param {[type]} text [description]
* @return {[type]} [description]
*/
function decodeWrap(text) {
if (!text) {
return '';
}
var textArr = [],
WRAP_TEXT = ['
\\
', '
\\
', '
n
'];
for (var i = 0, j = 0, l = text.length; i < l; i++) {
if (text[i] === WRAP_TEXT[j]) {
j++;
if (j === 3) {
j = 0;
textArr.push('
\\
n
');
}
continue;
}
switch (j) {
case 0: {
textArr.push(text[i]);
j = 0;
break;
}
case 1: {
if (text[i] === '
n
') {
textArr.push('
\
n
');
} else {
textArr.push(text[i-1], text[i]);
}
j = 0;
break;
}
case 2: {
textArr.push(text[i-2]);
if (text[i] !== '
\\
') {
j = 0;
textArr.push(text[i-1], text[i]);
}
break;
}
}
}
return textArr.join('');
}
function encode(json, level) {
function encode(json, level) {
var local = '';
var local = '';
level = level || 0;
level = level || 0;
local += repeat('
\
t
', level);
local += repeat('
\
t
', level);
local
+=
json
.
data
.
text
+
LINE_ENDING
;
local +=
encodeWrap(json.data.text)
+ LINE_ENDING;
if (json.children) {
if (json.children) {
json.children.forEach(function(child) {
json.children.forEach(function(child) {
local += encode(child, level + 1);
local += encode(child, level + 1);
...
@@ -59,14 +147,14 @@ define(function(require, exports, module) {
...
@@ -59,14 +147,14 @@ define(function(require, exports, module) {
line = line.replace(TAB_CHAR.REGEXP, '');
line = line.replace(TAB_CHAR.REGEXP, '');
level++;
level++;
}
}
return level;
return level;
}
}
function getNode(line) {
function getNode(line) {
return {
return {
data: {
data: {
text
:
line
.
replace
(
TAB_CHAR
.
DELETE
,
""
)
text:
decodeWrap(line.replace(TAB_CHAR.DELETE, "")
)
}
}
};
};
}
}
...
@@ -146,4 +234,4 @@ define(function(require, exports, module) {
...
@@ -146,4 +234,4 @@ define(function(require, exports, module) {
return Node2Text(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