diff --git a/lib/modules/collapseWhitespace.es6 b/lib/modules/collapseWhitespace.es6
index 5ef611b..3d04ee6 100644
--- a/lib/modules/collapseWhitespace.es6
+++ b/lib/modules/collapseWhitespace.es6
@@ -76,6 +76,17 @@ function collapseRedundantWhitespaces(text, collapseType, shouldTrim = false, cu
if (shouldTrim) {
if (collapseType === 'aggressive') {
if (onlyWhitespacePattern.test(text)) {
+ if (!noTrimWhitespacesArroundElements.has(currentTag)) {
+ // Remove very first and very end spaces inside text node
+ if (typeof prevNodeTag === 'undefined') {
+ text = text.trimStart();
+ }
+
+ if (typeof nextNodeTag === 'undefined') {
+ text = text.trimEnd();
+ }
+ }
+
// "text" only contains whitespaces. Only trim when both prevNodeTag & nextNodeTag are not "noTrimWhitespacesArroundElement"
// Otherwise the required ONE whitespace will be trimmed
if (
diff --git a/test/modules/collapseWhitespace.js b/test/modules/collapseWhitespace.js
index ed2dcbb..c054ecf 100644
--- a/test/modules/collapseWhitespace.js
+++ b/test/modules/collapseWhitespace.js
@@ -10,7 +10,23 @@ describe('collapseWhitespace', () => {
posthtml htmlnano
hello world! other link
- Example `;
+ Example `;
+
+ const spaceInsideTextNodeHtml = `
+