[Tkabber-dev] r552 - trunk/plugins/juick

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Apr 27 08:56:49 MSK 2014


Author: Totktonada
Date: 2014-04-27 08:56:48 +0400 (Sun, 27 Apr 2014)
New Revision: 552

Modified:
   trunk/plugins/juick/juick.tcl
Log:
Juick plugin (svn branch):

* Add support for markdown-style links.


Modified: trunk/plugins/juick/juick.tcl
===================================================================
--- trunk/plugins/juick/juick.tcl	2014-02-01 18:14:16 UTC (rev 551)
+++ trunk/plugins/juick/juick.tcl	2014-04-27 04:56:48 UTC (rev 552)
@@ -18,6 +18,7 @@
 }
 
 namespace eval juick {
+
 variable options
 variable juick_nicknames
 variable chat_things
@@ -59,7 +60,36 @@
     ::richtext::entity_state citing 1
     ::richtext::entity_state juick 1
     ::richtext::entity_state juick_ligth 1
+    ::richtext::entity_state markdown_url 1
 
+    ::richtext::register_entity juick_numbers \
+        -configurator [namespace current]::configure_juick_numbers \
+        -parser [namespace current]::process_juick_numbers \
+        -renderer [namespace current]::render_juick \
+        -parser-priority 54
+
+    ::richtext::register_entity juick_ligth \
+        -configurator [namespace current]::configure_juick_ligth \
+        -parser [namespace current]::process_juick_ligth \
+        -renderer [namespace current]::render_juick_ligth \
+        -parser-priority 81
+
+    ::richtext::register_entity citing \
+        -configurator [namespace current]::configure_citing \
+        -parser [namespace current]::process_citing \
+        -renderer [namespace current]::render_citing \
+        -parser-priority 82
+
+    ::richtext::register_entity juick \
+        -configurator [namespace current]::configure_juick \
+        -parser [namespace current]::process_juick \
+        -renderer [namespace current]::render_juick \
+        -parser-priority 85
+
+    ::richtext::register_entity markdown_url \
+	    -parser [namespace current]::process_markdown_urls \
+	    -parser-priority 49
+
     hook::add draw_message_hook        \
         [namespace current]::ignore_server_messages 0
 
@@ -97,6 +127,12 @@
 }
 
 proc unload {} {
+    ::richtext::unregister_entity juick_numbers
+    ::richtext::unregister_entity citing
+    ::richtext::unregister_entity juick
+    ::richtext::unregister_entity juick_ligth
+    ::richtext::unregister_entity process_markdown_urls
+
     hook::remove draw_message_hook        \
         [namespace current]::ignore_server_messages 0
 
@@ -683,6 +719,32 @@
     return true
 }
 
+proc spot_markdown_url {what at startVar endVar} {
+    variable ::plugins::urls::url_regexp
+
+    set matched [regexp -indices -start $at -- \
+        {(\[([^\]]+)\]\[([^\]]+)\])} $what -> \
+        bounds title_bounds url_bounds]
+
+    if {!$matched} { return false }
+
+    lassign $url_bounds us ue
+    set url [string range $what $us $ue]
+    set md_url_regexp [format "^%s$" $::plugins::urls::url_regexp]
+    set matched [regexp -expanded -nocase -- $md_url_regexp $url]
+
+    if {!$matched} { return false }
+
+    upvar 1 $startVar uStart $endVar uEnd
+    lassign $bounds uStart uEnd
+    upvar 1 title_start title_start title_end title_end
+    lassign $title_bounds title_start title_end
+    upvar 1 url_start url_start url_end url_end
+    lassign $url_bounds url_start url_end
+
+    return true
+}
+
 proc process_juick {atLevel accName} {
     if {[::richtext::property_exists {JUICK}]} {
         return [process $atLevel $accName juick]
@@ -705,6 +767,12 @@
     }
 }
 
+proc process_markdown_urls {atLevel accName} {
+    if {[::richtext::property_exists {JUICK}]} {
+       return [process $atLevel $accName markdown_url]
+    }
+}
+
 proc process {atLevel accName what} {
     upvar #$atLevel $accName chunks
 
@@ -735,8 +803,17 @@
             }
 
             set thing [string range $s $uStart $uEnd]
-            # Write out current thing:
-            lappend out $thing $what $tags
+
+            if {[string equal $what markdown_url]} {
+                set title [string range $s $title_start $title_end]
+                set url [string range $s $url_start $url_end]
+                lappend out $url url $tags
+                ::richtext::property_update url:title,$url $title
+            } else {
+                # Write out current thing:
+                lappend out $thing $what $tags
+            }
+
             set index [expr {$uEnd + 1}]
         }
         # Write out text after the last thing, if any:
@@ -796,28 +873,6 @@
     return $id
 }
 
-::richtext::register_entity juick_numbers \
-    -configurator [namespace current]::configure_juick_numbers \
-    -parser [namespace current]::process_juick_numbers \
-    -renderer [namespace current]::render_juick \
-    -parser-priority 54
-
-::richtext::register_entity juick_ligth \
-    -configurator [namespace current]::configure_juick_ligth \
-    -parser [namespace current]::process_juick_ligth \
-    -renderer [namespace current]::render_juick_ligth \
-    -parser-priority 81
-
-::richtext::register_entity citing \
-    -configurator [namespace current]::configure_citing \
-    -parser [namespace current]::process_citing \
-    -renderer [namespace current]::render_citing \
-    -parser-priority 82
-
-::richtext::register_entity juick \
-    -configurator [namespace current]::configure_juick \
-    -parser [namespace current]::process_juick \
-    -renderer [namespace current]::render_juick \
-    -parser-priority 85
+# namespace eval juick
 }
 # vi:ts=4:et



More information about the Tkabber-dev mailing list