Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7923195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:13:54+00:00 2026-06-03T17:13:54+00:00

I am currently using Sphinx to document a mixed-language project, such that the documentation

  • 0

I am currently using Sphinx to document a mixed-language project, such that the documentation includes examples of interactive sessions not just in Python, but also in bash and the Windows command-line, as well as MATLAB and other interpreters. While Pygments takes care of highlighting everything nicely, all of the interactive sessions I’ve included in the documentation so far show up in HTML output preceded by the Python prompt, >>>. How can I change that prompt to $, for example, when documenting bash sessions?


Edited to clarify:

As documented in the Sphinx manual, under “Showing code examples,” ReST source for a Sphinx document can contain code like:

>>> # python code here
>>> print "foo"
foo

This code then gets turned into markup like that demonstrated in the documentation of argparse in the Python standard library documentation, showing the code after the >>> as a highlighted snippet. Though it is clear that one can simply typeset unhighlighted blocks with other prompt characters, I am wondering how to combine a prompt other than >>> with the interactive prompt styling shown in the argparse example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:13:56+00:00Added an answer on June 3, 2026 at 5:13 pm

    You can use, say, $ as the prompt for bash snippets, but it cannot be used for Python if you want the output to be nicely highlighted.

    >>> is recognized as the interactive Python prompt. But using another prompt won’t work. The documentation says: “Normal Python code is only highlighted if it is parseable”, and something like

    $ import sys 
    

    or

    >> import sys 
    

    is not parseable as Python.

    It is possible to use extensions to make Sphinx accept other Python prompts. The ipython directive is an example (not tested by me).


    These examples work well for me:

    .. code-block:: bash
    
       $ pwd
       /home
       $ echo TEST
       TEST
    
    .. code-block:: python
    
       >>> import sys
       >>> print "X"
       X
    

    And the following produces identical formatting and highlighting:

    .. highlight:: bash
    
    ::
    
       $ pwd
       /home
       $ echo TEST
       TEST
    
    .. highlight:: python
    
    ::
    
       >>> import sys
       >>> print "X"
       X
    

    For Python interactive sessions, no extra markup is actually needed (unless the most recent .. highlight:: directive has a target other than python). Sphinx recognizes >>> automatically:

    >>> import sys
    >>> print "X"
    X
    

    Without any prompts, the code must be in a code-block (or literal block) to be formatted properly:

    .. code-block:: python
    
       import sys
       print "X"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently using vim. But i found that there is not even a plugin
I'm building a system using django, Sphinx and MySQL that's very quickly becoming quite
Currently using: @^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$ How can i make http:// not compulsory but if it does
I have a website that is using Sphinx search server to search through a
Im currently using base64_encode for some $_GET params that i don't want regular user
Im currently using a method that looks like the following code to add script
I'm using the Sphinx autodoc extension to document a module, and I'd like to
Currently using Gettext on a project and the .po files are nicely kept under
I currently using my own membership implementation on a ASP.MVC project. I've got an
Is there a way to automatically generate an image/figure caption using sphinx? I currently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.