From 0948452cd5c955ec26aff8a79f5dd680425ceee1 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Wed, 22 Jan 2020 12:06:33 +0100 Subject: [PATCH] Markdown: fix rendering when source has prepending whitespace Fixed an issue with pat-markdown where rendering was not like expected when source has prepending whitespace (#697) Fixes #697 --- CHANGES.md | 1 + src/pat/markdown/markdown.js | 1 + src/pat/markdown/tests.js | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 836ae18ea..723b40cf3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ Features - Fixed an issue with pat-scroll when placed on an item without a href - Fixed an issue with pat-autofocus that would set focus on hidden items - Fixed an issue with pat-inject scroll that would scroll too much (#694) +- Fixed an issue with pat-markdown where rendering was not like expected when source has prepending whitespace (#697) Fixes ~~~~~ diff --git a/src/pat/markdown/markdown.js b/src/pat/markdown/markdown.js index a012f40f2..fe54ac8ea 100644 --- a/src/pat/markdown/markdown.js +++ b/src/pat/markdown/markdown.js @@ -28,6 +28,7 @@ define([ render: function(text) { var $rendering = $("
"), converter = new Showdown.Converter({tables: true, extensions: ['prettify']}); + text = text.trim(); $rendering.html(converter.makeHtml(text)); return $rendering; }, diff --git a/src/pat/markdown/tests.js b/src/pat/markdown/tests.js index 35a7b1ac9..bf92894d1 100644 --- a/src/pat/markdown/tests.js +++ b/src/pat/markdown/tests.js @@ -54,6 +54,13 @@ define(["pat-markdown"], function(Pattern) { var $rendering = Pattern.prototype.render("*This is markdown*"); expect($rendering.html()).toBe("

This is markdown

"); }); + + it("removes whitespace from start and end of text", function() { + // If text is not removed, the rendering breaks and ouputs this instead: + // '
 *This is markdown*     
' + var $rendering = Pattern.prototype.render(" *This is markdown* "); + expect($rendering.html()).toBe("

This is markdown

"); + }); }); describe("Session extraction", function() {