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

[Docs] Implement code examples to be opened/importable in Remix #11415

Open
franzihei opened this issue May 19, 2021 · 7 comments
Open

[Docs] Implement code examples to be opened/importable in Remix #11415

franzihei opened this issue May 19, 2021 · 7 comments

Comments

@franzihei
Copy link
Member

@franzihei franzihei commented May 19, 2021

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.

@cameel
Copy link
Member

@cameel cameel commented May 19, 2021

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.

@cameel
Copy link
Member

@cameel cameel commented May 19, 2021

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.

@franzihei
Copy link
Member Author

@franzihei franzihei commented May 20, 2021

Just talked to Yann about this. He said the easiest way would be to write a script to do the following:

  1. Take the Solidity code
  2. Encode it (https://www.base64encode.org/)
  3. Go to remix.ethereum.org/?code=[encoded code here]

We could probably write some automation to do this, or?

@cameel
Copy link
Member

@cameel cameel commented May 20, 2021

  1. Go to remix.ethereum.org/?code=[encoded code here]

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.

@chriseth
Copy link
Contributor

@chriseth chriseth commented May 20, 2021

Oh nice! New we only need to find out how to add the appropriate buttons / links to the documentation.

@chriseth chriseth added this to New issues in Solidity via automation May 20, 2021
@chriseth chriseth moved this from New issues to Implementation Backlog Important in Solidity May 20, 2021
@cameel
Copy link
Member

@cameel cameel commented Jul 1, 2021

@hrkrshnn's suggestion from #11605 (comment) might be useful for finding these snippets:

Was wondering if there was a sphinx extension that could help here. Found https://www.enricozini.org/blog/2020/python/checking-sphinx-code-blocks/

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Solidity
  
Implementation Backlog Important
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants