[MKDoc-commit] [MKDoc-Text-Structured] Test and fix for URI
surrounded by <> bug
bruno at mkdoc.demon.co.uk
bruno at mkdoc.demon.co.uk
Wed Mar 30 14:42:43 BST 2005
Log Message:
-----------
[MKDoc-Text-Structured] Test and fix for URI surrounded by <> bug
Modified Files:
--------------
MKDoc-Text-Structured:
Changes
MANIFEST
MKDoc-Text-Structured/lib/MKDoc/Text/Structured:
Inline.pm
Added Files:
-----------
MKDoc-Text-Structured/t:
016_uri.t
-------------- next part --------------
Index: MANIFEST
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/MANIFEST,v
retrieving revision 1.2
retrieving revision 1.3
diff -LMANIFEST -LMANIFEST -u -r1.2 -r1.3
--- MANIFEST
+++ MANIFEST
@@ -33,3 +33,4 @@
t/013_pre_sep.t
t/014_niceties.t
t/015_becky_marketeese.t
+t/016_uri.t
Index: Changes
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/Changes,v
retrieving revision 1.17
retrieving revision 1.18
diff -LChanges -LChanges -u -r1.17 -r1.18
--- Changes
+++ Changes
@@ -3,6 +3,7 @@
0.81
- removed defunct email address
- Documented entity substitution
+ - Test and fix for URI surrounded by <> bug
0.8 Thu Jul 22 17:51:30 2004
- Fixed Bruno's broken trailing spaces patch ;-)
Index: Inline.pm
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/lib/MKDoc/Text/Structured/Inline.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -Llib/MKDoc/Text/Structured/Inline.pm -Llib/MKDoc/Text/Structured/Inline.pm -u -r1.7 -r1.8
--- lib/MKDoc/Text/Structured/Inline.pm
+++ lib/MKDoc/Text/Structured/Inline.pm
@@ -11,11 +11,11 @@
local $Text;
$Text = shift;
$Text = " $Text ";
- $Text =~ s/&/&/g;
- $Text =~ s/</</g;
- $Text =~ s/>/>/g;
$Text =~ s/\n/ /gsm;
+ _make_entities();
+
+ $Text =~ s/>/ >/g;
# automagically finds hyperlinks
my $finder = URI::Find->new (
sub {
@@ -24,15 +24,7 @@
}
);
$finder->find (\$Text);
-
- $Text =~ s/(?<=(?:\s|\n))--(?=(?:\s|\n))/\—/g; # -- becomes em-dash
- $Text =~ s/(?<=(?:\s|\n))-(?=(?:\s|\n))/\–/g; # - becomes en-dash
- $Text =~ s/(?<!\.)\.\.\.(?!\.)/\…/g; # ... becomes ellipsis
-
- $Text =~ s/\(tm\)(?=(?:\s|\n|\p{IsPunct}))/\™/gi; # (tm) becomes trademark
- $Text =~ s/\(r\)(?=(?:\s|\n|\p{IsPunct}))/\®/gi; # (r) becomes registered
- $Text =~ s/\(c\)(?=(?:\s|\n|\p{IsPunct}))/\©/gi; # (c) becomes copyright
- $Text =~ s/(?<=(?:\s|\n))(\d+)\s*x\s*(\d+)(?=(?:\s|\n|\p{isPunct}))/$1\×$2/g; # x becomes dimension
+ $Text =~ s/ >/>/g;
# abbreviations
while ($Text =~ s/([[:upper:]][[:upper:]]+)\s+(\(.*?\))/_make_abbr_implicit ($1, $2)/e) {}; # implicit
@@ -48,6 +40,23 @@
}
+sub _make_entities
+{
+ $Text =~ s/&/&/g;
+ $Text =~ s/</</g;
+ $Text =~ s/>/>/g;
+
+ $Text =~ s/(?<=(?:\s|\n))--(?=(?:\s|\n))/\—/g; # -- becomes em-dash
+ $Text =~ s/(?<=(?:\s|\n))-(?=(?:\s|\n))/\–/g; # - becomes en-dash
+ $Text =~ s/(?<!\.)\.\.\.(?!\.)/\…/g; # ... becomes ellipsis
+
+ $Text =~ s/\(tm\)(?=(?:\s|\n|\p{IsPunct}))/\™/gi; # (tm) becomes trademark
+ $Text =~ s/\(r\)(?=(?:\s|\n|\p{IsPunct}))/\®/gi; # (r) becomes registered
+ $Text =~ s/\(c\)(?=(?:\s|\n|\p{IsPunct}))/\©/gi; # (c) becomes copyright
+ $Text =~ s/(?<=(?:\s|\n))(\d+)\s*x\s*(\d+)(?=(?:\s|\n|\p{isPunct}))/$1\×$2/g; # x becomes dimension
+}
+
+
sub _make_abbr_implicit
{
my $abbr = shift;
--- /dev/null
+++ t/016_uri.t
@@ -0,0 +1,18 @@
+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: http://www.google.com/");
+is ($text, '<p>This is a test: <a href="http://www.google.com/">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: <<a href="http://www.google.com/">http://www.google.com/</a>></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&c=d">http://www.google.com/?a=b&c=d</a></p>');
+
+__END__
More information about the MKDoc-commit
mailing list