Make Mermaid.js limit configurable (#16519)
* Make Mermaid.js limit configurable Add `MERMAID_MAX_SOURCE_CHARACTERS` to `[markup]` settings to make the maximum size of a mermaid render configurable. Fix #16513 Signed-off-by: Andrew Thornton <art27@cantab.net> * fixup! Make Mermaid.js limit configurable * Update custom/conf/app.example.ini Co-authored-by: silverwind <me@silverwind.io> * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		
							parent
							
								
									342f338bda
								
							
						
					
					
						commit
						f135a818f5
					
				
					 6 changed files with 22 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
const MAX_SOURCE_CHARACTERS = 5000;
 | 
			
		||||
const {MermaidMaxSourceCharacters} = window.config;
 | 
			
		||||
 | 
			
		||||
function displayError(el, err) {
 | 
			
		||||
  el.closest('pre').classList.remove('is-loading');
 | 
			
		||||
| 
						 | 
				
			
			@ -26,8 +26,8 @@ export async function renderMermaid(els) {
 | 
			
		|||
  });
 | 
			
		||||
 | 
			
		||||
  for (const el of els) {
 | 
			
		||||
    if (el.textContent.length > MAX_SOURCE_CHARACTERS) {
 | 
			
		||||
      displayError(el, new Error(`Mermaid source of ${el.textContent.length} characters exceeds the maximum allowed length of ${MAX_SOURCE_CHARACTERS}.`));
 | 
			
		||||
    if (MermaidMaxSourceCharacters >= 0 && el.textContent.length > MermaidMaxSourceCharacters) {
 | 
			
		||||
      displayError(el, new Error(`Mermaid source of ${el.textContent.length} characters exceeds the maximum allowed length of ${MermaidMaxSourceCharacters}.`));
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue