[MKDoc-commit] [MKDoc-Text-Structured] Added support for <a rel="nofollow" href="...

bruno at mkdoc.demon.co.uk bruno at mkdoc.demon.co.uk
Fri Aug 5 14:14:33 BST 2005


Log Message:
-----------
[MKDoc-Text-Structured] Added support for <a rel="nofollow" href="...

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

Added Files:
-----------
    MKDoc-Text-Structured/t:
        022_nofollow.t

-------------- next part --------------
Index: MANIFEST
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/MANIFEST,v
retrieving revision 1.6
retrieving revision 1.7
diff -LMANIFEST -LMANIFEST -u -r1.6 -r1.7
--- MANIFEST
+++ MANIFEST
@@ -39,3 +39,4 @@
 t/019_insert_spaces.t
 t/020_mailto.t
 t/021_smilies.t
+t/022_nofollow.t
Index: Changes
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/Changes,v
retrieving revision 1.26
retrieving revision 1.27
diff -LChanges -LChanges -u -r1.26 -r1.27
--- Changes
+++ Changes
@@ -6,6 +6,7 @@
     - strip mailto: when linking and displaying email addresses
     - documented MKDoc::Text::Structured::Inline
     - wrap smilies in CSS classes
+    - Added support for <a rel="nofollow" href="...
 
 0.82 Thu Mar 31 13:45:00 2005
     - fixed failure to change " to &quot; bug
Index: Structured.pm
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/lib/MKDoc/Text/Structured.pm,v
retrieving revision 1.28
retrieving revision 1.29
diff -Llib/MKDoc/Text/Structured.pm -Llib/MKDoc/Text/Structured.pm -u -r1.28 -r1.29
--- lib/MKDoc/Text/Structured.pm
+++ lib/MKDoc/Text/Structured.pm
@@ -312,6 +312,10 @@
 This module uses L<URI::Find> to locate URIs such as http://mkdoc.com/ and turn
 them into clickable links.
 
+Add rel="nofollow" attributes to <a> tags like so:
+
+  local $MKDoc::Text::Structured::Inline::NoFollow = 1;
+
 Additionally, once the XHTML fragment is produced, you could use
 L<MKDoc::XML::Tagger> to hyperlink it against a glossary of hyperlinks.
 
Index: Inline.pm
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/lib/MKDoc/Text/Structured/Inline.pm,v
retrieving revision 1.16
retrieving revision 1.17
diff -Llib/MKDoc/Text/Structured/Inline.pm -Llib/MKDoc/Text/Structured/Inline.pm -u -r1.16 -r1.17
--- lib/MKDoc/Text/Structured/Inline.pm
+++ lib/MKDoc/Text/Structured/Inline.pm
@@ -6,6 +6,7 @@
 our $Text    = '';
 
 our $LongestWord = 78;
+our $NoFollow = 0;
 
 =head1 NAME
 
@@ -56,7 +57,16 @@
         sub {
             my ($uri, $orig_uri) = @_;
             $orig_uri =~ s/^mailto://;
-            return qq|<a href="$uri">$orig_uri</a>|;
+
+            # http://googleblog.blogspot.com/2005/01/preventing-comment-spam.html
+            if ($NoFollow)
+            {
+                return qq|<a href="$uri" rel="nofollow">$orig_uri</a>|;
+            }
+            else
+            {
+                return qq|<a href="$uri">$orig_uri</a>|;
+            }
         }
     );
     $finder->find (\$Text);
--- /dev/null
+++ t/022_nofollow.t
@@ -0,0 +1,25 @@
+use warnings;
+use strict;
+use Test::More 'no_plan';
+use lib ('lib', '../lib');
+use MKDoc::Text::Structured;
+
+my $text = undef;
+
+$MKDoc::Text::Structured::Inline::NoFollow = 1;
+
+$text = MKDoc::Text::Structured::process ("This is a test: http://www.google.com/");
+is ($text, '<p>This is a test: <a href="http://www.google.com/" rel="nofollow">http://www.google.com/</a></p>');
+
+$text = MKDoc::Text::Structured::process ("This is a test: <http://www.google.com/>");
+is ($text, '<p>This is a test: &lt;<a href="http://www.google.com/" rel="nofollow">http://www.google.com/</a>&gt;</p>');
+
+$text = MKDoc::Text::Structured::process ("This is a test: http://www.google.com/?a=b&c=d");
+is ($text, '<p>This is a test: <a href="http://www.google.com/?a=b&amp;c=d" rel="nofollow">http://www.google.com/?a=b&amp;c=d</a></p>');
+
+undef $MKDoc::Text::Structured::Inline::NoFollow;
+
+$text = MKDoc::Text::Structured::process ("This is a test: http://www.google.com/");
+is ($text, '<p>This is a test: <a href="http://www.google.com/">http://www.google.com/</a></p>');
+
+__END__


More information about the MKDoc-commit mailing list