SlideShare a Scribd company logo
Code Syntax Highlighting
Ghost is a really nice blog engine, however it's still in development and lacks
many features. In particular, one feature, as a developer I need is Syntax
Highlighting, without this any entries will have to rely on images of the code.
Luckily there is a simple solution, Code Prettify is a git hub project that works by
selecting the contents of <code/>blocks decorated with a prettyprint class. It then
applies spans with a varieties of classes to around language expressions, this
then allows css to colorize the content.
Adding Code Prettify
To add Code Prettify you need to include the following JavaScript tag, onto each
page so we can stylist any code block.
<script src="https://google-code-
prettify.googlecode.com/svn/loader/run_prettify.js"></script>
To do this we have two options, firstly we can update the default.hbs view file.
This approach has the downside that if we subsequently updates to Ghost or the
Casper theme we run the risk of losing any changes we make, also update the
view's will requires restarting the WebApp.
The option that I’ve chosen is to use the code injection feature of ghost.
1. Click Settings
2. Click Code Injection
3. Add <script> tag above to Blog Footer
4. Click Save
Changing the theme
The default look is still a flat background with washed our colours but I need
something punchier.
The solution is use one of the Pretty Print Themes and all I need to do is simple
update the JavaScript source, to include a skin query parameter.
src="https://.../svn/loader/run_prettify.js?skin=sons-of-obsidian.
While this did change the syntax colours unfortunately it didn't change the
background.
On inspection of the source code it became clear the reason is the <pre> tag is
expected to have decorated with the prettyprint class, however that's only located
on the <code> tag.
Fixing the theme
The solution is to add additional styling, it's possible to add some additional css
styling. Similar to how we added the JavaScript we can edit the 'screen.css' file
or create a new file.
As before the first option runs the risk that when you update Ghost you will lose
this styling. However, the second option requires browsers to load two file and is
slightly less performant, however this for me is still the best option.
In Ghost css files live in the following folder /content/themes/[your
theme]/assets/css/ folder which is then mapped /assets/css/ for browsers to
access. In this folder I create a prettyprint.css text file and add this following
css.
pre {
background-color: #000;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
-o-border-radius: 8px;
-ms-border-radius: 8px;
-khtml-border-radius: 8px;
border-radius: 8px;
width: 95%;
color: #eee;
margin: 1em auto;
padding: 1em;
white-space: pre-wrap;
}
Next I update the Code Injection setting and this file to the Blog Header and we're
now ready to start using Ghost with Syntax highlighting.
Using Code Prettify.
Ghost uses Markdown, as a language for generating html within the editor. To
add <code> blocks the syntax is 3 back ticks ```. We can also follow this with
class name, like this ```prettyprint lang-html or ```prettyprint lang-css
linenums, next you add the code you wish to stylise and the close it with another
three back ticks.

More Related Content

What's hot (9)

PDF
Nguyễn hữu bình
TopDev.vn
 
PDF
Chrome Extentions: From HelloWorld to Task note
Hiếu Bùi Đức
 
PDF
Webpack & React Performance in 16+ Steps
Grgur Grisogono
 
PPTX
How to integrate your design in Odoo v8 CMS
Odoo
 
PDF
Pagespeed what, why, and how it works
Ilya Grigorik
 
PPTX
Introduction to Java Script
Vijay Kumar Verma
 
PPT
Java script
umesh patil
 
PDF
Odoo - Open Source CMS: A performance comparision
Odoo
 
Nguyễn hữu bình
TopDev.vn
 
Chrome Extentions: From HelloWorld to Task note
Hiếu Bùi Đức
 
Webpack & React Performance in 16+ Steps
Grgur Grisogono
 
How to integrate your design in Odoo v8 CMS
Odoo
 
Pagespeed what, why, and how it works
Ilya Grigorik
 
Introduction to Java Script
Vijay Kumar Verma
 
Java script
umesh patil
 
Odoo - Open Source CMS: A performance comparision
Odoo
 

Viewers also liked (15)

PDF
Symantec Solutions
twelling
 
PDF
Altiris IT Management Suite 7
Symantec
 
PPT
Winning Business Proposals Module 3
Deiric McCann
 
PDF
Starters 6 sb
Thinh Vinh
 
PDF
Starters 2 test 2
rol1977
 
PDF
Yle starters1 tb
Thinh Vinh
 
PDF
165870 yle-starters-sample-papers-vol-
caycho123
 
PDF
Movers Picture Description
The Interactive English Classroom
 
DOCX
Jobe A. Diagne
jobediagne
 
PDF
English Adventure Starter A
My schools: Escuela 25 DE 12, Escuela 7 DE 17
 
PDF
ESL Activities and Mini-Books
Adrienne Kirby
 
PDF
Movers 6
Isabella Pham
 
PDF
Movers 7
Isabella Pham
 
PDF
Starters 2 test 1
rol1977
 
PDF
Starters 2 speaking tests
rol1977
 
Symantec Solutions
twelling
 
Altiris IT Management Suite 7
Symantec
 
Winning Business Proposals Module 3
Deiric McCann
 
Starters 6 sb
Thinh Vinh
 
Starters 2 test 2
rol1977
 
Yle starters1 tb
Thinh Vinh
 
165870 yle-starters-sample-papers-vol-
caycho123
 
Movers Picture Description
The Interactive English Classroom
 
Jobe A. Diagne
jobediagne
 
ESL Activities and Mini-Books
Adrienne Kirby
 
Movers 6
Isabella Pham
 
Movers 7
Isabella Pham
 
Starters 2 test 1
rol1977
 
Starters 2 speaking tests
rol1977
 
Ad

Similar to Code syntax highlighting in ghost (13)

DOC
Class 2 handout css exercises (2)
Erin M. Kidwell
 
PPTX
The Language of the Web - HTML and CSS
kcasavale
 
PPTX
Gutenberg Extended
Sören Wrede
 
PPTX
Intro to WordPress Theming
Andy McIlwain
 
PDF
CSS3 Talk (PDF version)
Robyn Overstreet
 
PDF
CSS3 Talk at SF HTML5 Meetup
Robyn Overstreet
 
DOCX
Adding disqus to ghost blog
Paul Graham
 
PDF
SASS, Compass, Gulp, Greensock
Marco Pinheiro
 
PPTX
Customizing Your WordPress Theme Using Firebug and Basic CSS
Laura Hartwig
 
PDF
Extending WordPress' TinyMCE
Hristo Chakarov
 
PDF
How to Use Sass to Make Your Site More Maintainable
Scott Vandehey
 
PPTX
How To Write Beautiful Code
2C Development Group
 
PDF
Responsive Prototyping with WordPress and Atomic UI Libraries - anthonydpaul ...
Anthony D. Paul
 
Class 2 handout css exercises (2)
Erin M. Kidwell
 
The Language of the Web - HTML and CSS
kcasavale
 
Gutenberg Extended
Sören Wrede
 
Intro to WordPress Theming
Andy McIlwain
 
CSS3 Talk (PDF version)
Robyn Overstreet
 
CSS3 Talk at SF HTML5 Meetup
Robyn Overstreet
 
Adding disqus to ghost blog
Paul Graham
 
SASS, Compass, Gulp, Greensock
Marco Pinheiro
 
Customizing Your WordPress Theme Using Firebug and Basic CSS
Laura Hartwig
 
Extending WordPress' TinyMCE
Hristo Chakarov
 
How to Use Sass to Make Your Site More Maintainable
Scott Vandehey
 
How To Write Beautiful Code
2C Development Group
 
Responsive Prototyping with WordPress and Atomic UI Libraries - anthonydpaul ...
Anthony D. Paul
 
Ad

More from Paul Graham (7)

PPTX
Publising a nuget package
Paul Graham
 
DOCX
EPiServer report generation
Paul Graham
 
DOCX
A guide to EPiServer CMS Scheduled Job
Paul Graham
 
DOCX
Creating an nuget package for EPiServer
Paul Graham
 
DOCX
Creating EPiServer Usage Reports
Paul Graham
 
DOCX
C# 6.0
Paul Graham
 
DOCX
Entity framework (EF) 7
Paul Graham
 
Publising a nuget package
Paul Graham
 
EPiServer report generation
Paul Graham
 
A guide to EPiServer CMS Scheduled Job
Paul Graham
 
Creating an nuget package for EPiServer
Paul Graham
 
Creating EPiServer Usage Reports
Paul Graham
 
C# 6.0
Paul Graham
 
Entity framework (EF) 7
Paul Graham
 

Recently uploaded (20)

PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
PDF
Open Source Milvus Vector Database v 2.6
Zilliz
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Open Source Milvus Vector Database v 2.6
Zilliz
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 

Code syntax highlighting in ghost

  • 1. Code Syntax Highlighting Ghost is a really nice blog engine, however it's still in development and lacks many features. In particular, one feature, as a developer I need is Syntax Highlighting, without this any entries will have to rely on images of the code. Luckily there is a simple solution, Code Prettify is a git hub project that works by selecting the contents of <code/>blocks decorated with a prettyprint class. It then applies spans with a varieties of classes to around language expressions, this then allows css to colorize the content.
  • 2. Adding Code Prettify To add Code Prettify you need to include the following JavaScript tag, onto each page so we can stylist any code block. <script src="https://google-code- prettify.googlecode.com/svn/loader/run_prettify.js"></script> To do this we have two options, firstly we can update the default.hbs view file. This approach has the downside that if we subsequently updates to Ghost or the Casper theme we run the risk of losing any changes we make, also update the view's will requires restarting the WebApp.
  • 3. The option that I’ve chosen is to use the code injection feature of ghost. 1. Click Settings 2. Click Code Injection 3. Add <script> tag above to Blog Footer 4. Click Save
  • 4. Changing the theme The default look is still a flat background with washed our colours but I need something punchier. The solution is use one of the Pretty Print Themes and all I need to do is simple update the JavaScript source, to include a skin query parameter. src="https://.../svn/loader/run_prettify.js?skin=sons-of-obsidian.
  • 5. While this did change the syntax colours unfortunately it didn't change the background. On inspection of the source code it became clear the reason is the <pre> tag is expected to have decorated with the prettyprint class, however that's only located on the <code> tag.
  • 6. Fixing the theme The solution is to add additional styling, it's possible to add some additional css styling. Similar to how we added the JavaScript we can edit the 'screen.css' file or create a new file. As before the first option runs the risk that when you update Ghost you will lose this styling. However, the second option requires browsers to load two file and is slightly less performant, however this for me is still the best option. In Ghost css files live in the following folder /content/themes/[your theme]/assets/css/ folder which is then mapped /assets/css/ for browsers to access. In this folder I create a prettyprint.css text file and add this following css.
  • 7. pre { background-color: #000; -moz-border-radius: 8px; -webkit-border-radius: 8px; -o-border-radius: 8px; -ms-border-radius: 8px; -khtml-border-radius: 8px; border-radius: 8px; width: 95%; color: #eee; margin: 1em auto; padding: 1em; white-space: pre-wrap; } Next I update the Code Injection setting and this file to the Blog Header and we're now ready to start using Ghost with Syntax highlighting.
  • 8. Using Code Prettify. Ghost uses Markdown, as a language for generating html within the editor. To add <code> blocks the syntax is 3 back ticks ```. We can also follow this with class name, like this ```prettyprint lang-html or ```prettyprint lang-css linenums, next you add the code you wish to stylise and the close it with another three back ticks.