Inputing also ".rst" files
See original GitHub issueIf we ever want to also input “.rst” files, it’s really easy to read them in, and convert them to .py files.
I just came across some code lying on my disk since a while (probably copy-pasted from Internet):
from docutils.core import publish_doctree
doctree = publish_doctree(open('input.rst').read())
def is_code_block(node):
return (node.tagname == 'literal_block')
code_blocks = doctree.traverse(condition=is_code_block)
source_code = [block.astext() for block in code_blocks]
with open('output.py', 'w') as f:
f.write('\n######################\n\n'.join(source_code[2:]))
So we should keep in mind that it’s probably a low cost feature that might make users happy.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
13. Example .rst File — EdX Style Guide documentation
This file contains examples of .rst formatting. ... grading problems (also called *custom JavaScript problems* or *JS input problems*) allow you to create...
Read more >Quick reStructuredText - Docutils
Inline Markup. Inline markup allows words and phrases within text to have character styles (like italics and boldface) and functionality (like hyperlinks). ...
Read more >Sphinx and RST syntax guide (0.9.3) - Thomas-Cokelaer.info
This page describes some of the RST and Sphinx syntax. It is based on resource found at Sphinx ... What are directives; Inserting...
Read more >RST File Format- reStructuredText File
It is a text file written in the reStructuredText markup language that applies styles and formatting to plain text documents for generation of...
Read more >reStructuredText Primer - Sphinx documentation
It is also possible to replace or expand upon some of this inline markup with roles. ... For example, the file sketch/spam.rst could...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes we already do it – I’m saying that this might be a problem / conflict if we implement a “run all RST” feature
@larsoner Excellent response! This helped explain a lot of the parts that I didn’t know. I am interested in pursuing this concept further, especially if there is interest from other sphinx-gallery users. I’m probably going to work on enabling sphinx-gallery for a project first, so I can get more familiar with its usage and features.
@lucyleeow Good question. I use standard Sphinx-style, NumPy-style, and Google-style docstrings in different projects, so I would want to support all of them, but I think that should be possible. I would guess that there’s a layer/stage of the process at which all example code snippets are handled the same way and could be detected/executed without needing to specialize for different formats/tools, but I am not super familiar with the internals of these packages.