Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
cda1e86f
Commit
cda1e86f
authored
Apr 27, 2014
by
scoder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #290 from Carreau/clean-annotate-2
line-highlight fix + pygments highlight
parents
3de7790c
122a0a01
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
7 deletions
+51
-7
Cython/Compiler/Annotate.py
Cython/Compiler/Annotate.py
+51
-7
No files found.
Cython/Compiler/Annotate.py
View file @
cda1e86f
...
...
@@ -54,7 +54,11 @@ class AnnotationCCodeWriter(CCodeWriter):
for
i
in
range
(
255
):
color
=
u"FFFF%02x"
%
int
(
255
/
(
1
+
i
/
10.0
))
css
.
append
(
'
\
n
.cython.score-%d {background-color: #%s;}'
%
(
i
,
color
))
try
:
from
pygments.formatters
import
HtmlFormatter
css
.
append
(
HtmlFormatter
().
get_style_defs
(
'.cython'
))
except
ImportError
:
pass
return
''
.
join
(
css
)
_js
=
"""
...
...
@@ -70,7 +74,7 @@ class AnnotationCCodeWriter(CCodeWriter):
.cython.tag { }
.cython.line { margin: 0em }
.cython.code { font-size: 9; color: #444444; display: none; margin
-left: 20px;
}
.cython.code { font-size: 9; color: #444444; display: none; margin
: 0px 0px 0px 20px;
}
.cython.code .py_c_api { color: red; }
.cython.code .py_macro_api { color: #FF7000; }
...
...
@@ -135,6 +139,30 @@ class AnnotationCCodeWriter(CCodeWriter):
return
''
.
join
(
outlist
)
def
_save_annotation_body
(
self
,
lines
,
code_source_file
):
try
:
from
pygments
import
highlight
from
pygments.lexers
import
CythonLexer
from
pygments.formatters
import
HtmlFormatter
# pygments strip whitespace a t begining of file,
# need to compensate
n_empty_lines
=
0
for
l
in
lines
:
if
l
==
'
\
n
'
:
n_empty_lines
=
n_empty_lines
+
1
else
:
break
code
=
''
.
join
(
lines
)
hllines
=
highlight
(
code
,
CythonLexer
(),
HtmlFormatter
(
nowrap
=
True
))
# re-prepend the empty lines
hllines
=
'
\
n
'
*
n_empty_lines
+
hllines
lines
=
hllines
.
split
(
'
\
n
'
)
except
ImportError
:
lines
=
map
(
html_escape
,
lines
)
outlist
=
[
u'<div class="cython">'
]
pos_comment_marker
=
u'/*
\
N{HORIZONTAL ELLIPSIS}
*/
\
n
'
new_calls_map
=
dict
(
...
...
@@ -150,8 +178,8 @@ class AnnotationCCodeWriter(CCodeWriter):
return
ur"<span class='%s'>%s</span>"
%
(
group_name
,
match
.
group
(
group_name
))
ln_width
=
len
(
str
(
len
(
lines
)))
for
k
,
line
in
enumerate
(
lines
,
1
):
line
=
html_escape
(
line
)
try
:
code
=
code_source_file
[
k
]
except
KeyError
:
...
...
@@ -166,10 +194,26 @@ class AnnotationCCodeWriter(CCodeWriter):
code
=
_parse_code
(
annotate
,
code
)
score
=
(
5
*
calls
[
'py_c_api'
]
+
2
*
calls
[
'pyx_c_api'
]
+
calls
[
'py_macro_api'
]
+
calls
[
'pyx_macro_api'
])
outlist
.
append
(
u"<pre class='cython line score-%s' onclick='toggleDiv(this)'> %d: %s</pre>
\
n
"
%
(
score
,
k
,
line
.
rstrip
()))
outlist
.
append
(
u"<pre class='cython code score-%s'>%s</pre>"
%
(
score
,
code
))
onclick
=
''
expandsymbol
=
' '
if
code
:
onclick
=
"onclick='toggleDiv(this)'"
expandsymbol
=
'+'
outlist
.
append
(
u"<pre class='cython line score-{score}'"
u"{onclick}>"
# generate line number with expand symbol in front,
# and the right number of digit
"{expandsymbol}{ln:0{ln_width}d}: {line}</pre>
\
n
"
.
format
(
score
=
score
,
expandsymbol
=
expandsymbol
,
ln_width
=
ln_width
,
ln
=
k
,
line
=
line
.
rstrip
(),
onclick
=
onclick
))
if
code
:
outlist
.
append
(
u"<pre class='cython code score-%s'>%s</pre>"
%
(
score
,
code
))
outlist
.
append
(
u"</div>"
)
return
outlist
...
...
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