-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 'ADD word definitions macro sample' from feature/w…
…ord_defintions into develop Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/api.onlyoffice.com/pulls/95 Reviewed-by: Natalia Ovchinnikova <[email protected]>
- Loading branch information
Showing
5 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions
45
.../pages/Docs/Plugin and Macros/Macros/Samples/Generate word definitions/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
order: | ||
--- | ||
|
||
## Description | ||
|
||
Generates word definitions in your document using the [Dictionary API](https://api-ninjas.com/api/dictionary) offered by [API Ninjas](https://api-ninjas.com). | ||
|
||
> To use this macro, you need to obtain your own API key from API Ninjas. | ||
<!-- This code snippet is shown in the screenshot. --> | ||
|
||
<!-- eslint-skip --> | ||
|
||
```ts | ||
(function () { | ||
const oDocument = Api.GetDocument(); | ||
const oRange = oDocument.GetRangeBySelect(); | ||
const word = oRange.GetText(); | ||
$.ajax({ | ||
method: "GET", | ||
url: "https://api.api-ninjas.com/v1/dictionary?word=" + word, | ||
headers: { "X-Api-Key": "your-api-key" }, | ||
contentType: "application/json", | ||
success: function (result) { | ||
console.log(result); | ||
const text = result.definition; | ||
const oParagraph = Api.CreateParagraph(); | ||
oParagraph.AddText(text); | ||
oDocument.InsertContent([oParagraph], { KeepTextOnly: true }); | ||
}, | ||
error: function ajaxError(jqXHR) { | ||
console.error("Error: ", jqXHR.responseText); | ||
}, | ||
}); | ||
})(); | ||
``` | ||
|
||
Methods used: GetDocument, GetRangeBySelect, GetText, CreateParagraph, AddText, InsertContent | ||
|
||
## Result | ||
|
||
<!-- imgpath --> | ||
|
||
![Generate word definitons](/assets/images/plugins/generate-word-definitions.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters