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
43e0e194
Commit
43e0e194
authored
Feb 24, 2014
by
Akikonata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
svg
parent
c67e5f49
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
0 deletions
+102
-0
svg.js
src/protocal/svg.js
+102
-0
No files found.
src/protocal/svg.js
0 → 100644
View file @
43e0e194
KityMinder
.
registerProtocal
(
"svg"
,
function
()
{
var
LINE_ENDING
=
'
\
n'
,
TAB_CHAR
=
'
\
t'
;
function
repeat
(
s
,
n
)
{
var
result
=
""
;
while
(
n
--
)
result
+=
s
;
return
result
;
}
function
encode
(
json
,
level
)
{
var
local
=
""
;
level
=
level
||
0
;
local
+=
repeat
(
TAB_CHAR
,
level
);
local
+=
json
.
data
.
text
+
LINE_ENDING
;
if
(
json
.
children
)
{
json
.
children
.
forEach
(
function
(
child
)
{
local
+=
encode
(
child
,
level
+
1
);
}
);
}
return
local
;
}
function
isEmpty
(
line
)
{
return
!
/
\S
/
.
test
(
line
);
}
function
getLevel
(
line
)
{
var
level
=
0
;
while
(
line
.
charAt
(
level
)
===
TAB_CHAR
)
level
++
;
return
level
;
}
function
getNode
(
line
)
{
return
{
data
:
{
text
:
line
.
replace
(
new
RegExp
(
'^'
+
TAB_CHAR
+
'*'
),
''
)
}
};
}
function
decode
(
local
)
{
var
json
,
parentMap
=
{},
lines
=
local
.
split
(
LINE_ENDING
),
line
,
level
,
node
;
function
addChild
(
parent
,
child
)
{
var
children
=
parent
.
children
||
(
parent
.
children
=
[]
);
children
.
push
(
child
);
}
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
line
=
lines
[
i
];
if
(
isEmpty
(
line
)
)
continue
;
level
=
getLevel
(
line
);
node
=
getNode
(
line
);
if
(
level
===
0
)
{
if
(
json
)
{
throw
new
Error
(
'Invalid local format'
);
}
json
=
node
;
}
else
{
if
(
!
parentMap
[
level
-
1
]
)
{
throw
new
Error
(
'Invalid local format'
);
}
addChild
(
parentMap
[
level
-
1
],
node
);
}
parentMap
[
level
]
=
node
;
}
return
json
;
}
var
lastTry
,
lastResult
;
function
recognize
(
local
)
{
if
(
!
Utils
.
isString
(
local
)
)
return
false
;
lastTry
=
local
;
try
{
lastResult
=
decode
(
local
);
}
catch
(
e
)
{
lastResult
=
null
;
}
return
!!
lastResult
;
}
return
{
fileDescription
:
'svg'
,
fileExtension
:
'.svg'
,
encode
:
function
(
json
)
{
return
encode
(
json
,
0
);
},
decode
:
function
(
local
)
{
if
(
lastTry
==
local
&&
lastResult
)
{
return
lastResult
;
}
return
decode
(
local
);
},
recognize
:
recognize
,
recognizePriority
:
-
1
};
}
);
\ 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