2009-10-03 4 views
3

미리 포맷 된 코드를 표시하기 위해 장고에서 사용할 수있는 것을 찾고 있습니다. 비록 html과 xml을 잘 보여 주면서 시작하는 것이 좋은 출발점이 될지라도 이것은 이상적으로 다양한 프로그래밍 언어에 대한 out-of-the-box 구문 강조를 포함합니다.장고에 예쁜 코드 표시

이와 비슷한 것이 있습니까?

기본적으로 위젯 dpaste (및 스택 오버플로) 코드를 표시하는 용도로 사용하고 있습니다.

<?xml version="1.0" encoding='UTF-8'?> 
<painting> 
    <img src="madonna.jpg" alt='Foligno Madonna, by Raphael'/> 
    <caption>This is Raphael's "Foligno" Madonna, painted in 
    <date>1511</date>-<date>1512</date>.</caption> 
</painting> 

http://dpaste.com/hold/102141/

또는

내가 this question 알고 있어요,하지만 내 코드를 탈출의 메커니즘에 대한 것이 아니라,이 UI에 관하여이다.

답변

8

Pygments을 사용하여 구문 강조를 수행하고 표시 할 HTML을 가져올 수 있습니다.

예 번호 :

from pygments import highlight 
from pygments.lexers import PythonLexer 
from pygments.formatters import HtmlFormatter 

highlighted = highlight('# Some Python code', PythonLexer(), HtmlFormatter()) 

는 또한 official documentation 참조.