leptos-rs / book

The home for the Leptos book, which can be found deployed at https://book.leptos.dev
MIT License
89 stars 68 forks source link

Add custom admonition for code sandbox #95

Closed anvlkv closed 6 months ago

anvlkv commented 6 months ago

This PR adds custom admonition for mdbook-admonish, addressing the #1

It can be used in the book like this:

    ```admonish sandbox title="Live example" collapsible=true
    [Click to open CodeSandbox.](https://codesandbox.io/p/sandbox/1-basic-component-3d74p3?file=%2Fsrc%2Fmain.rs%3A1%2C1)
    <noscript>
      Please enable JavaScript to view examples.
    </noscript>
    <template>
      <iframe src="https://codesandbox.io/p/sandbox/1-basic-component-3d74p3?file=%2Fsrc%2Fmain.rs%3A1%2C1" width="100%" height="1000px" style="max-height: 100vh"></iframe>
    </template>


There's also some styling of an expanded block making it wider on large screens.
gbj commented 6 months ago

Wow! That looks really nice.

anvlkv commented 6 months ago

No worries, happy to be of help :)

gbj commented 6 months ago

Thank you!

anvlkv commented 6 months ago

Hi, I see that it stopped inserting the template since the class name changed...

Has to be updated in the sandbox.js as well https://github.com/leptos-rs/book/pull/95/files#diff-f7e2d2c7fe483804ec618762331b0ca33fa535b68c06fd41944298e093c4c4a7R2

anvlkv commented 6 months ago

Or maybe I missed something?

On https://book.leptos.dev/view/01_basic_component.html it appears without the 'admonition-sandbox' class.

paul-hansen commented 6 months ago

Seems like it's using the admonish-note styling too instead of the new admonish-sandbox

How it looks running latest main branch locally (looks correct): image

How it looks on https://book.leptos.dev/view/01_basic_component.html image

paul-hansen commented 6 months ago

Ohh! The github action is using mdbook-admonish v0.14.0 and custom directives were added in v0.15.0. Probably just need to update that in the action here: https://github.com/leptos-rs/book/blob/40774ab8b5e563253380e23e3c73761cff07fc1c/.github/workflows/publish_mdbook.yml#L43-L46

anvlkv commented 6 months ago

Oeps, didn't know.

I hope you can update it

paul-hansen commented 6 months ago

Opened a PR here: #96

Actually Greg got it at the same time: https://github.com/leptos-rs/book/pull/97 :heart: