Not a developer? Go to MovableType.com

Plugin and Theme Directory

GCPrettify v0.5

By Byrne Reese
Posted November 14, 2009, in Developer.

Details

GCPrettify is a plugin designed to allow easy use of Google Code’s prettify.js script for syntax highlighting of code samples.

GCPrettify 0.5 uses the May 21, 2009, release of the prettify.js code.

Features

  • Provides the global MT tag modifier gcprettify which when set will replace all <code> html tags in the output content of the modified MT tag with <code class="prettyprint">.

    Any <code> html tags with an existing class such as <code class="my-example"> or <code class="nopretty"> will not be replaced.

  • Alters the default “Convert Line Breaks” filter by restricting the creation of <br /> and <p> tags within the context of <pre> blocks.

Documentation

Integrate Prettify Functionality

  1. Add the Prettify script and style links to the html <head> element:

    <link href="<$mt:StaticWebPath$>plugins/GCPrettify/prettify.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="<$mt:StaticWebPath$>plugins/GCPrettify/prettify.js"></script>
    
  2. To trigger the styling the prettyPrint() javascript function must be called after the html page has loaded. To do this use one of the following methods after including the above scripts:

    • After the <script> tag loading the mt.js script (which may be in the <head> as well) add the following:

      <script type="text/javascript">mtAttachEvent('load', prettyPrint);</script>
      
    • If using jQuery, add this code after including the jQuery script:

      <script type="text/javascript" charset="utf-8">
          $(document).ready(function() {
              prettyPrint();
          });
      </script>
      
  3. Update template tags outputting content which will contain <code> html tags.

    If <code> html tags will be added in the “body” or “extended” of entries, search the Movable Type templates for these tags:

    <$mt:EntryBody$>
    <$mt:EntryExtended$>
    

    Update these tags with the gcprettify attribute and a true value:

    <$mt:EntryBody gcprettify="1"$>
    <$mt:EntryExtended gcprettify="1"$>
    

    Save the templates.

  4. Create a new entry and paste the following code into the body of the entry:

    <pre><code>
    /* calculate nth fibonacci number */
    int fib(int n) {
        if (n < 2)
            return 1;
        return fib(n - 2) + fib(n - 1);
    }
    </code></pre>
    
  5. Publish and view entry.

    The “prettyPrint” JavaScript function called on load will then detect all <code> tags with the “prettyprint” class, parse their contents, and the appropriate span elements for syntax highlighting.

    Further details on the operations of this script are available at the google-code-prettify page.

    View the page html source and you’ll see that MT has updated the <code> html tag with the “prettyprint” class:

    <pre><code class="prettyprint">
    /* calculate nth fibonacci number */
    int fib(int n) {
        if (n < 2)
            return 1;
        return fib(n - 2) + fib(n - 1);
    }
    </code></pre>
    

Styling <code> HTML Tags in Other Templates

Because the prettify.js script will “prettify” any <code> tag which has the “prettyprint” class, any <code> blocks which have the “prettyprint” class in the published html source code will be “prettified” upon page load.

In index templates manually add the “prettyprint” class to all <code> html elements:

<pre><code class="prettyprint">
document.write('<b>Hello World</b>');
</code></pre>

Installation

  1. Move the GCPrettify plugin directory to the MT plugins directory.
  2. Move the GCPrettify mt-static directory to the mt-static/plugins directory.

Should look like this when installed:

$MT_HOME/
    plugins/
        GCPrettify/
    mt-static/
        plugins/
            GCPrettify/

Desired Features

  • Blog-level overrides of the default GCPrettify style sheet
  • Alteration of “Convert Line Breaks” filtering only within tags affected by the gcprettify tag modifier

Support

This plugin is not an official Six Apart release, and as such support from Six Apart for this plugin is not available.

Compatibility

Movable Type versions: 4.3

License

Perl Artistic


Back

55 Comments

nish gau

nish gau on September 18, 2016, 11:56 a.m. Reply

Hi Byrne, Thanks for sharing such informative posts. It helped me a lot. Awesome plugin details explained in your article above. keep posting. Thanks. instagram follower

Brayan Meadows

Brayan Meadows on May 26, 2017, 4:49 p.m. Reply

I think Byrne is one of the reasons why I have stayed with MT as my CMS of choice. There are a lot of other options out there that give you the chance to publish to the web, MT is the easiest, most feature filled option there is in my opinion. And this is due to no small contribution by Byrne. I have used it here on rusticweddinginvitations.xyz since day one and I couldn’t be happier about the decision.

nish gau

nish gau on September 18, 2016, 11:58 a.m. Reply

Hi Byrne, Thanks for sharing such informative posts. It helped me a lot. Nice coding explained. Awesome plugin details explained in your article above. keep posting. Thanks. instagram follower

avaya duggu

avaya duggu on March 17, 2017, 5:58 a.m. Reply

amazing information thank you sharing this information easter day images pictures easter egg images

avaya duggu

avaya duggu on March 17, 2017, 5:59 a.m. Reply

amazing information thank you for sharing this information easter day images pictures easter egg images

joelle

joelle on May 10, 2017, 8:51 a.m. Reply

Bienvenue pour la visite de mon site ! Quelques altérations communes pour une robe pour un mariage qui ne rentre pas. J’espère que vous apprécierez tous les jours avec moi dans ce petit espace !

johnrosner

johnrosner on June 7, 2017, 3:57 a.m. Reply

Excellently written article, if only all bloggers offered the same level of content as you, the internet would be a much better place. Please keep it up! 192.168.o.1 192.168.l.254

rosario

rosario on June 26, 2017, 5:49 p.m. Reply

Comment bien choisir sa scie, sur http://scie-info.fr

Jean Chrysostome

Jean Chrysostome on July 20, 2017, 2:05 p.m. Reply

Tres bon site pour les plans culs et autre rencontres bien coquines, egalement un site pour savoir faire l’amour a sa meuf, et un site pour lui acheter un bijoux magique après la baise! Tes refait mec!

Jean Chrysostome

Jean Chrysostome on July 20, 2017, 2:06 p.m. Reply

Tres bon site pour les plans culs et autre rencontres bien coquines,

Radjapov

Radjapov on January 26, 2018, 7:17 a.m. Reply

You will be asked for your iTunes account information through an In App purchase. http://downloadallfilesnow.gdn Mark your favorite quotes to easily access them later.

james

james on February 27, 2018, 5:33 a.m. Reply

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. herbalife diet

james

james on March 1, 2018, 12:23 p.m. Reply

Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it’s nice to find a website that details so much information about different artists.

james

james on March 3, 2018, 8:30 p.m. Reply

The ideas that you have shared on this blog can be easily discussed on chat social network. It is blogs like these which make the writing world even more fun bespoke suits philadelphia

james

james on March 10, 2018, 12:18 p.m. Reply

I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share. lawn mowing

james

james on March 10, 2018, 12:18 p.m. Reply

Wonderful article, thanks for putting this together! This is obviously one great post. Thanks for the valuable information and insights you have so provided here. lawn mowing

hendry

hendry on November 28, 2018, 10:52 a.m. Reply

GCPrettify v0.5 it is plugin used for google codes. The code samples and its syntax is mentioned here. The documentation and its compatibility are mentioned here. The installation steps are details mentioned here.more helpful hints

lunami

lunami on March 23, 2019, 9:00 p.m. Reply

It is rather very good, nevertheless glance at the data with this handle. ถุงยางแบบบาง

wahid

wahid on March 27, 2019, 4:12 p.m. Reply

Any time you are browsing the web quite often I have discovered a web site which may be rather thought invoking like this one. Best Hairdressers Brisbane

wahid

wahid on April 3, 2019, 10:37 p.m. Reply

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more … good luck. Asbestos surveys Portsmouth

wahid

wahid on April 3, 2019, 10:41 p.m. Reply

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here. професионално почистване варна

wahid

wahid on April 3, 2019, 10:53 p.m. Reply

It has fully emerged to crown Singapore’s southern shores and undoubtedly placed her on the global map of residential landmarks. I still scored the more points than I ever have in a season for GS. I think you would be hard pressed to find somebody with the same consistency I have had over the years so I am happy with that. детски лагери от варна

wahid

wahid on April 8, 2019, 3:23 p.m. Reply

Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written. 안전공원

wahid

wahid on April 17, 2019, 5:12 p.m. Reply

I am overwhelmed by your post with such a nice topic. Usually I visit your blogs and get updated through the information you include but today’s blog would be the most appreciable. Well done! 토토사이트

lunami

lunami on April 17, 2019, 6:32 p.m. Reply

So it is interesting and very good written and see what they think about other people. 여유증 수술

wahid

wahid on April 20, 2019, 4:16 p.m. Reply

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here. 바카라사이트

wahid

wahid on April 20, 2019, 11:27 p.m. Reply

For many people this is important, so check out my profile: 토토사이트

wahid

wahid on April 21, 2019, 12:05 a.m. Reply

I should say only that its awesome! The blog is informational and always produce amazing things. 룸알바

wahid

wahid on April 28, 2019, 4:09 a.m. Reply

I frequently take joy in locating a website that delivers very good information as I like finding out new stuff. I desired to share that I found the content on your web site was rather entertaining and I also learnt something new. An awesome site and I will be back once more for further great content… tarot reading

wahid

wahid on April 29, 2019, 4:05 p.m. Reply

Typically when I browse the ‘net I try to look for web-sites which provide good information so I found this web site. Very often that I have been to this particular site I’ve truly took pleasure in the nice article here. I’ll be certain to look out for the following post.. Thanks for this fantastic posting I am going to come back in the future. social media marketing columbus

wahid

wahid on May 3, 2019, 2:20 a.m. Reply

Whilst surfing the web in some cases I have found a site that is definitely very thought invoking like this one. I want to express that I found the content within your site has been pretty enjoyable and I also learnt new things. I’ll be sure to watch out for the following article.. Thanks for the fantastic write-up I will return in the future. Exchange Bangkok

