Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 495901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:38:07+00:00 2026-05-13T05:38:07+00:00

I’m using blogger.com to host some texts on programming, and I’d like to use

  • 0

I’m using blogger.com to host some texts on programming, and I’d like to use Prettify (same as Stack Overflow) to nicely colour the code samples.

How do I install the Prettify scripts into the blog domain?
Would it be better (if indeed it’s possible) to link to a shared copy somewhere?
I have webspace on a different domain. Would that help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:38:07+00:00Added an answer on May 13, 2026 at 5:38 am

    When you make a new entry in Blogger, you get the option to use HTML in your entry and to edit your blog entries.

    So type http://blogger.com, log in, and navigate to Posting → Edit Posts → Edit. In there put this at the top:

    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/lang-css.min.js"></script>
    <script type="text/javascript">
    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          if (oldonload) {
            oldonload();
          }
          func();
        }
      }
    }
    addLoadEvent(function() {
        prettyPrint();
    });
    </script>
    <style type="text/css">
    /* Pretty printing styles. Used with prettify.js. */
    
    .str { color: #080; }
    .kwd { color: #008; }
    .com { color: #800; }
    .typ { color: #606; }
    .lit { color: #066; }
    .pun { color: #660; }
    .pln { color: #000; }
    .tag { color: #008; }
    .atn { color: #606; }
    .atv { color: #080; }
    .dec { color: #606; }
    pre.prettyprint { padding: 2px; border: 1px solid #888; }
    
    @media print {
      .str { color: #060; }
      .kwd { color: #006; font-weight: bold; }
      .com { color: #600; font-style: italic; }
      .typ { color: #404; font-weight: bold; }
      .lit { color: #044; }
      .pun { color: #440; }
      .pln { color: #000; }
      .tag { color: #006; font-weight: bold; }
      .atn { color: #404; }
      .atv { color: #060; }
    }
    </style>
    

    Note that you shouldn’t use prettyPrint directly as an event handler. It confuses it (see the readme for details). Which is why we’re passing addLoadEvent a function that then turns around and calls prettyPrint.

    In this case, because Blogger does not allow us to link to the stylesheet, we just embed the prettify.css contents.

    Then add a <code></code> tag or a <pre></pre> tag with the class name of "prettyprint". You can even specify the language like "prettyprint lang-html".

    So it can look like this:

    <pre class="prettyprint lang-html">
    <!-- your code here-->
    </pre>
    

    Or like this:

    <code class="prettyprint lang-html">
    <!-- your code here-->
    </code>
    

    The code that you put in needs to have its HTML cleaned from < and >. To do this, just paste your code in here: https://www.freeformatter.com/html-escape.html

    You can put the top code in your HTML layout, so that it’s included for all pages by default if you like.

    As of 2012, you can link CSS files in Blogger, so adding this to the <head> should be enough:

    <link href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/lang-css.min.js"></script>
    <script type="text/javascript">
        document.addEventListener('DOMContentLoaded',function() {
            prettyPrint();
        });
    </script>
    

    I chose not to replace the body onload event on purpose. Instead, I’m using the new DOMContentLoaded event that the old browsers don’t support. If you need old browser support, you can use any other load event to initiate prettyPrint, for example jQuery:

    jQuery(function($){
        prettyPrint();
    });
    

    Or the supposedly smallest domready ever

    And you’re done 🙂

    As Lim H pointed out in the comments, in case where you use the Blogger dynamic views (Ajax templates) then you need to use the method described here to bind custom JavaScript code: prettyPrint() doesn't get called on page load

    Use the guide at GitHub: https://github.com/google/code-prettify

    Basically just use this 🙂

    <script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/run_prettify.min.js"></script>
    <pre class="prettyprint"><code class="language-css">...</code></pre>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.