1169- break out getRows

Moved getRows function from `state/stateRenderer.js` and `state/shapes.js` into `common/common.js`. Broke out section into small one line functions for replacing line breaks, then moved the `sanitize` function from `utils.js` to this new module as there is shared functionality
This commit is contained in:
Justin Greywolf
2020-02-21 13:49:05 -08:00
parent 5ccca5e329
commit 6d74c5663f
6 changed files with 51 additions and 42 deletions

View File

@@ -0,0 +1,39 @@
export const getRows = s => {
if (!s) return 1;
let str = breakToPlaceholder(s);
str = str.replace(/\\n/g, '#br#');
return str.split('#br#');
};
export const sanitizeText = (text, config) => {
let txt = text;
let htmlLabels = true;
if (
config.flowchart &&
(config.flowchart.htmlLabels === false || config.flowchart.htmlLabels === 'false')
)
htmlLabels = false;
if (config.securityLevel !== 'loose' && htmlLabels) {
// eslint-disable-line
txt = breakToPlaceholder(txt);
txt = txt.replace(/</g, '&lt;').replace(/>/g, '&gt;');
txt = txt.replace(/=/g, '&equals;');
txt = placeholderToBreak(txt);
}
return txt;
};
const breakToPlaceholder = s => {
return s.replace(/<br\s*\/?>/gi, '#br#');
};
const placeholderToBreak = s => {
return s.replace(/#br#/g, '<br/>');
};
export default {
getRows,
sanitizeText
};