allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/7] allura git commit: [#6923] Adding emoji code support extension
Date Tue, 23 Oct 2018 20:11:04 GMT
Repository: allura
Updated Branches:
  refs/heads/master ca592dfea -> 2eae88d25


[#6923] Adding emoji code support extension


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/5e134f73
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/5e134f73
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/5e134f73

Branch: refs/heads/master
Commit: 5e134f73e6beda0b7b9604871ba2ec63f5307003
Parents: ca592df
Author: Shalitha Suranga <shalithasuranga@gmail.com>
Authored: Wed Oct 17 12:43:03 2018 +0530
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Tue Oct 23 19:56:45 2018 +0000

----------------------------------------------------------------------
 Allura/allura/lib/app_globals.py         |  3 ++-
 Allura/allura/lib/markdown_extensions.py | 27 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/5e134f73/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 1260ca3..8958558 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -55,6 +55,7 @@ from allura import model as M
 from allura.lib.markdown_extensions import (
     ForgeExtension,
     CommitMessageExtension,
+    EmojiExtension
 )
 from allura.eventslistener import PostEvent
 
@@ -419,7 +420,7 @@ class Globals(object):
             # 'fenced_code'
             extensions=['fenced_code', 'codehilite',
                         ForgeExtension(
-                            **kwargs), 'tables', 'toc', 'nl2br', 'markdown_checklist.extension'],
+                            **kwargs), EmojiExtension(), 'tables', 'toc', 'nl2br', 'markdown_checklist.extension'],
             output_format='html4')
 
     @property

http://git-wip-us.apache.org/repos/asf/allura/blob/5e134f73/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 180f6f7..161b31c 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -273,6 +273,33 @@ class ForgeExtension(markdown.Extension):
         self.forge_link_tree_processor.reset()
 
 
+class EmojiExtension(markdown.Extension):
+
+    EMOJI_RE = r'(:[+\-\w]+:)'
+    EMOJI_LIST = {
+        ':+1:' : u'\U0001F44D',
+        ':smile:' : u'\U0001F642'
+    }
+
+    def __init__(self, **kwargs):
+        markdown.Extension.__init__(self)
+        
+    def extendMarkdown(self, md, md_globals):
+        pattern = EmojiInlinePattern(self.EMOJI_RE, self.EMOJI_LIST)
+        md.inlinePatterns.add('emoji', pattern,'<not_strong')
+
+        
+class EmojiInlinePattern(markdown.inlinepatterns.Pattern):
+    
+    def __init__(self, pattern, emojis):
+        markdown.inlinepatterns.Pattern.__init__(self, pattern)
+        self.emojis = emojis
+        
+    def handleMatch(self, m):
+        emoji_code = m.group(2)
+        return self.emojis.get(emoji_code)
+
+
 class ForgeLinkPattern(markdown.inlinepatterns.LinkPattern):
 
     artifact_re = re.compile(r'((.*?):)?((.*?):)?(.+)')


Mime
View raw message