CppLangNet icon indicating copy to clipboard operation
CppLangNet copied to clipboard

Godbolt links for code snippets

Open breyerml opened this issue 2 years ago • 3 comments

It would be a nice improvement if you could add an additional button (besides the copy button) that directly opens the current code snippet in a new https://godbolt.org/ tab.

breyerml avatar Sep 19 '22 15:09 breyerml

I think there are two things here:

  1. UI: How the button will end up looking and the specific implementation we want. Should this be an optional feature so that a button shows up next to the copy one for this or should this be an ellipsis on the code block which shows an option to open this up in godbolt.
  2. How to open this up in godbolt: As per the godbolt API. We can base 64 encode a client state and have that open up.

For example

{
  "sessions": [
    {
      "id": 1,
      "language": "c++",
      "source": "// Hello from ellipse0934 \n int main() { return 42; }",
      "compilers": [
        {
          "id": "g82",
          "options": "-O3"
        }
      ],
      "executors": [
        {
          "arguments": "arg1",
          "compiler": {
            "id": "g92",
            "libs": [],
            "options": "-O3"
          },
          "stdin": ""
        }
      ]
    }
  ]
}

Will produce https://godbolt.org/clientstate/eyJzZXNzaW9ucyI6W3sic291cmNlIjoiLy8gSGVsbG8gZnJvbSBlbGxpcHNlMDkzNCBcbiBpbnQgbWFpbigpIHsgcmV0dXJuIDQyOyB9IiwiZXhlY3V0b3JzIjpbeyJzdGRpbiI6IiIsImFyZ3VtZW50cyI6ImFyZzEiLCJjb21waWxlciI6eyJvcHRpb25zIjoiLU8zIiwiaWQiOiJnOTIiLCJsaWJzIjpbXX19XSwiaWQiOjEsImxhbmd1YWdlIjoiYysrIiwiY29tcGlsZXJzIjpbeyJvcHRpb25zIjoiLU8zIiwiaWQiOiJnODIifV19XX0=

image

I may take this on depending on how I easy/difficult I find working with Docusaurus.

Ellipse0934 avatar Nov 29 '23 17:11 Ellipse0934

UI: How the button will end up looking and the specific implementation we want. Should this be an optional feature so that a button shows up next to the copy one for this or should this be an ellipsis on the code block which shows an option to open this up in godbolt.

I think a button similar to the one that copies code to the clipboard will be good. We already have "Toggle full code" button implemented this way.

How to open this up in godbolt: As per the godbolt API. We can base 64 encode a client state and have that open up.

Compiler explorer can generate short link for any setup. We use it for example on our front page.

PoetaKodu avatar Nov 29 '23 18:11 PoetaKodu

If we use short link we will have to generate shortlinks as part of the build. Not sure if such a dependency is necessary. Maybe this should be an optional in the build process.

Ellipse0934 avatar Nov 29 '23 18:11 Ellipse0934