Skip to content

Be able to create runnable, editable snippets and include portions of the file #2643

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

Open
vincevargadev opened this issue Apr 5, 2025 · 0 comments
Labels
C-enhancement Category: Enhancement or feature request

Comments

@vincevargadev
Copy link

Problem

I want to be able to include a code snippet

  • either by lines or anchors

that is:

  • runnable (with Playground)
  • editable by the user

By default, only the selected range (either by lines or anchors) should be displayed, but the user should be able to run the whole file with Playground, expand all content, and edit the content.

As I've seen that's currently not possible as only the shown part of the file will be sent to the playground.

The closest I got is:

    ```rust,editable
    {{#include ../code/hello.rs:printl}}
    ````

This displays the selected anchor of the file, keep the content editable, and displays the play button.

However, when the reader taps on play, only the selected content between the anchors will be sent to the Rust playground, so it won't compile, as the the main function and some of the .rs file's content is not in the snippet.

Another approach I tried is this

    ```rust
    {{#rustdoc_include  ../code/hello.rs:printl}}
    ```

This will show only the selected part of the file, it will run the whole file, BUT it won't be editable.

    ```rust,editable
    {{#rustdoc_include  ../code/hello.rs:printl}}
    ```

If I add the editable tag, it becomes editable, it runs the examples with Playgorund BUT the whole file is rendered, not only the selected region.

Proposed Solution

I should be able to

  1. include only part of the file by lines or anchor, and display only that region of the code in the book
  2. have the code run the whole file with Playground
  3. keep the content editable
  4. keep the content expandable and show the whole file with the eyes icon

All four should be true.

Notes

It would be great if this could work:

    ```rust,editable
    {{#rustdoc_include  ../code/hello.rs:printl}}
    ```

Or alternatively, a global "editable-by-default" flag in the book.toml:

    ```rust
    {{#rustdoc_include  ../code/hello.rs:printl}}
    ```
[output-html-playground]
editable-by-default = true
@vincevargadev vincevargadev added the C-enhancement Category: Enhancement or feature request label Apr 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement or feature request
Projects
None yet
Development

No branches or pull requests

1 participant