Skip to content

Instantly share code, notes, and snippets.

@pikesley
Created March 14, 2016 14:50
Show Gist options
  • Save pikesley/eee3ebb37ba0d6e8c922 to your computer and use it in GitHub Desktop.
Save pikesley/eee3ebb37ba0d6e8c922 to your computer and use it in GitHub Desktop.
Embed your README

Easily embed your README.md as documentation

  • Disregards everything before the first # Heading
  • Requires kramdown
<div class='row'>
<div class='col-md-3'></div>
<% lines = File.read('README.md').split("\n") %>
<% interesting_index = lines.index { |s| s =~ /^#/ } %>
<% good_parts = lines[interesting_index..-1] %>
<% good_parts[0] = good_parts[0] + " <button data-toggle='collapse' data-target='#readme' class='btn btn-info read-docs pull-right'>Show documentation <i class='fa fa-arrow-circle-down'></i></button>" %>
<div class='col-md-6 well docs'>
<div id='heading'>
<%= Kramdown::Document.new(good_parts[0..2].join("\n")).to_html %>
</div>
<div id='readme' class='collapse'>
<%= Kramdown::Document.new(good_parts[3..-1].join("\n")).to_html %>
</div>
</div>
<div class='col-md-3'></div>
</div>
<script>
$('.read-docs').click(function(){
var $this = $(this);
$this.toggleClass('read-docs');
if($this.hasClass('read-docs')){
$this.html('Show documentation <i class="fa fa-arrow-circle-down"></i>');
} else {
$this.html('Hide documentation <i class="fa fa-arrow-circle-up"></i>');
}
});
</script>
#readme img {
width: 100%;
}
.docs {
margin-top: 30px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment