diff --git a/Gruntfile.js b/Gruntfile.js index 38657b01e0..5c6975fd6a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -461,7 +461,6 @@ var path = require('path'), 'bower_components/validator-js/validator.js', 'core/client/assets/lib/showdown/extensions/ghostdown.js', - 'core/shared/lib/showdown/extensions/typography.js', 'core/shared/lib/showdown/extensions/github.js', // ToDo: Remove or replace @@ -524,7 +523,6 @@ var path = require('path'), 'bower_components/validator-js/validator.js', 'core/client/assets/lib/showdown/extensions/ghostdown.js', - 'core/shared/lib/showdown/extensions/typography.js', 'core/shared/lib/showdown/extensions/github.js', // ToDo: Remove or replace diff --git a/core/client/assets/lib/editor/htmlPreview.js b/core/client/assets/lib/editor/htmlPreview.js index 16d1cabb70..af4bb22ac6 100644 --- a/core/client/assets/lib/editor/htmlPreview.js +++ b/core/client/assets/lib/editor/htmlPreview.js @@ -9,7 +9,7 @@ 'use strict'; var HTMLPreview = function (markdown, uploadMgr) { - var converter = new Showdown.converter({extensions: ['typography', 'ghostdown', 'github']}), + var converter = new Showdown.converter({extensions: ['ghostdown', 'github']}), preview = document.getElementsByClassName('rendered-markdown')[0], update; diff --git a/core/server/models/post.js b/core/server/models/post.js index efc4732b5f..6e265f6697 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -4,8 +4,7 @@ var _ = require('lodash'), errors = require('../errorHandling'), Showdown = require('showdown'), github = require('../../shared/lib/showdown/extensions/github'), - typography = require('../../shared/lib/showdown/extensions/typography'), - converter = new Showdown.converter({extensions: [typography, github]}), + converter = new Showdown.converter({extensions: [github]}), User = require('./user').User, Tag = require('./tag').Tag, Tags = require('./tag').Tags, diff --git a/core/shared/lib/showdown/extensions/typography.js b/core/shared/lib/showdown/extensions/typography.js deleted file mode 100644 index 998aba1e70..0000000000 --- a/core/shared/lib/showdown/extensions/typography.js +++ /dev/null @@ -1,114 +0,0 @@ -/*global module */ -// -// Replaces straight quotes with curly ones, -- and --- with en dash and em -// dash respectively, and ... with horizontal ellipses. -// - -(function () { - var typography = function () { - return [ - { - type: "lang", - filter: function (text) { - var fCodeblocks = {}, nCodeblocks = {}, iCodeblocks = {}, - e = { - endash: '\u2009\u2013\u2009', // U+2009 = thin space - emdash: '\u2014', - lsquo: '\u2018', - rsquo: '\u2019', - ldquo: '\u201c', - rdquo: '\u201d', - hellip: '\u2026' - }, - - i; - - // Extract fenced code blocks. - i = -1; - text = text.replace(/```((?:.|\n)+?)```/g, - function (match, code) { - i += 1; - fCodeblocks[i] = "```" + code + "```"; - return "{typog-fcb-" + i + "}"; - }); - - // Extract indented code blocks. - i = -1; - text = text.replace(/((\n+([ ]{4}|\t).+)+)/g, - function (match, code) { - i += 1; - nCodeblocks[i] = " " + code; - return "{typog-ncb-" + i + "}"; - }); - - // Extract inline code blocks - i = -1; - text = text.replace(/`(.+)`/g, function (match, code) { - i += 1; - iCodeblocks[i] = "`" + code + "`"; - return "{typog-icb-" + i + "}"; - }); - - // Perform typographic symbol replacement. - - // Double quotes. There might be a reason this doesn't use - // the same \b matching style as the single quotes, but I - // can't remember what it is :( - text = text. - // Opening quotes - replace(/"([\w'])/g, e.ldquo + "$1"). - // All the rest - replace(/"/g, e.rdquo); - - // Single quotes/apostrophes - text = text. - // Apostrophes first - replace(/\b'\b/g, e.rsquo). - // Opening quotes - replace(/'\b/g, e.lsquo). - // All the rest - replace(/'/g, e.rsquo); - - // Dashes - text = text. - // Don't replace lines containing only hyphens - replace(/^-+$/gm, "{typog-hr}"). - replace(/---/g, e.emdash). - replace(/ -- /g, e.endash). - replace(/{typog-hr}/g, "----"); - - // Ellipses. - text = text.replace(/\.{3}/g, e.hellip); - - - // Restore fenced code blocks. - text = text.replace(/{typog-fcb-([0-9]+)}/g, function (x, y) { - return fCodeblocks[y]; - }); - - // Restore indented code blocks. - text = text.replace(/{typog-ncb-([0-9]+)}/g, function (x, y) { - return nCodeblocks[y]; - }); - - // Restore inline code blocks. - text = text.replace(/{typog-icb-([0-9]+)}/g, function (x, y) { - return iCodeblocks[y]; - }); - - return text; - } - } - ]; - }; - - // Client-side export - if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) { - window.Showdown.extensions.typography = typography; - } - // Server-side export - if (typeof module !== 'undefined') { - module.exports = typography; - } -}()); - diff --git a/core/test/functional/frontend/feed_test.js b/core/test/functional/frontend/feed_test.js index 439765dc69..f1088a5a47 100644 --- a/core/test/functional/frontend/feed_test.js +++ b/core/test/functional/frontend/feed_test.js @@ -10,7 +10,7 @@ CasperTest.begin('Ensure that RSS is available', 11, function suite(test) { siteDescription = '', siteUrl = 'http://127.0.0.1:2369/', postTitle = '', - postStart = 'You’re live!', + postStart = 'You\'re live!', postEnd = 'you think :)

]]>
', postLink = 'http://127.0.0.1:2369/welcome-to-ghost/', postCreator = ''; @@ -29,17 +29,17 @@ CasperTest.begin('Ensure that RSS is available', 11, function suite(test) { }); }, false); -CasperTest.begin('Ensure that author element is not included. Only dc:creator', 3, function suite(test) { +CasperTest.begin('Ensure that author element is not included. Only dc:creator', 3, function suite(test) { CasperTest.Routines.togglePermalinks.run('off'); - casper.thenOpen(url + 'rss/', function (response) { + casper.thenOpen(url + 'rss/', function (response) { var content = this.getPageContent(), author = '', postCreator = ''; test.assertEqual(response.status, 200, 'Response status should be 200.'); test.assert(content.indexOf(author) < 0, 'Author element should not be included'); - test.assert(content.indexOf(postCreator) >= 0, 'Welcome post should have Test User as the creator.'); - }); + test.assert(content.indexOf(postCreator) >= 0, 'Welcome post should have Test User as the creator.'); + }); }, false); CasperTest.begin('Ensures dated permalinks works with RSS', 2, function suite(test) { diff --git a/core/test/unit/client_showdown_int_spec.js b/core/test/unit/client_showdown_int_spec.js index 6fbc8f71e8..1f44313003 100644 --- a/core/test/unit/client_showdown_int_spec.js +++ b/core/test/unit/client_showdown_int_spec.js @@ -478,4 +478,19 @@ describe("Showdown client side converter", function () { processedMarkup.should.match(testPhrase.output); }); }); + + + // Waiting for showdown typography to be updated + // it("should correctly convert quotes to curly quotes", function () { + // var testPhrases = [ + // { + // input: "Hello world\nIt's a fine day\nout", + // output: /^

Hello world
\nIt’s a fine day
\nout<\/p>$/} + // ]; + // + // testPhrases.forEach(function (testPhrase) { + // processedMarkup = converter.makeHtml(testPhrase.input); + // processedMarkup.should.match(testPhrase.output); + // }); + // }) });