diff --git a/modules/ext.templateDataGenerator.ui.js b/modules/ext.templateDataGenerator.ui.js
index 0aa98f42..a9f90967 100644
--- a/modules/ext.templateDataGenerator.ui.js
+++ b/modules/ext.templateDataGenerator.ui.js
@@ -158,16 +158,19 @@
'\n' + newTemplateData + '\n'
);
} else {
- if ( isPageSubLevel ) {
- // Add the
- finalOutput = fullWikitext + '\n\n' +
+ finalOutput = fullWikitext;
+ if ( fullWikitext.substr( -1 ) !== '\n' ) {
+ finalOutput += '\n';
+ }
+
+ if ( !isPageSubLevel ) {
+ finalOutput += '\n';
+ }
+ finalOutput += '\n' +
newTemplateData +
'\n\n';
- } else {
- // If we are not in a subpage, add tags
- finalOutput = fullWikitext + '\n\n\n' +
- newTemplateData +
- '\n\n\n';
+ if ( !isPageSubLevel ) {
+ finalOutput += '\n';
}
}
return finalOutput;