Displaying code snippet in Blogger posts using Github Gist files and associated embed links (script tags)

Display code snippet in blogger, https://www.dotnetexample.in/2018/09/display-code-snippet-in-blogger.html . The article covers how to use Github gist facility to create code snippets/files and that on save, it provides an embed link (script tag) which can be inserted in blogger post (in HTML mode).

When I tried it first, Blogger complained that the HTML is invalid but on saving it, it worked. However, later I did not face such errors when I replaced the script tag or added a new script tag. As I was trying out code and pre tags earlier on, perhaps it was some of that code that triggered the Blogger warnings. On switching to Compose mode, the script tag and associated code are not shown but can be viewed by switching back to HTML mode (preview post shows the code snippet). On viewing the blogger post, the script tag does a great job of showing the associated code and a link to view the code file (raw) in a separate window. While there is no copy code button shown on the blogger post, one can manually select all the code in the snippet and copy it, or open it in a separate window (raw link) and then use Ctrl+A to select all and then copy all the code.

Note that WordPress post editor has a nice code block feature where one insert code. Blogger does not seem to have an equivalent and so one has to explore alternatives like using Github Gist and its embed link feature.

Some readers may also want to visit my related post: Test HTML code snippet shown using xmp (deprecated), pre and code tags, https://raviswdev.blogspot.com/2024/02/test-html-code-snippet-in-blogger.html .

Comments