Skip to content

Commit

Permalink
fixed Remove extra spaces macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ovchinnikova-natalya committed Dec 18, 2024
1 parent 9119505 commit 29c99d4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
Binary file modified site/assets/images/plugins/remove-extra-spaces.dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified site/assets/images/plugins/remove-extra-spaces.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ Removes extra spaces in text document.
```ts
(function()
{
const oDocument = Api.GetDocument();
const oRange = oDocument.GetRangeBySelect();
const rawText = oRange.GetText();
oRange.Delete();

// Split the original word into an array of paragraphs based on newline characters
const paragraphs = rawText.split('\n');

// Create an array to store cleaned paragraphs
const cleanedParagraphs = [];

// Clean each paragraph and store it in the cleanedParagraphs array
for (const paragraph of paragraphs) {
// Use a regular expression to replace consecutive whitespaces with a single space
const cleanedParagraph = paragraph.replace(/\s+/g, ' ');
cleanedParagraphs.push(cleanedParagraph);
}

// Join the cleaned paragraphs back together with newline characters
const cleanedText = cleanedParagraphs.join('\n');

// Insert the cleanedText with original paragraph structure
const oParagraph = Api.CreateParagraph();
oParagraph.AddText(cleanedText);
oDocument.InsertContent([oParagraph], { "KeepTextOnly": true });
const oDocument = Api.GetDocument();
const oRange = oDocument.GetRangeBySelect();
const rawText = oRange.GetText();
oRange.Delete();

// Split the original word into an array of paragraphs based on newline characters
const paragraphs = rawText.split('\n');

// Create an array to store cleaned paragraphs
const cleanedParagraphs = [];

// Clean each paragraph and store it in the cleanedParagraphs array
for (const paragraph of paragraphs) {
// Use a regular expression to replace consecutive whitespaces with a single space
const cleanedParagraph = paragraph.replace(/\s+/g, ' ');
cleanedParagraphs.push(cleanedParagraph);
}

// Join the cleaned paragraphs with newline characters
const cleanedText = cleanedParagraphs.join('\n');

// Insert the cleanedText into the original paragraph structure
const oParagraph = Api.CreateParagraph();
oParagraph.AddText(cleanedText);
oDocument.InsertContent([oParagraph], { "KeepTextOnly": true });
})();
```

Expand Down

0 comments on commit 29c99d4

Please sign in to comment.