Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Boxiang Sun
erp5
Commits
cf0731f9
Commit
cf0731f9
authored
Jul 22, 2019
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_notebook: Process Python code block
We follow the standard jsmd format.
parent
aa95e1a0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
5 deletions
+27
-5
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js
...ateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js
+27
-5
No files found.
bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/gadget_jsmd_eval.js.js
View file @
cf0731f9
...
@@ -6,12 +6,13 @@
...
@@ -6,12 +6,13 @@
var
IODide
=
function
createIODide
()
{
var
IODide
=
function
createIODide
()
{
return
;
return
;
},
},
JSMDCell
=
function
createJSMDCell
(
type
,
line_list
)
{
JSMDCell
=
function
createJSMDCell
(
type
,
line_list
,
option
)
{
this
.
_type
=
type
;
this
.
_type
=
type
;
this
.
_line_list
=
line_list
;
this
.
_line_list
=
line_list
;
this
.
_option
=
option
;
},
},
split_line_regex
=
/
[\r\n
|
\n
|
\r]
/
,
split_line_regex
=
/
[\r\n
|
\n
|
\r]
/
,
cell_type_regexp
=
/^
\%\%
(\w
+
)
$
/
;
cell_type_regexp
=
/^
\%\%
(\w
+
)
/
;
window
.
iodide
=
new
IODide
();
window
.
iodide
=
new
IODide
();
...
@@ -67,16 +68,24 @@
...
@@ -67,16 +68,24 @@
var
line_list
=
jsmd
.
split
(
split_line_regex
),
var
line_list
=
jsmd
.
split
(
split_line_regex
),
i
,
i
,
len
=
line_list
.
length
,
len
=
line_list
.
length
,
code_type
,
current_line
,
current_line
,
current_type
,
current_type
,
current_header
,
current_text_list
,
current_text_list
,
option
,
next_type
,
next_type
,
cell_list
=
[];
cell_list
=
[];
function
pushNewCell
()
{
function
pushNewCell
()
{
if
(
current_type
!==
undefined
)
{
if
(
current_type
!==
undefined
)
{
option
=
current_header
.
slice
(
current_type
[
0
].
length
);
if
(
option
!==
''
)
{
option
=
JSON
.
parse
(
option
);
}
cell_list
.
push
(
new
JSMDCell
(
current_type
[
1
],
cell_list
.
push
(
new
JSMDCell
(
current_type
[
1
],
current_text_list
));
current_text_list
,
option
));
}
}
}
}
...
@@ -84,9 +93,10 @@
...
@@ -84,9 +93,10 @@
current_line
=
line_list
[
i
];
current_line
=
line_list
[
i
];
next_type
=
current_line
.
match
(
cell_type_regexp
);
next_type
=
current_line
.
match
(
cell_type_regexp
);
if
(
next_type
)
{
if
(
next_type
)
{
// New type dete
x
ted
// New type dete
c
ted
pushNewCell
();
pushNewCell
();
current_type
=
next_type
;
current_type
=
next_type
;
current_header
=
current_line
;
current_text_list
=
[];
current_text_list
=
[];
}
else
if
(
current_text_list
!==
undefined
)
{
}
else
if
(
current_text_list
!==
undefined
)
{
current_text_list
.
push
(
current_line
);
current_text_list
.
push
(
current_line
);
...
@@ -253,8 +263,17 @@
...
@@ -253,8 +263,17 @@
});
});
}
}
function
executeCodeCell
(
line_list
,
language
)
{
if
(
language
===
'
py
'
)
{
console
.
log
(
line_list
);
console
.
log
(
"
We are processing Python code!!!
"
);
}
else
{
throw
new
Error
(
'
Unsupported code language:
'
+
language
);
}
}
function
executeCell
(
cell
)
{
function
executeCell
(
cell
)
{
if
(
cell
.
_type
===
'
raw
'
)
{
if
(
cell
.
_type
===
'
raw
'
||
cell
.
_type
===
'
meta
'
||
cell
.
_type
===
'
plugin
'
)
{
// Do nothing...
// Do nothing...
return
;
return
;
}
}
...
@@ -273,6 +292,9 @@
...
@@ -273,6 +292,9 @@
if
(
cell
.
_type
===
'
css
'
)
{
if
(
cell
.
_type
===
'
css
'
)
{
return
executeCssCell
(
cell
.
_line_list
);
return
executeCssCell
(
cell
.
_line_list
);
}
}
if
(
cell
.
_type
===
'
code
'
)
{
return
executeCodeCell
(
cell
.
_line_list
,
cell
.
_option
.
language
);
}
return
executeUnknownCellType
(
cell
);
return
executeUnknownCellType
(
cell
);
}
}
...
...
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