How to use color in text with ReStructured Text (rst2html.py) or how to insert HTML tags without blank lines?

后端 未结 7 1557
抹茶落季
抹茶落季 2020-12-13 13:37

How can I use color with ReStructured Text? For example, **hello** translates into hello. How can I make ReStructure(r

相关标签:
7条回答
  • 2020-12-13 14:41

    Combining @prosseek's and @RayLuo's answers all in one place - to make easier to find

    At the top of your RST file, place

    .. raw:: html
    
        <style> .red {color:red} </style>
    
    .. role:: red
    
    :red:`test - this text should be red`
    

    SIDE COMMENT:

    Of course, many folks will want the style in a separate file, as @sienkiew says.

    But not always.

    E.g. I am generating the above from a script that I want other users to be able to run, often from a file URL. Depending on rst2html.py is bad enough - requiring something nonstandard to be in a config file is worse.

    If there were a way to create a weak local definition for the style - e.g. "if there is no style .red already defined use this, but otherwise use the style already defined" - would be nice. But AFAIK local definitions are stronger.

    This ran with rst2html.py (Docutils 0.13.1 [release], Python 3.6.4, on cygwin), but other RST tools rejected.

    0 讨论(0)
提交回复
热议问题