diff --git a/languagetool-dev/src/main/java/org/languagetool/dev/diff/LightRuleMatchParser.java b/languagetool-dev/src/main/java/org/languagetool/dev/diff/LightRuleMatchParser.java
index <HASH>..<HASH> 100644
--- a/languagetool-dev/src/main/java/org/languagetool/dev/diff/LightRuleMatchParser.java
+++ b/languagetool-dev/src/main/java/org/languagetool/dev/diff/LightRuleMatchParser.java
@@ -180,7 +180,7 @@ class LightRuleMatchParser {
   private String getContextWithSpan(String context, int startMarkerPos, int maxEnd) {
     context = context.substring(0, startMarkerPos) +
       "<span class='marker'>" +
-      context.substring(startMarkerPos, maxEnd) +
+      context.substring(startMarkerPos, maxEnd).replace(" ", "&nbsp;") +
       "</span>" +
       context.substring(maxEnd);
     return context;
avoid collapsing consecutive spaces