wahid

wahid on May 5, 2019, 6:44 p.m. Reply

Wow! Such an amazing and helpful post this is. I really really love it. It’s so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also. NBR Stylist in Northeast Ohio

wahid

wahid on May 14, 2019, 2:32 a.m. Reply

Why do only so much written on this subject? Here you see more. 카지노사이트

wahid

wahid on May 21, 2019, 6:12 p.m. Reply

Profit primarily prime quality items — you can understand them all within: voyance par telephone direct

maxxjohnson

maxxjohnson on May 22, 2019, 2:12 p.m. Reply

Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. Escorts in lahore

wahid

wahid on May 23, 2019, 4:30 p.m. Reply

You should mainly superior together with well-performing material, which means that see it: business analyst training

wahid

wahid on May 23, 2019, 4:33 p.m. Reply

On that website page, you’ll see your description, why not read through this. bird videos

wahid

wahid on May 23, 2019, 4:34 p.m. Reply

This is exciting, nevertheless it is vital for you to visit this specific url: Medical Assistant Course

wahid

wahid on May 23, 2019, 4:39 p.m. Reply

This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. SEO consultant

bluepine

bluepine on June 30, 2019, 9:51 p.m. Reply

Your site has a very interesting contents and issues for me! Thank you for mentioning such problems. Our site also has a similar contents to yours. Please visit our site. Thanks regards. 먹튀폴리스 119 성인웹툰,무료웹툰

wahid

wahid on August 17, 2019, 2:15 p.m. Reply

I encourage you to read this text it is fun described … 카지노사이트

wahid

wahid on August 18, 2019, 10:47 a.m. Reply

Amazing, this is great as you want to learn more, I invite to This is my page. 바카라사이트

betmable

betmable on August 22, 2019, 5:19 a.m. Reply

먹튀검증

Italian national striker Luca Toni, who joined Ribéry in the same year as Ribéry, is known to highly recommend Fiorentina. Tony played for Fiorentina twice before joining Munich and shortly before retiring. Ribéry said, “After looking around Tony and Fiorentina, we decided to join. I thought I could adapt if I didn’t perfect Italy. ”

betmable

betmable on August 22, 2019, 5:20 a.m. Reply

먹튀검증 Italian national striker Luca Toni, who joined Ribéry in the same year as Ribéry, is known to highly recommend Fiorentina. Tony played for Fiorentina twice before joining Munich and shortly before retiring. Ribéry said, “After looking around Tony and Fiorentina, we decided to join. I thought I could adapt if I didn’t perfect Italy. ”

chance999

chance999 on August 23, 2019, 10:01 a.m. Reply

Want a lot of information about casinos and baccarat? Then visit our site once 인터넷카지노

wahid

wahid on August 25, 2019, 11:17 a.m. Reply

This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. Bitcoin Price

amineaeyjay1009

amineaeyjay1009 on September 3, 2019, 8:52 a.m. Reply

Dreams are essential. It is only when you dream big with all your heart you will be able to achieve big. As students our dream is to achieve good marks, have good friends, get support from the family and make it big in life.바카라사이트프로

amineaeyjay1009

amineaeyjay1009 on September 3, 2019, 8:52 a.m. Reply

Dreams are essential. It is only when you dream big with all your heart you will be able to achieve big. As students our dream is to achieve good marks, have good friends, get support from the family and make it big in life.바카라사이트프로

wahid

wahid on September 6, 2019, 6:28 a.m. Reply

Three are usually cheap Ralph Lauren available for sale each and every time you wish to buy. Malta Real Estate

wahid

wahid on September 14, 2019, 12:42 p.m. Reply

I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you! refrigerator technician

wahid

wahid on September 25, 2019, 5:22 a.m. Reply

This is very appealing, however , it is very important that will mouse click on the connection: Situs Judi Slot Online

wahid

wahid on October 2, 2019, 5:18 a.m. Reply

This post is really magnificent. I really like this post. It is one of the best posts that I ve read in a long time. Thanks a lot for this really good post. I really appreciate it! software development companies ukraine

wahid

wahid on October 6, 2019, 7:09 a.m. Reply

Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing… 카지노사이트주소

wahid

wahid on October 12, 2019, 7:47 a.m. Reply

It’s late finding this act. At least, it’s a thing to be familiar with that there are such events exist. I agree with your Blog and I will be back to inspect it more in the future so please keep up your act. ray ban wayfarer screw

Leave a Comment

Byrne Reese

Byrne Reese was previously the Product Manager of Movable Type at Six Apart, where he had also held positions as the Manager of Platform Technology and Product Manager for TypePad. Byrne is a huge supporter of the Movable Type user and developer community. He dedicates much of his time to promoting and educating people about Movable Type as well as building the tools and plugins for Movable Type that are showcased on Majordojo. He contributes regularly to open source; and he is an advocate for open protocols and standards like Atom and OpenID.

Website: http://profile.typekey.com/byrnereese