Add documentation for exposed detectType function

This commit is contained in:
Pedro Reyes
2023-03-06 19:32:34 -03:00
parent 8ebd550e0b
commit 878c9f1d9d
2 changed files with 34 additions and 0 deletions

View File

@@ -247,6 +247,23 @@ The example below show an outline of how this could be used. The example just lo
</script> </script>
``` ```
To determine the type of diagram present in a given text, you can utilize the `mermaid.detectType` function, as demonstrated in the example below.
```html
<script type="module">
import mermaid from './mermaid.esm.mjs';
const graphDefinition = `sequenceDiagram
Pumbaa->>Timon:I ate like a pig.
Timon->>Pumbaa:Pumbaa, you ARE a pig.`;
try {
const type = mermaid.detectType(graphDefinition);
console.log(type); // 'sequence'
} catch (error) {
// UnknownDiagramError
}
</script>
```
### Binding events ### Binding events
Sometimes the generated graph also has defined interactions like tooltip and click events. When using the API one must Sometimes the generated graph also has defined interactions like tooltip and click events. When using the API one must

View File

@@ -244,6 +244,23 @@ The example below show an outline of how this could be used. The example just lo
</script> </script>
``` ```
To determine the type of diagram present in a given text, you can utilize the `mermaid.detectType` function, as demonstrated in the example below.
```html
<script type="module">
import mermaid from './mermaid.esm.mjs';
const graphDefinition = `sequenceDiagram
Pumbaa->>Timon:I ate like a pig.
Timon->>Pumbaa:Pumbaa, you ARE a pig.`;
try {
const type = mermaid.detectType(graphDefinition);
console.log(type); // 'sequence'
} catch (error) {
// UnknownDiagramError
}
</script>
```
### Binding events ### Binding events
Sometimes the generated graph also has defined interactions like tooltip and click events. When using the API one must Sometimes the generated graph also has defined interactions like tooltip and click events. When using the API one must