From 380a6c9e9d3422a01061cc01e4c6f91f43b92b8d Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 29 Aug 2013 15:18:27 -0400 Subject: [PATCH] FIX: Blockquotes prefixed by spaces --- .../discourse/dialects/bold_italics_dialect.js | 17 +++++++++++++++++ .../javascripts/external/better_markdown.js | 4 +++- test/javascripts/components/markdown_test.js | 11 +++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/dialects/bold_italics_dialect.js b/app/assets/javascripts/discourse/dialects/bold_italics_dialect.js index b77b2e304c5..7cea70c8485 100644 --- a/app/assets/javascripts/discourse/dialects/bold_italics_dialect.js +++ b/app/assets/javascripts/discourse/dialects/bold_italics_dialect.js @@ -23,3 +23,20 @@ replaceMarkdown('**', 'strong'); replaceMarkdown('__', 'strong'); replaceMarkdown('*', 'em'); replaceMarkdown('_', 'em'); + + +// There's a weird issue with the markdown parser where it won't process simple blockquotes +// when they are prefixed with spaces. This fixes it. +Discourse.Dialect.on("register", function(event) { + var dialect = event.dialect, + MD = event.MD; + + dialect.block["fix_simple_quotes"] = function(block, next) { + var m = /^ +(\>[\s\S]*)/.exec(block); + if (m && m[1] && m[1].length) { + next.unshift(MD.mk_block(m[1])); + return []; + } + }; + +}); \ No newline at end of file diff --git a/app/assets/javascripts/external/better_markdown.js b/app/assets/javascripts/external/better_markdown.js index 4d5da8935a4..df990510644 100644 --- a/app/assets/javascripts/external/better_markdown.js +++ b/app/assets/javascripts/external/better_markdown.js @@ -10,6 +10,8 @@ * We fixed a bug where references can be created directly following a list. + * Fix to blockquote to handle spaces in front and when nested. + * Note the name BetterMarkdown doesn't mean it's *better* than markdown-js, it refers to it being better than our previous markdown parser! @@ -750,7 +752,7 @@ Markdown.dialects.Gruber = { } // Strip off the leading "> " and re-process as a block. - var input = block.replace( /^> ?/gm, "" ), + var input = block.replace( /^> */gm, "" ), old_tree = this.tree, processedBlock = this.toTree( input, [ "blockquote" ] ), attr = extract_attr( processedBlock ); diff --git a/test/javascripts/components/markdown_test.js b/test/javascripts/components/markdown_test.js index 19ecf7f3655..ef2d5e9dbfe 100644 --- a/test/javascripts/components/markdown_test.js +++ b/test/javascripts/components/markdown_test.js @@ -109,6 +109,17 @@ test("Links", function() { }); +test("simple quotes", function() { + cooked("> nice!", "

nice!

", "it supports simple quotes"); + cooked(" > nice!", "

nice!

", "it allows quotes with preceeding spaces"); + cooked("> level 1\n> > level 2", + "

level 1

level 2

", + "it allows nesting of blockquotes"); + cooked("> level 1\n> > level 2", + "

level 1

level 2

", + "it allows nesting of blockquotes with spaces"); +}); + test("Quotes", function() { cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n[/quote]",