Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renderer: option to show source code #225

Open
machow opened this issue Jul 25, 2023 · 5 comments
Open

Renderer: option to show source code #225

machow opened this issue Jul 25, 2023 · 5 comments
Assignees
Milestone

Comments

@machow
Copy link
Owner

machow commented Jul 25, 2023

Let's add an option to render the source code for an object (inside a collapsed dropdown).

Still thinking about if this should happen by default 🤔

@machow
Copy link
Owner Author

machow commented Aug 8, 2023

Here's an example of source code in a doc.

image

Let's aim to do something similar:

  • add the option show_source to layout.Auto
  • lists file name
  • click to expand
  • test via snapshot

@machow machow added the ibis label Aug 25, 2023
@machow machow assigned machow and unassigned hamelsmu Aug 30, 2023
@machow
Copy link
Owner Author

machow commented Aug 30, 2023

There's a bit of a funky issue here. Basically quarto will look for python blocks, even in indented blocks in a qmd. So we need an escaping strategy to place source code inside qmds.

So far using a function like this seems to work:

def sanitize(x):
    return (x
        .replace("{", "{")
        .replace("}", "}")
        .replace("`", "`")
    )

It can take a string of source like this...

def f(x):
    """Some func

    ```{python}
    1 + 1
    ```
    """

And turn it into this (I've added code and pre elements):

<code><pre>
def f(x):
    """Some func

    &grave;&grave;&grave;&lbrace;python&rbrace;
    1 + 1
    &grave;&grave;&grave;
    """
</code></pre>

In this case, quarto doesn't read the source as having a python block to execute.

@isabelizimm
Copy link
Collaborator

Another potential option is to not have the source code rendered, but rather have a link to source code that opens on GitHub. Happy to break that out into another issue if that makes more sense!

CC: @ncclementi @gforsyth who are interested in this for ibis docs 👀

@deepyaman
Copy link

Another potential option is to not have the source code rendered, but rather have a link to source code that opens on GitHub. Happy to break that out into another issue if that makes more sense!

CC: @ncclementi @gforsyth who are interested in this for ibis docs 👀

I randomly came across this issue just now because I was independently frustrated that it wasn't in the Ibis docs. 😂 I actually prefer links to GitHub source, personally.

@ncclementi
Copy link

Opened a separate issue for a feature to link to github source since it's slightly different than the original opened here.
xref: #354

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

5 participants