[Docs] Implement code examples to be opened/importable in Remix #11415
Comments
We already have a script that extracts all the snippets from the docs and I see that Remix can load files from various sources (gists, github repos, IPFS, Swarm) so we would just have to create a CI job that uploads the extracted snippets somewhere on new release. Then the problem is how to link to them directly. Looks like you can tell Remix to load a specific gist, e.g. https://remix.ethereum.org/#gist=1b737742a93f9035baefc074ac2979ca. Not sure about github, IPFS or other options. Unfortunately you have to click the file on the list to see it - it shows the start page by default. There are some URL parameters for hiding panels but I don't see anything that would make it switch to the editor immediately. |
We would also need something to automatically insert links to individual snippets next to them in the docs. I did a quick search but I could not find any tool that would do it for us out of the box. I'm afraid we might have to create a custom Sphinx plugin to do that. I found one that might serve as a base: sphinxawesome-codelinter. It's a linter that finds and processes all the code snippets. We would need to modify it to not only traverse the doctree but also insert the generated links. |
Just talked to Yann about this. He said the easiest way would be to write a script to do the following:
We could probably write some automation to do this, or? |
This is solved with the encoded code option, where you land directly in the editor, e.g. see: https://remix.ethereum.org/?code=Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IEdQTC0zLjAKcHJhZ21hIHNvbGlkaXR5ID49MC40LjE2IDwwLjkuMDsKCmNvbnRyYWN0IFNpbXBsZVN0b3JhZ2UgewogICAgdWludCBzdG9yZWREYXRhOwoKICAgIGZ1bmN0aW9uIHNldCh1aW50IHgpIHB1YmxpYyB7CiAgICAgICAgc3RvcmVkRGF0YSA9IHg7CiAgICB9CgogICAgZnVuY3Rpb24gZ2V0KCkgcHVibGljIHZpZXcgcmV0dXJucyAodWludCkgewogICAgICAgIHJldHVybiBzdG9yZWREYXRhOwogICAgfQp9 |
Oh, I did not know it can do that. This seems to be an undocumented query parameter. I originally wanted to suggest something like that (e.g. https://godbolt.org has something similar for C++) but I thought this feature does not exist in Remix. If it does then great. |
Oh nice! New we only need to find out how to add the appropriate buttons / links to the documentation. |
@hrkrshnn's suggestion from #11605 (comment) might be useful for finding these snippets:
We still need a way to append to them though. In the worst case we can just rewrite the .rst files but would be better if it could be done via the Sphinx API. |
It would be nice to be able to directly open the code examples in the Solidity documentation in Remix (e.g. by clicking "open in Remix").
We need to find out how that would be possible in Remix.
The text was updated successfully, but these errors were encountered: