fix(#4140): Deprecate mermaidAPI.render

This commit is contained in:
Sidharth Vinod 2023-02-24 12:20:31 +05:30
parent 1e5d9ae1f4
commit 0206ff540a
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
3 changed files with 29 additions and 24 deletions

View File

@ -95,7 +95,7 @@ mermaid.initialize(config);
#### Defined in
[mermaidAPI.ts:680](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L680)
[mermaidAPI.ts:659](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L659)
## Functions

View File

@ -337,6 +337,32 @@ const parse = async (text: string, parseOptions?: ParseOptions): Promise<boolean
});
};
/**
* Function that renders an svg with a graph from a chart definition. Usage example below.
*
* ```javascript
* mermaid.initialize({
* startOnLoad: true,
* });
* $(function () {
* const graphDefinition = 'graph TB\na-->b';
* const cb = function (svgGraph) {
* console.log(svgGraph);
* };
* mermaid.render('id1', graphDefinition, cb);
* });
* ```
*
* @param id - The id for the SVG element (the element to be rendered)
* @param text - The text for the graph definition
* @param cb - Callback which is called after rendering is finished with the svg code as in param.
* @param svgContainingElement - HTML element where the svg will be inserted. (Is usually element with the .mermaid class)
* If no svgContainingElement is provided then the SVG element will be appended to the body.
* Selector to element in which a div with the graph temporarily will be
* inserted. If one is provided a hidden div will be inserted in the body of the page instead. The
* element will be removed when rendering is completed.
* @returns Returns the rendered element as a string containing the SVG definition.
*/
const render = (id: string, text: string, container?: Element): Promise<RenderResult> => {
return new Promise((resolve, reject) => {
// This promise will resolve when the mermaidAPI.render call is done.

View File

@ -370,30 +370,9 @@ export const removeExistingElements = (
};
/**
* Function that renders an svg with a graph from a chart definition. Usage example below.
* @deprecated - use the `mermaid.render` function instead of `mermaid.mermaidAPI.render`
*
* ```javascript
* mermaidAPI.initialize({
* startOnLoad: true,
* });
* $(function () {
* const graphDefinition = 'graph TB\na-->b';
* const cb = function (svgGraph) {
* console.log(svgGraph);
* };
* mermaidAPI.render('id1', graphDefinition, cb);
* });
* ```
*
* @param id - The id for the SVG element (the element to be rendered)
* @param text - The text for the graph definition
* @param cb - Callback which is called after rendering is finished with the svg code as in param.
* @param svgContainingElement - HTML element where the svg will be inserted. (Is usually element with the .mermaid class)
* If no svgContainingElement is provided then the SVG element will be appended to the body.
* Selector to element in which a div with the graph temporarily will be
* inserted. If one is provided a hidden div will be inserted in the body of the page instead. The
* element will be removed when rendering is completed.
* @returns Returns the rendered element as a string containing the SVG definition.
* Deprecated for external use.
*/
const render = async function (