Disable underscore emphasis syntaxes for markdown
This commit is contained in:
		
							
								
								
									
										7
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								TODO.md
									
									
									
									
									
								
							@@ -16,6 +16,7 @@
 | 
				
			|||||||
  - Time on their own lines
 | 
					  - Time on their own lines
 | 
				
			||||||
  - When selecting text and scrolling up, selection stops working after a while
 | 
					  - When selecting text and scrolling up, selection stops working after a while
 | 
				
			||||||
    - Ensure all the text that should be copied is copied
 | 
					    - Ensure all the text that should be copied is copied
 | 
				
			||||||
 | 
					  - Mouse wheel scrolling speed in event list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  - Pressing backspace in composer sometimes doesn't work
 | 
					  - Pressing backspace in composer sometimes doesn't work
 | 
				
			||||||
  - Message order isn't preserved when sending a first message in a E2E
 | 
					  - Message order isn't preserved when sending a first message in a E2E
 | 
				
			||||||
@@ -67,7 +68,7 @@
 | 
				
			|||||||
  - Combine events so they take less space
 | 
					  - Combine events so they take less space
 | 
				
			||||||
    - After combining is implemented, no need to hide profile changes anymore.
 | 
					    - After combining is implemented, no need to hide profile changes anymore.
 | 
				
			||||||
  - Replies
 | 
					  - Replies
 | 
				
			||||||
  - Messages editing
 | 
					  - Messages editing and redaction
 | 
				
			||||||
  - Code highlighting
 | 
					  - Code highlighting
 | 
				
			||||||
  - Support GIF avatars and images
 | 
					  - Support GIF avatars and images
 | 
				
			||||||
  - Adapt shortcuts flicking speed to font size and DPI
 | 
					  - Adapt shortcuts flicking speed to font size and DPI
 | 
				
			||||||
@@ -127,7 +128,7 @@
 | 
				
			|||||||
    - Edit/delete own devices
 | 
					    - Edit/delete own devices
 | 
				
			||||||
    - Request room keys from own other devices
 | 
					    - Request room keys from own other devices
 | 
				
			||||||
    - Auto-trust accounts within the same client
 | 
					    - Auto-trust accounts within the same client
 | 
				
			||||||
  - Uploads & proper http thumbnails
 | 
					  - Uploads
 | 
				
			||||||
    - Reduce messages ListView cacheBuffer height once http thumbnails
 | 
					    - Reduce messages ListView cacheBuffer height once http thumbnails
 | 
				
			||||||
      downloading is implemented 
 | 
					      downloading is implemented 
 | 
				
			||||||
  - Read receipts
 | 
					  - Read receipts
 | 
				
			||||||
@@ -163,8 +164,6 @@
 | 
				
			|||||||
      - Fetch all members when using the filter members bar
 | 
					      - Fetch all members when using the filter members bar
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  - Direct chats category
 | 
					  - Direct chats category
 | 
				
			||||||
  - Markdown: don't turn #things (no space) and `thing\n---` into title,
 | 
					 | 
				
			||||||
    disable `__` syntax for bold/italic
 | 
					 | 
				
			||||||
  - Better `<pre>` 
 | 
					  - Better `<pre>` 
 | 
				
			||||||
  - When inviting someone to direct chat, room is "Empty room" until accepted,
 | 
					  - When inviting someone to direct chat, room is "Empty room" until accepted,
 | 
				
			||||||
    it should be the peer's display name instead.
 | 
					    it should be the peer's display name instead.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,22 @@ import html_sanitizer.sanitizer as sanitizer
 | 
				
			|||||||
from html_sanitizer.sanitizer import Sanitizer
 | 
					from html_sanitizer.sanitizer import Sanitizer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MarkdownRenderer(mistune.Renderer):
 | 
					class MarkdownInlineGrammar(mistune.InlineGrammar):
 | 
				
			||||||
    pass
 | 
					    # Enable *word* but not _word_ syntaxes (TODO: config option for that)
 | 
				
			||||||
 | 
					    emphasis        = re.compile(r"^\*((?:\*\*|[^\*])+?)\*(?!\*)")
 | 
				
			||||||
 | 
					    double_emphasis = re.compile(r"^\*{2}([\s\S]+?)\*{2}(?!\*)")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class MarkdownInlineLexer(mistune.InlineLexer):
 | 
				
			||||||
 | 
					    grammar_class = MarkdownInlineGrammar
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def output_double_emphasis(self, m):
 | 
				
			||||||
 | 
					        return self.renderer.double_emphasis(self.output(m.group(1)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def output_emphasis(self, m):
 | 
				
			||||||
 | 
					        return self.renderer.emphasis(self.output(m.group(1)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class HtmlFilter:
 | 
					class HtmlFilter:
 | 
				
			||||||
@@ -41,7 +55,7 @@ class HtmlFilter:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        # hard_wrap: convert all \n to <br> without required two spaces
 | 
					        # hard_wrap: convert all \n to <br> without required two spaces
 | 
				
			||||||
        self._markdown_to_html = mistune.Markdown(
 | 
					        self._markdown_to_html = mistune.Markdown(
 | 
				
			||||||
            hard_wrap=True, renderer=MarkdownRenderer(),
 | 
					            hard_wrap=True, inline=MarkdownInlineLexer,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self._markdown_to_html.block.default_rules = [
 | 
					        self._markdown_to_html.block.default_rules = [
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user