How to Embed Html or Xml in reStructuredText (Sphinx) So the Browser Cna Render Them?

I just need to embed a small piece of html or xml in the reStructuredText (sphinx) so that the browser can render them in the generated HTML files, like the following little piece

.. raw:: html
  <a href="testurl">testurl</a>

or

.. raw:: html
  <math><apply><plus/><ci>a</ci><apply><minus/><ci>b</ci><ci>c</ci></apply></apply></math>

No matter I tried directives like "literal", "raw", "container", "code", either the html code is displayed as the inner text of some "p" block (so the browser display the code rather than render it), or the code just disappear from the output.

What is the correct way to embed html or xml in the reStructuredText (sphinx) so the browser can render them? I just want to html or xml just be placed there intact.

1 Answer

You need to add a blank line between the raw directive and your code.

.. raw:: html

    <a href="testurl">testurl</a>

I would suggest indenting 4 spaces to be consistent with Python formatting, but 2 is fine.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest