From c5880303ec69f984827af77f08cf3d9a54f83cd2 Mon Sep 17 00:00:00 2001 From: milde Date: Tue, 30 Nov 2010 11:59:33 +0000 Subject: Prepare CodeBlock directive for inclusion in the Docutils core. Rename directive and class from "code-block" to "code". Fix fallback if pygments not found. Use class-based interface. Add "number-lines" option. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@6488 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- .../code-block-directive/docs/myfunction.py.htm | 118 ++----------------- .../code-block-directive/docs/myfunction.py.pdf | Bin 25434 -> 25692 bytes .../code-block-directive/docs/myfunction.py.tex | 131 ++++++++------------- .../code-block-directive/docs/myfunction.py.txt | 16 ++- 4 files changed, 76 insertions(+), 189 deletions(-) (limited to 'sandbox/code-block-directive/docs') diff --git a/sandbox/code-block-directive/docs/myfunction.py.htm b/sandbox/code-block-directive/docs/myfunction.py.htm index 62f7ae00f..617f4b671 100644 --- a/sandbox/code-block-directive/docs/myfunction.py.htm +++ b/sandbox/code-block-directive/docs/myfunction.py.htm @@ -3,124 +3,30 @@ - + - +
-

This is a test of the new code-block directive:

+

This is a test of the new "code" directive:

-
-def my_function():
-    "just a test"
-    print 8/2
-
+
+1 def my_function():
+2     """Test the lexer.
+3 
+4     just a test"""
+5 
+6     # and now for something completely different
+7     print 8/2
 
+

The end.

