Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Make examples alive
Browse files Browse the repository at this point in the history
  • Loading branch information
kwankyu committed Mar 24, 2022
1 parent 72c8378 commit 1a47505
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 445 deletions.
10 changes: 9 additions & 1 deletion src/doc/common/themes/sage-classic/static/sage.css_t
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,16 @@ dl.citation p {

#thebelab-activate-button {
position: fixed;
right: -100px;
top: 50%;
border-radius: 20px;
transition-property: right;
transition-duration: 300ms;
transition-timing-function: ease-out;
}

#thebelab-activate-button:hover {
right: 10px;
bottom: 10px;
}

.jupyter_cell .thebelab-input {
Expand Down
45 changes: 42 additions & 3 deletions src/sage/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,6 @@ def find_sage_dangling_links(app, env, node, contnode):
name, obj = matches[0]
debug_inf(app, "++ match = %s %s"%(name, obj))

from docutils import nodes
newnode = nodes.reference('', '', internal=True)
if name == target_module:
newnode['refid'] = name
Expand Down Expand Up @@ -912,11 +911,12 @@ def skip_TESTS_block(app, what, name, obj, options, docstringlines):
while len(docstringlines) > len(lines):
del docstringlines[len(lines)]


class SagemathTransform(Transform):
"""
Transform for code-blocks.
Transform for code blocks.
This allows Sphinx to treat code-blocks with prompt "sage:" as
This allows Sphinx to treat code blocks with prompt "sage:" as
associated with the pycon lexer, and in particular, to change
"<BLANKLINE>" to a blank line.
"""
Expand All @@ -931,6 +931,44 @@ def apply(self):
node.rawsource = source
node[:] = [nodes.Text(source)]


from jupyter_sphinx.ast import JupyterCellNode, CellInputNode

class SagecodeTransform(Transform):
"""
Transform code blocks to live code blocks enabled by jupter-sphinx.
"""
# lower than the priority of jupyer_sphinx.execute.ExecuteJupyterCells
default_priority = 170

def apply(self):
for node in self.document.traverse(nodes.literal_block):
if node.get('language') is None and node.astext().startswith('sage:'):
source = node.rawsource
lines = []
for line in source.splitlines():
newline = line.lstrip()
if newline.startswith('sage: ') or newline.startswith('....: '):
lines.append(newline[6:])
cell_node = JupyterCellNode(
execute=True,
hide_code=True,
hide_output=True,
emphasize_lines=[],
raises=False,
stderr=False,
code_below=False,
classes=["jupyter_cell"])
cell_input = CellInputNode(classes=['cell_input'])
cell_input += nodes.literal_block(
text='\n'.join(lines),
linenos=False,
linenostart=1)
cell_node += cell_input

node.parent.insert(node.parent.index(node) + 1, cell_node)


from sage.misc.sageinspect import sage_getargspec
autodoc_builtin_argspec = sage_getargspec

Expand All @@ -944,6 +982,7 @@ def setup(app):
app.connect('autodoc-process-docstring', skip_TESTS_block)
app.connect('autodoc-skip-member', skip_member)
app.add_transform(SagemathTransform)
app.add_transform(SagecodeTransform)

# When building the standard docs, app.srcdir is set to SAGE_DOC_SRC +
# 'LANGUAGE/DOCNAME', but when doing introspection, app.srcdir is
Expand Down
Loading

0 comments on commit 1a47505

Please sign in to comment.