Times we need to snip some code into HTML. A few method we can use.
One is using gist.github.com login with you GitHub ID and create snippet. Copy script and add to HTML.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<script src="https://gist.github.com/username/f12ae1f2ds1f21ds2f1ds.js"></script> | |
</body> |
Second is using highlight.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre><code class="javascript"> | |
$(document).ready(function() { | |
$('pre code').each(function(i, block) { | |
hljs.highlightBlock(block); | |
}); | |
}); | |
</code></pre> | |
<link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/default.min.css" rel="stylesheet"></link> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/highlight.min.js"></script> | |
<script>hljs.initHighlightingOnLoad();</script> |
No comments:
Post a Comment