Adding code snippets to your blog
When writing technical articles about programming, one needs to add code
snippets for reference from time to time. The following post highlights two
methods I find both simple and easy to use.
hilite.me converts your code
snippets into pretty-printed HTML format, easily embeddable into blog posts,
emails and websites.
Just copy the source code to the left pane, select the language and the
color scheme, and click "Highlight!". The HTML from the right pane
can now be pasted to your blog or email, no external CSS or Javascript files
are required.
Github Gist
Think of a Gist as a single source controlled file that can be edited,
cloned and shared easily. This is one of my favorite options for sharing small
code snippets. It has the added advantage of being version controlled as well.
Instructions
1- Click on gist.github.com2- If you have a github account (which you should) sign in. Start by adding a file name for your gist; the syntax highlighting will automatically be detected by the extension:
3- Make sure to create the gist as "public". Once you do so,
you'll see a "embed this gist" link ont he left hand side in the
following format:
<script src="https://gist.github.com/<user_id>/<gist_id>.js"/>
<script src="https://gist.github.com/<user_id>/<gist_id>.js"/>
4- Copy that and embed it in your blog. Here is an example with some ruby
code:
No comments:
Post a Comment
Add Comment