css - Sphinx inline code highlight -


i use sphinx make website contains code samples. i'm successful using .. code-block directive syntax highlighting. can't inline syntax highlighting using code:

.. role:: bash(code)    :language: bash  test inline: :bash:`export foo="bar"`.  .. code-block:: bash      export foo="bar" 

which produces output i.e. inline code not highlighted while block code is:

result

problem me generated html inline code contains long class names while not code blocks. here output html (indented readability):

<p>test inline:     <tt class="code bash docutils literal">         <span class="name builtin">             <span class="pre">export</span>         </span>         <span class="name variable">             <span class="pre">foo</span>         </span>         <span class="operator">             <span class="pre">=</span>         </span>         <span class="literal string double">             <span class="pre">&quot;bar&quot;</span>         </span>     </tt>. </p>   <p>test code-block:</p> <div class="highlight-bash">     <div class="highlight">         <pre>             <span class="nb">export </span>             <span class="nv">foo</span>             <span class="o">=</span>             <span class="s2">&quot;bar&quot;</span>         </pre>     </div> </div> 

any appreciated.

ok used workaround: generate css file contains both short , long names. i'm still interested in "good" answer.

#!/usr/bin/env python  """generate css file pygments contain both short , long class names."""   import subprocess import sys   pygmentize = 'pygmentize'   def parse_command_line():     import argparse     parser = argparse.argumentparser(description=__doc__)     parser.add_argument('-s', '--style', default='colorful')     parser.add_argument('-p', '--prefix', default='.highlight')     return parser.parse_args()   def pygmentize(style, prefix='.highlight'):     cmd = '{0} -f html -s {1} -a {2}'.format(pygmentize, style, prefix)     # fail if pygmentize not exist.     try:         p = subprocess.popen(cmd.split(), stdout=subprocess.pipe)     except oserror:         print >> sys.stderr, '{0}: command not found'.format(pygmentize)         exit(1)      out, err = p.communicate()     if p.returncode != 0:         exit(p.returncode)     return out   def main():     args = parse_command_line()     style = args.style     prefix = args.prefix      # print new css header.     header = """\ /*   * pygment css style {0} generated  *     {1}  */""".format(style, ' '.join(sys.argv))     print header      # parse pygmentize output.     # find long names based on comments.     content = pygmentize(style, prefix)     s = content.splitlines()     out = ''     line in s:         start = line.find("/* ") + 3         end = line.find(" */")         # if line has comment         if start != 2:             comment = line[start:end]             name = '.' + comment.lower()             arg = line[line.find('{ '): start - 4]             out += '%(prefix)s %(name)s %(arg)s\n' % vars()      print content     print out   if __name__ == '__main__':     main() 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -