Skip to content

Commit

Permalink
Added post migration to visual editor for legacy editor posts with ol…
Browse files Browse the repository at this point in the history
…d caption formatting
  • Loading branch information
aforcier authored and maxme committed Jul 8, 2016
1 parent 4767334 commit 5322157
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,19 @@ private String migrateLegacyDraft(String content) {
matcher.appendReplacement(stringBuffer, replacement);
}
matcher.appendTail(stringBuffer);
return stringBuffer.toString();
content = stringBuffer.toString();
}
if (content.contains("[caption")) {
// Convert old legacy post caption formatting to new format, to avoid being stripped by the visual editor
Pattern pattern = Pattern.compile("(\\[caption[^]]*caption=\"([^\"]*)\"[^]]*].+?)(\\[\\/caption])");
Matcher matcher = pattern.matcher(content);
StringBuffer stringBuffer = new StringBuffer();
while (matcher.find()) {
String replacement = matcher.group(1) + matcher.group(2) + matcher.group(3);
matcher.appendReplacement(stringBuffer, replacement);
}
matcher.appendTail(stringBuffer);
content = stringBuffer.toString();
}
return content;
}
Expand Down

0 comments on commit 5322157

Please sign in to comment.