Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
d3f63d36
Kaydet (Commit)
d3f63d36
authored
Tem 23, 2012
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Simplify the LaTeX section (only three escapes are needed for alltt)
üst
392bfd30
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
11 deletions
+6
-11
highlight.py
Tools/scripts/highlight.py
+6
-11
No files found.
Tools/scripts/highlight.py
Dosyayı görüntüle @
d3f63d36
...
...
@@ -57,7 +57,7 @@ def analyze_python(source):
if
kind
:
text
,
written
=
combine_range
(
lines
,
written
,
(
srow
,
scol
))
yield
''
,
text
text
,
written
=
combine_range
(
lines
,
written
,
(
erow
,
ecol
)
)
text
,
written
=
tok_str
,
(
erow
,
ecol
)
yield
kind
,
text
line_upto_token
,
written
=
combine_range
(
lines
,
written
,
(
erow
,
ecol
))
yield
''
,
line_upto_token
...
...
@@ -172,15 +172,10 @@ default_latex_document = r'''
\end{document}
'''
def
latex_escape
(
s
):
'Replace LaTeX special characters with their escaped equivalents'
# http://en.wikibooks.org/wiki/LaTeX/Basics#Special_Characters
xlat
=
{
'#'
:
r'\#'
,
'$'
:
r'\$'
,
'
%
'
:
r'\%'
,
'^'
:
r'\textasciicircum{}'
,
'&'
:
r'\&'
,
'_'
:
r'\_'
,
'{'
:
r'\{'
,
'}'
:
r'\}'
,
'~'
:
r'\~{}'
,
'
\\
'
:
r'\textbackslash{}'
,
}
return
re
.
sub
(
r'[\\#$
%
^&_{}~]'
,
lambda
mo
:
xlat
[
mo
.
group
()],
s
)
def
alltt_escape
(
s
):
'Replace backslash and braces with their escaped equivalents'
xlat
=
{
'{'
:
r'\{'
,
'}'
:
r'\}'
,
'
\\
'
:
r'\textbackslash{}'
}
return
re
.
sub
(
r'[\\{}]'
,
lambda
mo
:
xlat
[
mo
.
group
()],
s
)
def
latex_highlight
(
classified_text
,
title
=
'python'
,
commands
=
default_latex_commands
,
...
...
@@ -191,7 +186,7 @@ def latex_highlight(classified_text, title = 'python',
for
kind
,
text
in
classified_text
:
if
kind
:
result
.
append
(
r'\py
%
s{'
%
kind
)
result
.
append
(
latex
_escape
(
text
))
result
.
append
(
alltt
_escape
(
text
))
if
kind
:
result
.
append
(
'}'
)
return
default_latex_document
%
dict
(
title
=
title
,
macros
=
macros
,
body
=
''
.
join
(
result
))
...
...
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