-9

For context I see a lot of new users who fail to realize there is a runnable inline code snippet feature that lets them have a running example.

Now unfortunately I don't know if there is a better way of actually getting users to use the feature and I don't think the goal is to do this. However, I have edited a bunch of questions/answers where I basically add this example in for them. They already have all the HTML/CSS/JavaScript separated out so its just tediously copying and pasting.

Is there anyway we can make it so when you use the stack snippet feature it can just copy the code related snippets that already exist in the answer/question you are editing? How it would do this is it could just see what code is already in the question based on the formatting.

It would be really nice if it could discern HTML vs CSS vs JavaScript and put them in the correct boxes (should be possible but if that's too much work, even just shoving it into an area to let editors move the code snippets into the correct boxes would be more than enough).

I think the only concern people might have is the fact that people might not always want to inject the code they have in the question/answer when adding a code snippet -- that's fine because it's really easy to just delete whatever is in there and then they should know to not add the existing code example as a snippet.

One last thing to mention is that this might just end up having people inject stack snippets that aren't runnable because naturally they don't work. I think that's still okay though because the stack snippet still makes it easier for answers to copy their snippets so they can edit/fix them

Related questions (although they don't seem to answer my question):

Automatic detection of copied code

Code Snippet as a formatting tool

Stack Snippets being misused

5
  • 1
    It would be difficult to tell the difference between, say, C# code and JavaScript under many circumstances. I don't think it's okay to have a Stack Snippet for non-runnable code (especially when they are not HTML, CSS, or JS; I find it really annoying, because then I feel like I need to edit it to remove the snippet so that people aren't clicking on Run code snippet and expecting something to happen. May 8, 2017 at 19:05
  • That's a fair argument @MikeMcCaughan
    – aug
    May 8, 2017 at 19:36
  • @MikeMcCaughan It's not that hard to look into the tags. The syntax highlighting already relies on the language tags added to the question. // About the request: This feature shouldn't work automatically (i.e. shouldn't generate that snipped automatically). It would be enough when it suggests to use Stack Snippet with a working example and the editor/OP can decided if (s)he wants to use it or not.
    – Tom
    May 9, 2017 at 0:11
  • I didn't read through but instantly understood that YES of course it is possible to take a functional webpage (all in one index.html) and drop it down to be detected, so that it automatically take out HTML, CSS and JS from it.
    – user985399
    May 6, 2019 at 0:17
  • From my understanding, a lot of the complaints are related to how feasible it is to distinguish different programming languages solely from syntax and there would be a lot of overhead. I find that an acceptable "reason" to not implement this if we aren't confident we can do it right.
    – aug
    May 7, 2019 at 20:28

1 Answer 1

10

Please don't implement this

This would add needless complication to the existing system and it would probably be extremely difficult to create a reliable implementation. We would probably have constant bug reports about it selecting the wrong code, or not selecting the right code, when right now you only need a maximum of three cuts and three pastes to make a runnable snippet from a code sample.

You can even do it without closing the snippet editor:

  • Cut all three code samples out at once
  • Open the snippet editor
  • Paste all three code samples into the first section
  • Cut the remaining two samples and paste them into the appropriate sections
  • Select Save & insert into post

This answer assumes that you know code samples that are not runnable should not be in snippets.

2
  • Well the goal would be that it wouldn't be an unreliable implementation but you make a fair point that a lot of code samples that aren't runnable shouldn't be snippets so this would only apply to web related snippets which makes it seemingly not worth it. I was thinking they could do something clever like look at the tag to know when to trigger the feature but I can see how that's not very reliable either. I'll go ahead and accept this answer.
    – aug
    May 8, 2017 at 19:38
  • It is not complicated at all to parse <style>, <script> and <html> and concatenate all styles in one, alls scripts in one and the rest of html in one. I should not feed the trolls with arguments to copy paste, but there can be a document.write in a script, but if the auto insert of code does not work it should still be possible make it in old fashion.
    – user985399
    May 6, 2019 at 0:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .