Added emoji's
This commit is contained in:
		
							parent
							
								
									4185bb3a69
								
							
						
					
					
						commit
						928969b8b6
					
				| @ -25,6 +25,7 @@ dependencies = [ | |||||||
|     "aiohttp-session", |     "aiohttp-session", | ||||||
|     "cryptography", |     "cryptography", | ||||||
|     "requests", |     "requests", | ||||||
|     "asyncssh" |     "asyncssh", | ||||||
|  |     "emoji" | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ from snek.system import http | |||||||
| from snek.system.cache import Cache | from snek.system.cache import Cache | ||||||
| from snek.system.markdown import MarkdownExtension | from snek.system.markdown import MarkdownExtension | ||||||
| from snek.system.middleware import cors_middleware | from snek.system.middleware import cors_middleware | ||||||
| from snek.system.template import LinkifyExtension, PythonExtension | from snek.system.template import LinkifyExtension, PythonExtension,EmojiExtension | ||||||
| from snek.view.about import AboutHTMLView, AboutMDView | from snek.view.about import AboutHTMLView, AboutMDView | ||||||
| from snek.view.docs import DocsHTMLView, DocsMDView | from snek.view.docs import DocsHTMLView, DocsMDView | ||||||
| from snek.view.index import IndexView | from snek.view.index import IndexView | ||||||
| @ -54,6 +54,7 @@ class Application(BaseApplication): | |||||||
|         self.jinja2_env.add_extension(MarkdownExtension) |         self.jinja2_env.add_extension(MarkdownExtension) | ||||||
|         self.jinja2_env.add_extension(LinkifyExtension) |         self.jinja2_env.add_extension(LinkifyExtension) | ||||||
|         self.jinja2_env.add_extension(PythonExtension) |         self.jinja2_env.add_extension(PythonExtension) | ||||||
|  |         self.jinja2_env.add_extension(EmojiExtension) | ||||||
|          |          | ||||||
|         self.setup_router() |         self.setup_router() | ||||||
|         self.cache = Cache(self) |         self.cache = Cache(self) | ||||||
|  | |||||||
| @ -1,6 +1,11 @@ | |||||||
| from types import SimpleNamespace | from types import SimpleNamespace | ||||||
| from bs4 import BeautifulSoup | from bs4 import BeautifulSoup | ||||||
| import re  | import re  | ||||||
|  | import emoji | ||||||
|  | 
 | ||||||
|  | from jinja2 import TemplateSyntaxError, nodes | ||||||
|  | from jinja2.ext import Extension | ||||||
|  | from jinja2.nodes import Const | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -33,9 +38,24 @@ def linkify_https(text): | |||||||
|     return set_link_target_blank(str(soup)) |     return set_link_target_blank(str(soup)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| from jinja2 import TemplateSyntaxError, nodes | class EmojiExtension(Extension): | ||||||
| from jinja2.ext import Extension |     tags = {"emoji"} | ||||||
| from jinja2.nodes import Const | 
 | ||||||
|  |     def parse(self, parser): | ||||||
|  |         line_number = next(parser.stream).lineno | ||||||
|  |         md_file = [Const("")] | ||||||
|  |         body = "" | ||||||
|  |         try: | ||||||
|  |             md_file = [parser.parse_expression()] | ||||||
|  |         except TemplateSyntaxError: | ||||||
|  |             body = parser.parse_statements(["name:endemoji"], drop_needle=True) | ||||||
|  |         return nodes.CallBlock( | ||||||
|  |             self.call_method("_to_html", md_file), [], [], body | ||||||
|  |         ).set_lineno(line_number) | ||||||
|  | 
 | ||||||
|  |     def _to_html(self, md_file, caller): | ||||||
|  |         return emoji.emojize(caller(),language='alias') | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class LinkifyExtension(Extension): | class LinkifyExtension(Extension): | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| {# | {# | ||||||
|     <div style="max-width:100%;" data-uid="{{uid}}" data-color="{{color}}" data-channel_uid="{{channel_uid}}" data-user_nick="{{user_nick}}" data-created_at="{{created_at}}" data-user_uid="{{user_uid}}" data-message="{{message}}" class="message"><div class="avatar" style="background-color: {{color}}; color: black;">{{user_nick[0]}}</div><div class="message-content"><div class="author" style="color: {{color}};">{{user_nick}}</div><div class="text"> |     <div style="max-width:100%;" data-uid="{{uid}}" data-color="{{color}}" data-channel_uid="{{channel_uid}}" data-user_nick="{{user_nick}}" data-created_at="{{created_at}}" data-user_uid="{{user_uid}}" data-message="{{message}}" class="message"><div class="avatar" style="background-color: {{color}}; color: black;">{{user_nick[0]}}</div><div class="message-content"><div class="author" style="color: {{color}};">{{user_nick}}</div><div class="text"> | ||||||
| #}{% autoescape false %}{% linkify %}{% markdown %}{% autoescape false %}{{ message }}{%raw %} {% endraw%}{%endautoescape%}{% endmarkdown %}{% endlinkify %}{% endautoescape %}{# | #}{% autoescape false %}{% linkify %}{% markdown %}{% autoescape false %}{% emoji %}{{ message }}{%raw %} {% endraw%}{% endemoji %}{%endautoescape%}{% endmarkdown %}{% endlinkify %}{% endautoescape %}{# | ||||||
|     </div><div class="time">{{created_at}}</div></div></div> |     </div><div class="time">{{created_at}}</div></div></div> | ||||||
| #} | #} | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user