-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Support embedding of rust playpen examples which are runnable #29
Comments
Yes, great idea :) Also, I have not tested extensively, but I think there is no syntax highlighting. I am not sure if the markdown crate I use supports it. Otherwise I will have pre- / post-process or use another markdown parser. |
Ace is the method playpen and rustbyexample use for embedding a text editor which in of itself isn't that difficult. Editor syntax highlighting is handled by ace. All you have to do is choose the theme. Regarding processing, rustbyexample loads the examples from Also, rustbyexample uses a I hope that's helpful. |
Yes, thank you for the explanation. Something that may look like: {{#playpen example.rs}} Would that be ok? Edit: |
I don't think it's important if it is Another thing. rustbyexample uses extensive example sets which must be testable. Currently it's done via the |
I don't really understand what you mean with the second paragraph, could you explain a little bit more? |
All the rustbyexample examples are composed of markdown files and rust files which makes nice documentation. The problem is when when rust is upgraded, some examples may start throwing warnings or errors when they are run because rust has been updated and some rust function was deprecated or renamed. To get around that, the make build system that is used manually searches the examples tree for rust files and compiles them with rustc to test to see if there are any warnings or errors. Part of the problem is I think we could migrate to annotating the examples in the Anyway, what would be really nice is if it was easy to setup so that when the structure of the document was laid out, any rust files which ended up being used got compiled via I hope that is a little more clear. |
Yes I understand know, but isn't that better implemented on their side? My goal is to expose all the functionality as a library (aside from a cli) so on their side they could just add this crate to their dependencies and wrap the build in some function that executes the tests etc.. I am actually just now looking at what I should expose and how, so any feedback on that would be very useful. Once that step is done I work a little bit on the docs and I can publish a first version on Crates.io |
That's why I said it might not be under your control though it'd definitely be handy. Either way, it's probably outside the scope of what you'd want to do currently. |
… function that parses the markdown to find playpen links
… they will be displayed as other code snippets included with markdown backticks except they have a playpen css class
Status update In the {{#playpen files.rs}} They will be displayed as all other code snippets inserted with markdown back ticks, except they have an additional If someone wants to battleproof, that would be awesome! :) What's next? I will begin with non editable but playable rust snippets, the rust code for this should be mostly done. Now it's mainly javascript:
After that we can start working on editable snippets. |
That went a lot faster than expected :) Editable snippets // Non-editable snippet
{{#playpen file.rs}}
// Editable snippet
{{#playpen file.rs editbale}} The non editable snippets are already here, they look the same as normal code snippets except they have a play button. For editable snippets to work there are a couple more things we need:
Most of this should be pretty straightforward, except maybe conditionally include the ace editor if a playpen is detected. |
This sounds pretty great! You should add a quick example to the example docs to show it in practice if you haven't already. I'll have to check it out later. |
Yes, the only problem is that I haven't yet built in a way to escape it, soo I can't show how it is done in the docs yet ;) I will do that now |
Here you go: [Doc - example](http://azerupi.github.io/mdBook/format/rust.html#Inserting runnable Rust files) |
That's so cool! |
@steveklabnik This now offers a hybrid between the book style and the rbe style because of the expansion it allows. For example, here I had to workaround the fact that the example is really huge but the important part is small. The style is to present entire examples so there isn't really a way around it. Compare with say here where the examples are compact but the actually linked to playpen example is basically useless. This would now allow the best of both worlds! This would be much more useful to the book in general but I could still see it being useful for rbe occasionally. Very cool. Once it supports ace, I'd start testing porting rbe to see how it works. I'm not sure I'd switch without search but it'd definitely might be worth considering. |
Oh this is amazing. 👍 |
Has there been any change on this? Is there a way to make this editable yet? If it was, I might attempt a big port of rbe next week (no guarantees because I might be busy though). I think this was the major rbe blocker. |
Not really, I have been very busy with school in the last months so I didn't get the chance to work on this project. I have some experiments in another branch but it doesn't feel right to push all the css and js onto everyone as the majority won't use it. Therefore I wanted to wait until I come up with a plug-in system where you can activate / deactivate features via the configuration file. But this essentially requires a major rewrite. I was poking at it a couple of months back but unfortunately it got sidetracked. Now that the exam period is over I will hopefully have the time again to make progress on the rewrite. |
Sounds good. FWIW, I think cargo can target a specific branch (or at least a specific revision). So if progress was made to the point where rust editing is pretty decent, we could adopt it. At least, there is that possibility. |
Any updates ? |
I'm not aware of any right now, but I'd like to take a crack at it in the future. |
So, re-reading this issue, it looks like everything but editing has been implemented, right? |
Yes, editing like on rust-by-example requires some heavy-weight javascript and with no easy way to let the user choose what he wants I am not comfortable pushing it onto everyone. #163 would be a big step towards implementing this issue. But it requires a lot of thought and it is probably blocked on other issues. We could implement a temporary workaround of course, a special option adding all the necessary JS. |
I don't think it's a huge priority; it'd be nice for once we get to RBE, but that's the only thing that supported it, and is not likely to get worked on for a long time. |
Is there something similar for python |
For example, just like http://rustbyexample.com/
The text was updated successfully, but these errors were encountered: