Adding typographic quotes to Ghost

As I write this, Ghost is at version 0.4.1 and does not include the ability to convert straight ' and " quotes to their proper typographic equivalents of ‘ ’ and “ ”, nor does it convert hyphens into en– or em— dashes.

Since I'd fiddled with an automatic converter for another project that also used the Showdown converter, I decided to try adding it to Ghost. It wasn't as straightforward as I expected, but even so it's not super complicated.

Back up!

Just in case something goes wrong, make a copy of any file you edit!

So warned, let's begin. The first step is to download my Typography extension to Showdown, either from that Github page, or from this direct link if you just want the JavaScript file. This file need to go in

ghost/core/shared/vendor/showdown/extensions/

Next the file ghost/core/server/models/post.js needs to be modified. At the top, change the line that reads:

converter = new Showown.converter({extensions: [github]}),  

to this:

typography = require('../../shared/vendor/showdown/extensions/typography'),  
converter = new Showdown.converter({extensions: [typography, github]}),  

Next the file ghost/core/client/views/editor.js needs to be modified. In the initMarkdown function, on line 441 (as of version 0.4.1; line number might be different for other versions), change the line that reads:

this.converter = new Showdown.converter({extensions: ['ghostdown', 'github']});  

to read:

this.converter = new Showdown.converter({extensions: ['typography', 'ghostdown', 'github']});  

Finally the file ghost/Gruntfile.js needs to be edited to add a reference to typography.js so it can be included in the minified and concatenated JavaScript used in the browser. Just add

'core/shared/vendor/showdown/extensions/typography.js',

to the list of files in the 'dev' and 'prod' sections of the 'concat' section, around line 400 or so, then run the grunt prod command and restart Ghost.


[photography] DPI is easy   ·   [blog] Comments: Disqus vs others