[MKDoc-commit] [MKDoc-Text-Structured] identify smilies and assign CSS classes

bruno at mkdoc.demon.co.uk bruno at mkdoc.demon.co.uk
Fri Aug 5 11:49:56 BST 2005


Log Message:
-----------
[MKDoc-Text-Structured] identify smilies and assign CSS classes

Modified Files:
--------------
    MKDoc-Text-Structured:
        Changes
        MANIFEST
    MKDoc-Text-Structured/lib/MKDoc/Text:
        Structured.pm
    MKDoc-Text-Structured/lib/MKDoc/Text/Structured:
        Inline.pm
    MKDoc-Text-Structured/t:
        010_ul.t

Added Files:
-----------
    MKDoc-Text-Structured/t:
        021_smilies.t

-------------- next part --------------
Index: MANIFEST
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/MANIFEST,v
retrieving revision 1.5
retrieving revision 1.6
diff -LMANIFEST -LMANIFEST -u -r1.5 -r1.6
--- MANIFEST
+++ MANIFEST
@@ -38,3 +38,4 @@
 t/018_pre_indented.t
 t/019_insert_spaces.t
 t/020_mailto.t
+t/021_smilies.t
Index: Changes
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/Changes,v
retrieving revision 1.25
retrieving revision 1.26
diff -LChanges -LChanges -u -r1.25 -r1.26
--- Changes
+++ Changes
@@ -5,6 +5,7 @@
     - method to insert spaces into long words
     - strip mailto: when linking and displaying email addresses
     - documented MKDoc::Text::Structured::Inline
+    - wrap smilies in CSS classes
 
 0.82 Thu Mar 31 13:45:00 2005
     - fixed failure to change " to " bug
Index: Structured.pm
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/lib/MKDoc/Text/Structured.pm,v
retrieving revision 1.26
retrieving revision 1.27
diff -Llib/MKDoc/Text/Structured.pm -Llib/MKDoc/Text/Structured.pm -u -r1.26 -r1.27
--- lib/MKDoc/Text/Structured.pm
+++ lib/MKDoc/Text/Structured.pm
@@ -315,6 +315,13 @@
 Additionally, once the XHTML fragment is produced, you could use
 L<MKDoc::XML::Tagger> to hyperlink it against a glossary of hyperlinks.
 
+=head1 Smilies
+
+Basic smilies such as :-) and :-( are wrapped in a CSS class:
+
+  <span class="smilie-happy">:-)</span>
+  <span class="smilie-sad">:-(</span>
+
 =head1 Long Words
 
 Long words are split up into fragments separated by spaces if the length
Index: Inline.pm
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/lib/MKDoc/Text/Structured/Inline.pm,v
retrieving revision 1.14
retrieving revision 1.15
diff -Llib/MKDoc/Text/Structured/Inline.pm -Llib/MKDoc/Text/Structured/Inline.pm -u -r1.14 -r1.15
--- lib/MKDoc/Text/Structured/Inline.pm
+++ lib/MKDoc/Text/Structured/Inline.pm
@@ -69,6 +69,7 @@
     _make_doublequotes();
     _make_strong();
     _make_em();
+    _make_smilies();
     _break_long_words();
 
     $Text =~ s/^ //;
@@ -271,6 +272,18 @@
 }
 
 
+sub _make_smilies
+{
+    $Text = join '', map {
+	my $stuff = $_;
+        $stuff =~ s/:-\)/<span class="smilie-happy">:-)<\/span>/g unless ($stuff =~ /^</);
+        $stuff =~ s/:-\(/<span class="smilie-sad">:-(<\/span>/g unless ($stuff =~ /^</);
+        # don't do ;-) think about what happens with &-)
+        $stuff;
+    } _tokenize ($Text);
+}
+
+
 sub _break_long_words
 {
     $Text = join '', map {
--- /dev/null
+++ t/021_smilies.t
@@ -0,0 +1,27 @@
+use warnings;
+use strict;
+use Test::More 'no_plan';
+use lib ('lib', '../lib');
+use MKDoc::Text::Structured;
+
+my $text = undef;
+
+$text = MKDoc::Text::Structured::process ('This :-)is a;-) test :-(');
+is ($text, '<p>This <span class="smilie-happy">:-)</span>is a;-) test <span class="smilie-sad">:-(</span></p>');
+
+$text = MKDoc::Text::Structured::process ('test &-) test');
+is ($text, '<p>test &amp;-) test</p>');
+
+$text = MKDoc::Text::Structured::process ('BBC (Brit Broad Corp :-) test');
+is ($text, '<p><abbr title="Brit Broad Corp :-">BBC</abbr> (Brit Broad Corp <span class="smilie-happy">:-)</span> test</p>');
+
+$text = MKDoc::Text::Structured::process ('BBC(Brit Broad Corp :-) test');
+is ($text, '<p><abbr title="Brit Broad Corp :-">BBC</abbr> test</p>');
+
+$text = MKDoc::Text::Structured::process ('BBC(Brit Broad Corp :-( ) test');
+is ($text, '<p><abbr title="Brit Broad Corp :-(">BBC</abbr> test</p>');
+
+$text = MKDoc::Text::Structured::process ('This is a test: mailto:-)@mkdoc.com');
+is ($text, '<p>This is a test: <a href="mailto:-)@mkdoc.com">-)@mkdoc.com</a></p>');
+
+__END__
Index: 010_ul.t
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/t/010_ul.t,v
retrieving revision 1.5
retrieving revision 1.6
diff -Lt/010_ul.t -Lt/010_ul.t -u -r1.5 -r1.6
--- t/010_ul.t
+++ t/010_ul.t
@@ -18,7 +18,7 @@
   - Also, I can have sub-lists
   - That's no problem
   - Notice that '*' and '-' have the same meaning.
-    It's just syntaxic sugar, really :-)
+    It's just syntaxic sugar, really
 EOF
 
 my $res = MKDoc::Text::Structured::process ($text);
@@ -30,7 +30,7 @@
 like ($res, qr#<ul><li><p>Also, I can have sub-lists</p></li>#);
 like ($res, qr#<li><p>That's no problem</p></li>#);
 like ($res, qr#<li><p>Notice that &lsquo;\*&rsquo; and &lsquo;-&rsquo; have the same meaning.#);
-like ($res, qr#It's just syntaxic sugar, really :-\)</p></li></ul></li></ul>#);
+like ($res, qr#It's just syntaxic sugar, really</p></li></ul></li></ul>#);
 
 1;
 


More information about the MKDoc-commit mailing list