Background
When answering questions on SO I generally like to ensure that my code is runnable by including sample data, so someone can copy, paste, and run it, seeing exactly what I'd proposed.
However, often this setup code takes up a lot of space before the code of interest, so I have to put the interesting code in my answer, followed by a runnable example with the full code.
Example of such an answer: Match any patterns in a table?
Suggestion
Have a way to collapse/hide code which is superfluous to the answer, but can be expanded.
var viewModel = function() {
this.expanded = ko.observable(false);
this.notexpanded = ko.observable(true);
this.toggle = function () {
this.expanded(!this.expanded());
this.notexpanded(!this.expanded());
};
};
ko.applyBindings(new viewModel());
.expand {
color: red;
background-color: lightgrey;
}
.collapsible {
background-color: lightgrey;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<pre data-bind="visible: expanded, click: toggle" class="collapsible">
declare @patterns table
(
pattern nvarchar(16) not null
)
declare @data table
(
datum nvarchar(16) not null
)
insert @patterns
values ('host1%')
,('%host2')
insert @data
values ('host1234')
, ('234host1')
, ('host2345')
, ('345host2')
</pre>
<a class="expand" href="#" data-bind="visible: notexpanded, click: toggle">-Expandible for Code Context-</a>
<pre>
select *
from @data
where not exists
(
select top 1 1
from @patterns
where datum like pattern
)
</pre>
Ironically I've used Code Snippets to demonstrate the functionality I'm describing (run the above to see); the difference being the above code-snippet is used to embed executable code into a post, whilst I'm only suggesting having the show-hide aspect of this feature (since this could be implemented in a language independent way, and for little effort).
Javascript/HTML/CSS Snippet (Ctrl+M)
; used to add runnable samples. If you mean the sample code in that snippet, that uses knockout.js (stackoverflow.com/questions/10577326/…). If something else, please let me know.CTRL+M
to do that kind of stuff. I support your request, however, as it would shorten A LOT of long questions by new users.<!-- begin snippet: js hide: true -->
stuff-to-hide<!-- end snippet -->
/