CppLangNet
CppLangNet copied to clipboard
Godbolt links for code snippets
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.
I think there are two things here:
- 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.
- 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=
I may take this on depending on how I easy/difficult I find working with Docusaurus.
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.
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.