mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	email_notifications: Run html2text as a subprocess.
html2text is GPL licensed. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							5529639b84
						
					
				
				
					commit
					e10b7f2f3c
				
			@@ -2,12 +2,12 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
 | 
					import subprocess
 | 
				
			||||||
from collections import defaultdict
 | 
					from collections import defaultdict
 | 
				
			||||||
from datetime import timedelta
 | 
					from datetime import timedelta
 | 
				
			||||||
from email.headerregistry import Address
 | 
					from email.headerregistry import Address
 | 
				
			||||||
from typing import Any, Dict, Iterable, List, Optional, Tuple
 | 
					from typing import Any, Dict, Iterable, List, Optional, Tuple
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import html2text
 | 
					 | 
				
			||||||
import lxml.html
 | 
					import lxml.html
 | 
				
			||||||
import pytz
 | 
					import pytz
 | 
				
			||||||
from bs4 import BeautifulSoup
 | 
					from bs4 import BeautifulSoup
 | 
				
			||||||
@@ -704,8 +704,8 @@ def enqueue_welcome_emails(user: UserProfile, realm_creation: bool = False) -> N
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def convert_html_to_markdown(html: str) -> str:
 | 
					def convert_html_to_markdown(html: str) -> str:
 | 
				
			||||||
    parser = html2text.HTML2Text()
 | 
					    # html2text is GPL licensed, so run it as a subprocess.
 | 
				
			||||||
    markdown = parser.handle(html).strip()
 | 
					    markdown = subprocess.check_output(["html2text"], input=html, text=True).strip()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # We want images to get linked and inline previewed, but html2text will turn
 | 
					    # We want images to get linked and inline previewed, but html2text will turn
 | 
				
			||||||
    # them into links of the form ``, which is
 | 
					    # them into links of the form ``, which is
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user