Skip to content

Commit

Permalink
Merge pull request 'Fixes for the Remove extra spaces macro' from fix…
Browse files Browse the repository at this point in the history
…/remove-extra-spaces into develop

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/api.onlyoffice.com/pulls/100
  • Loading branch information
LinneyS committed Dec 19, 2024
2 parents 9119505 + 6cebdf6 commit 4db6257
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 4db6257

Please sign in to comment.