diff --git a/sandbox/code-block-directive/docs/myfunction.py.pdf b/sandbox/code-block-directive/docs/myfunction.py.pdf index 05fba74ea..b6624d223 100644 Binary files a/sandbox/code-block-directive/docs/myfunction.py.pdf and b/sandbox/code-block-directive/docs/myfunction.py.pdf differ diff --git a/sandbox/code-block-directive/docs/myfunction.py.tex b/sandbox/code-block-directive/docs/myfunction.py.tex index 6d5ddd5dd..c72da4eac 100644 --- a/sandbox/code-block-directive/docs/myfunction.py.tex +++ b/sandbox/code-block-directive/docs/myfunction.py.tex @@ -1,93 +1,66 @@ -\documentclass[10pt,a4paper,english]{scrartcl} -\usepackage{babel} -\usepackage[T1]{fontenc} -\usepackage{shortvrb} -\usepackage{ucs} -\usepackage[utf8x]{inputenc} -\usepackage{tabularx} -\usepackage{longtable} -\usepackage{booktabs} -\setlength{\extrarowheight}{2pt} -\usepackage{amsmath} -\usepackage{graphicx} -\usepackage{color} -\usepackage{multirow} -\usepackage{ifthen} -\typearea{12} +\documentclass[a4paper]{article} % generated by Docutils -\newlength{\admonitionwidth} -\setlength{\admonitionwidth}{0.9\textwidth} -\newlength{\docinfowidth} -\setlength{\docinfowidth}{0.9\textwidth} -\newlength{\locallinewidth} -\newcommand{\optionlistlabel}[1]{\bf #1 \hfill} -\newenvironment{optionlist}[1] -{\begin{list}{} - {\setlength{\labelwidth}{#1} - \setlength{\rightmargin}{1cm} - \setlength{\leftmargin}{\rightmargin} - \addtolength{\leftmargin}{\labelwidth} - \addtolength{\leftmargin}{\labelsep} - \renewcommand{\makelabel}{\optionlistlabel}} -}{\end{list}} -\newlength{\lineblockindentation} -\setlength{\lineblockindentation}{2.5em} -\newenvironment{lineblock}[1] -{\begin{list}{} - {\setlength{\partopsep}{\parskip} - \addtolength{\partopsep}{\baselineskip} - \topsep0pt\itemsep0.15\baselineskip\parsep0pt - \leftmargin#1} - \raggedright} -{\end{list}} -% begin: floats for footnotes tweaking. -\setlength{\floatsep}{0.5em} -\setlength{\textfloatsep}{\fill} -\addtolength{\textfloatsep}{3em} -\renewcommand{\textfraction}{0.5} -\renewcommand{\topfraction}{0.5} -\renewcommand{\bottomfraction}{0.5} -\setcounter{totalnumber}{50} -\setcounter{topnumber}{50} -\setcounter{bottomnumber}{50} -% end floats for footnotes -% some commands, that could be overwritten in the style file. -\newcommand{\rubric}[1]{\subsection*{~\hfill {\it #1} \hfill ~}} -\newcommand{\titlereference}[1]{\textsl{#1}} -% end of "some commands" -% user specified packages and stylesheets: +\usepackage{fixltx2e} % LaTeX patches, \textsubscript +\usepackage{cmap} % fix search and cut-and-paste in Acrobat +\usepackage{ifthen} +\usepackage[T1]{fontenc} +\usepackage[utf8]{inputenc} +\setcounter{secnumdepth}{0} + +%%% Custom LaTeX preamble +% suppress the (LaTeX-added) References section heading +\AtBeginDocument{\renewcommand{\refname}{\vspace{-1em}}} +\newlength{\DUlineblockindent} +\setlength{\DUlineblockindent}{1em} + +%%% User specified packages and stylesheets \usepackage{../data/pygments-docutilsroles} -\ifthenelse{\isundefined{\hypersetup}}{ -\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} -}{} -% Custom roles: -% \DUrole{NAME}{content} calls \docutilsroleNAME if it exists -\providecommand{\DUrole}[2]{% - \ifcsname docutilsrole#1\endcsname% - \csname docutilsrole#1\endcsname{#2}% - \else% - #2% + +%%% Fallback definitions for Docutils-specific commands + +% inline markup (custom roles) +% \DUrole{#1}{#2} tries \DUrole#1{#2} +\providecommand*{\DUrole}[2]{% + \ifcsname DUrole#1\endcsname% + \csname DUrole#1\endcsname{#2}% + \else% backwards compatibility: try \docutilsrole#1{#2} + \ifcsname docutilsrole#1\endcsname% + \csname docutilsrole#1\endcsname{#2}% + \else% + #2% + \fi% \fi% } -\title{} -\author{} -\date{} -\raggedbottom + +% hyperlinks: +\ifthenelse{\isundefined{\hypersetup}}{ + \usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=black]{hyperref} + \urlstyle{same} % normal text font (alternatives: tt, rm, sf) +}{} + + +%%% Body \begin{document} -\setlength{\locallinewidth}{\linewidth} +This is a test of the new ``code'' directive: -This is a test of the new code-block directive: % Translate this document to HTML with a pygments enhanced frontend, e.g. % -% rst2html-highlight --stylesheet=../data/pygments-default.css --link-stylesheet +% ../rst2html-highlight --stylesheet=../data/pygments-default.css % -% rst2latex-highlight --stylesheet=../data/pygments-docutileroles.sty +% ../rst2latex-highlight --stylesheet=../data/pygments-docutilsroles.sty +% \begin{quote}{\ttfamily \raggedright \noindent -\DUrole{k}{def}~\DUrole{nf}{my{\_}function}\DUrole{p}{():}~\\ -~~~~\DUrole{s}{"just~a~test"}~\\ -~~~~\DUrole{k}{print}~\DUrole{mf}{8}\DUrole{o}{/}\DUrole{mf}{2}~\\ +\DUrole{ln}{~7~}\DUrole{k}{def}~\DUrole{nf}{my\_function}\DUrole{p}{():}~\\ +\DUrole{ln}{~8~}~~~~\DUrole{sd}{"{}"{}"Test~the~lexer.\\ +}\DUrole{ln}{~9~}\DUrole{sd}{~\\ +}\DUrole{ln}{10~}\DUrole{sd}{~~~~just~a~test"{}"{}"}~\\ +\DUrole{ln}{11~}~\\ +\DUrole{ln}{12~}~~~~\DUrole{c}{\#~and~now~for~something~completely~different}~\\ +\DUrole{ln}{13~}~~~~\DUrole{k}{print}~\DUrole{mi}{8}\DUrole{o}{/}\DUrole{mi}{2} +} +\end{quote} -}\end{quote} +The end. \end{document} diff --git a/sandbox/code-block-directive/docs/myfunction.py.txt b/sandbox/code-block-directive/docs/myfunction.py.txt index 783e5b0b6..b9727e96f 100644 --- a/sandbox/code-block-directive/docs/myfunction.py.txt +++ b/sandbox/code-block-directive/docs/myfunction.py.txt @@ -1,13 +1,21 @@ -This is a test of the new code-block directive: +This is a test of the new "code" directive: .. Translate this document to HTML with a pygments enhanced frontend, e.g. ../rst2html-highlight --stylesheet=../data/pygments-default.css - ../rst2latex-highlight --stylesheet=../data/pygments-docutileroles.sty + ../rst2latex-highlight --stylesheet=../data/pygments-docutilsroles.sty -.. code-block:: python +.. code:: python + :class: silly + :number-lines: 7 def my_function(): - "just a test" + """Test the lexer. + + just a test""" + + # and now for something completely different print 8/2 + +The end. -- cgit v1.2.1