9

I often format answers something like

Do this

var a = b * c;

Then do this

log("the answer is " + a);

Is it possible to pull those lines separately out of a snippet of say 10 lines to include in the answer?

For example maybe the full snippet is

var log = function(msg) {
  var div = document.createElement("div");
  div.appendChild(document.createTextnode(msg));
  document.body.appendChild(div);
};

var b = 12;
var c = 34;

var a = b * c;

log("the answer is " + a);

It might be really nice to be able to mark up the snippet and then insert it in parts into the answer like maybe the snippet might look like this

var log = function(msg) {
  var div = document.createElement("div");
  div.appendChild(document.createTextnode(msg));
  document.body.appendChild(div);
};

var b = 12;
var c = 34;

<!-- snippet#abc -->
var a = b * c;

<!-- snippet#answer -->
log("the answer is " + a);

<!-- snippit#end -->

And the markdown might look something like

Do this

![snippit#abc]

Then do this

![snippit#answer]


...full snippet source down here...

Thoughts? Seems like it would be very D.R.Y. and less error prone. You wouldn't have to fix two places if you come back and make an edit to the code.

1
  • 1
    +1 for the concept of highlighting the most relevant parts of a snippet. This is a much better version of my request here: meta.stackoverflow.com/questions/271762/… But I was going to repeat things; something like this is the better way. Commented Sep 29, 2014 at 8:26

1 Answer 1

1

This is a great idea. In case if that is an overkill, something simpler like:

     <!-- language: lang-js -->
        // code
     <!-- language: lang-js:break -->

Your explanation for the code above.

     <!-- language: lang-js:continue -->
        // rest of the code
     <!-- language: lang-html -->

will do, IMHO

You must log in to answer this question.

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