mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Fix TODO Qs
This commit is contained in:
parent
9b319a55f6
commit
8c85c10212
@ -73,7 +73,7 @@ export const detectType = function (text: string, config?: MermaidConfig): strin
|
||||
}
|
||||
}
|
||||
|
||||
return 'flowchart';
|
||||
throw new Error(`No diagram type detected for text: ${text}`);
|
||||
};
|
||||
|
||||
export const addDetector = (key: string, detector: DiagramDetector) => {
|
||||
|
@ -12,8 +12,7 @@ describe('DiagramAPI', () => {
|
||||
|
||||
it('should handle diagram registrations', () => {
|
||||
expect(() => getDiagram('loki')).toThrow();
|
||||
// TODO Q: Shouldn't this be throwing an error?
|
||||
expect(detectType('loki diagram')).toBe('flowchart');
|
||||
expect(() => detectType('loki diagram')).toThrow();
|
||||
registerDiagram(
|
||||
'loki',
|
||||
{
|
||||
|
@ -24,7 +24,6 @@ export const removeScript = (txt: string): string => {
|
||||
};
|
||||
|
||||
const sanitizeMore = (text: string, config: MermaidConfig) => {
|
||||
// TODO Q: Should this check really be here? Feels like we should be sanitizing it regardless.
|
||||
if (config.flowchart?.htmlLabels !== false) {
|
||||
const level = config.securityLevel;
|
||||
if (level === 'antiscript' || level === 'strict') {
|
||||
@ -54,7 +53,7 @@ export const sanitizeTextOrArray = (
|
||||
config: MermaidConfig
|
||||
): string | string[] => {
|
||||
if (typeof a === 'string') return sanitizeText(a, config);
|
||||
// TODO Q: Do we need flat?
|
||||
// TODO: Refactor to avoid flat.
|
||||
return a.flat().map((x: string) => sanitizeText(x, config));
|
||||
};
|
||||
|
||||
@ -108,7 +107,6 @@ const breakToPlaceholder = (s: string): string => {
|
||||
*/
|
||||
const getUrl = (useAbsolute: boolean): string => {
|
||||
let url = '';
|
||||
// TODO Q: If useAbsolute if false, empty string is returned. Bug?
|
||||
if (useAbsolute) {
|
||||
url =
|
||||
window.location.protocol +
|
||||
@ -116,7 +114,6 @@ const getUrl = (useAbsolute: boolean): string => {
|
||||
window.location.host +
|
||||
window.location.pathname +
|
||||
window.location.search;
|
||||
// TODO Q: Why is this necessary?
|
||||
url = url.replaceAll(/\(/g, '\\(');
|
||||
url = url.replaceAll(/\)/g, '\\)');
|
||||
}
|
||||
@ -130,9 +127,8 @@ const getUrl = (useAbsolute: boolean): string => {
|
||||
* @param {string | boolean} val String or boolean to convert
|
||||
* @returns {boolean} The result from the input
|
||||
*/
|
||||
// TODO Q: Should we make this check more specific? 'False', '0', 'null' all will evaluate to true.
|
||||
export const evaluate = (val: string | boolean): boolean =>
|
||||
val === 'false' || val === false ? false : true;
|
||||
export const evaluate = (val?: string | boolean): boolean =>
|
||||
val === false || ['false', 'null', '0'].includes(String(val).trim().toLowerCase()) ? false : true;
|
||||
|
||||
/**
|
||||
* Makes generics in typescript syntax
|
||||
|
@ -34,6 +34,7 @@ import theme from './themes';
|
||||
import utils, { directiveSanitizer } from './utils';
|
||||
import DOMPurify from 'dompurify';
|
||||
import { MermaidConfig } from './config.type';
|
||||
import { evaluate } from './diagrams/common/common';
|
||||
|
||||
let hasLoadedDiagrams = false;
|
||||
|
||||
@ -308,8 +309,7 @@ const render = function (
|
||||
let svgCode = root.select('#d' + id).node().innerHTML;
|
||||
|
||||
log.debug('cnf.arrowMarkerAbsolute', cnf.arrowMarkerAbsolute);
|
||||
// TODO Q: Needs verification.
|
||||
if (!cnf.arrowMarkerAbsolute && cnf.securityLevel !== 'sandbox') {
|
||||
if (!evaluate(cnf.arrowMarkerAbsolute) && cnf.securityLevel !== 'sandbox') {
|
||||
svgCode = svgCode.replace(/marker-end="url\(.*?#/g, 'marker-end="url(#', 'g');
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import c4 from './diagrams/c4/styles';
|
||||
import { FlowChartStyleOptions } from './diagrams/flowchart/styles';
|
||||
import { log } from './logger';
|
||||
|
||||
// TODO Q: Shouldn't registerDiagram be injecting data here?
|
||||
// TODO @knut: Inject from registerDiagram.
|
||||
const themes = {
|
||||
flowchart,
|
||||
'flowchart-v2': flowchart,
|
||||
|
Loading…
x
Reference in New Issue
Block a user