UNPKG

@figlinq/react-chart-editor

Version:
2 lines 1.26 kB
const getTextBlockRegExp=()=>/\\text\{([^}]*)}/g;const getLaTeXWrappedRegExp=()=>/^\$[\s\S]*\$$/;const stripHTMLTags=html=>html.replace(/<[^>]*>/g,"").trim();const extractTextBlocks=laTeX=>{let matchObj;let matchStr;const matches=[];const stringifiedLaTeX=JSON.stringify(laTeX);const regExp=getTextBlockRegExp();while((matchObj=regExp.exec(stringifiedLaTeX))!==null){matchStr=matchObj[1].trim().replace("\\n","");matches.push(matchStr)}return matches.join("<br>")};const wrapLaTeX=value=>value?`$${value}$`:"$$";const wrapText=value=>value?`\\text{${value}}`:"\\text{}";export const isLaTeXExpr=value=>getLaTeXWrappedRegExp().test(value);export const hasTextExpression=laTeX=>{const regExp=getTextBlockRegExp();const stringifiedLaTeX=JSON.stringify(laTeX);return regExp.test(stringifiedLaTeX)};export const htmlToLaTeX=html=>{const breakTag="<br>";const trimmedHTML=html.trim();if(trimmedHTML===""){return wrapLaTeX(wrapText())}if(trimmedHTML.replace(breakTag,"")===""){return wrapLaTeX(wrapText())}return wrapLaTeX(trimmedHTML.split(breakTag).map(para=>para.length?wrapText(stripHTMLTags(para)):"").join("\n"))};export const laTeXToHTML=laTeX=>{const trimmedLaTeX=laTeX.trim();return extractTextBlocks(trimmedLaTeX)}; //# sourceMappingURL=convertFormats.js.map