This commit is contained in:
Georg Brandl 2014-01-19 10:57:49 +01:00
commit 883b960cb1
10 changed files with 59 additions and 0 deletions

View File

@ -58,6 +58,7 @@ class CodeBlock(Directive):
'linenos': directives.flag,
'lineno-start': int,
'emphasize-lines': directives.unchanged_required,
'filename': directives.unchanged_required,
}
def run(self):
@ -76,6 +77,9 @@ class CodeBlock(Directive):
literal = nodes.literal_block(code, code)
literal['language'] = self.arguments[0]
filename = self.options.get('filename')
if filename:
literal['filename'] = filename
literal['linenos'] = 'linenos' in self.options or \
'lineno-start' in self.options
extra_args = literal['highlight_args'] = {}

View File

@ -462,3 +462,10 @@ div.viewcode-block:target {
border-top: 1px solid #ac9;
border-bottom: 1px solid #ac9;
}
div.code-block-filename {
background-color: #ddd;
color: #333;
padding: 2px 5px;
font-size: small;
}

View File

@ -471,6 +471,20 @@ table.highlighttable td {
padding: 0 0.5em 0 0.5em;
}
div.code-block-filename {
padding: 2px 5px;
font-size: small;
}
div.code-block-filename tt {
background-color: transparent;
}
div.code-block-filename + pre,
div.code-block-filename + div.highlight > pre {
margin-top: 0;
}
tt.descname {
background-color: transparent;
font-weight: bold;

View File

@ -308,3 +308,8 @@ div.viewcode-block:target {
border-top: 1px solid #ac9;
border-bottom: 1px solid #ac9;
}
div.code-block-filename {
color: #efefef;
background-color: #1c4e63;
}

View File

@ -243,3 +243,9 @@ div.viewcode-block:target {
border-top: 1px solid #ac9;
border-bottom: 1px solid #ac9;
}
div.code-block-filename {
background-color: #ddd;
color: #222;
border: 1px solid #C6C9CB;
}

View File

@ -340,3 +340,8 @@ tt.xref {
font-weight: normal;
font-style: normal;
}
div.code-block-filename {
background-color: #ddd;
color: #222;
}

View File

@ -337,3 +337,9 @@ div.viewcode-block:target {
border-top: 1px solid #ac9;
border-bottom: 1px solid #ac9;
}
div.code-block-filename {
background-color: #ddd;
color: #222;
border: 1px solid #ccc;
}

View File

@ -698,3 +698,7 @@ div.viewcode-block:target {
margin: -1px -10px;
padding: 0 10px;
}
div.code-block-filename {
background-color: #cceeff;
}

View File

@ -267,6 +267,9 @@ class HTMLTranslator(BaseTranslator):
**highlight_args)
starttag = self.starttag(node, 'div', suffix='',
CLASS='highlight-%s' % lang)
if node.has_key('filename'):
starttag += '<div class="code-block-filename"><tt>%s</tt></div>' % (
node['filename'],)
self.body.append(starttag + highlighted + '</div>\n')
raise nodes.SkipNode

View File

@ -1337,6 +1337,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
highlight_args['force'] = True
if 'linenos' in node:
linenos = node['linenos']
filename = node.get('filename')
if filename:
self.body.append('\n{\\colorbox[rgb]{0.9,0.9,0.9}'
'{\\makebox[\\textwidth][l]'
'{\\small\\texttt{%s}}}}\n' % (filename,))
def warner(msg):
self.builder.warn(msg, (self.curfilestack[-1], node.line))
hlcode = self.highlighter.highlight_block(code, lang, warn=warner,