maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r619983 - in /maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src: main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java
Date Fri, 08 Feb 2008 19:56:48 GMT
Author: ltheussl
Date: Fri Feb  8 11:56:42 2008
New Revision: 619983

URL: http://svn.apache.org/viewvc?rev=619983&view=rev
Log:
[DOXIA-212] Twiki: add local image support
Submitted by: Gabriel Falkenberg

Modified:
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java?rev=619983&r1=619982&r2=619983&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java
Fri Feb  8 11:56:42 2008
@@ -67,6 +67,12 @@
         Pattern.compile( "(.*)\\.(png|jpg|gif|bmp)" );
     
     /**
+     *  image tag pattern specification (used for images at relative URLs)
+     */
+    private static final Pattern IMAGE_TAG_PATTERN =
+        Pattern.compile( "<img\\b.*?\\bsrc=([\"'])(.*?)\\1.*>", Pattern.CASE_INSENSITIVE
);
+
+    /**
      * resolves wikiWordLinks
      */
     private final WikiWordLinkResolver wikiWordLinkResolver;
@@ -92,6 +98,7 @@
         final Matcher forcedLinkMatcher = FORCEDLINK_PATTERN.matcher( line );
         final Matcher anchorMatcher = ANCHOR_PATTERN.matcher( line );
         final Matcher urlMatcher = URL_PATTERN.matcher( line );
+        final Matcher imageTagMatcher = IMAGE_TAG_PATTERN.matcher( line );
 
         if ( linkMatcher.find() )
         {
@@ -113,6 +120,9 @@
         {
             parseUrl( line, ret, urlMatcher );
         }
+        else if ( imageTagMatcher.find() ) {
+            parseImage( line, ret, imageTagMatcher );
+        }
         else
         {
             if ( line.length() != 0 )
@@ -122,6 +132,19 @@
         }
 
         return ret;
+    }
+
+    /**
+     * Parses the image tag
+     * @param line the line to parse
+     * @param ret where the results live
+     * @param imageTagMatcher image tag matcher
+     */
+    private void parseImage(final String line, final List ret, final Matcher imageTagMatcher)
{
+        ret.addAll( parse( line.substring( 0, imageTagMatcher.start() ) ) );
+        final String src = imageTagMatcher.group( 2 );
+        ret.add( new ImageBlock( src ) );
+        ret.addAll( parse( line.substring( imageTagMatcher.end(), line.length() ) ) );
     }
 
     /**

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java?rev=619983&r1=619982&r2=619983&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java
Fri Feb  8 11:56:42 2008
@@ -353,4 +353,21 @@
             TOARRAY );
         assertTrue( Arrays.equals( expected, blocks ) );
     }
+
+    /**
+     * Test image inserted with a html img tag
+     */
+    public final void testRelativeImage()
+    {
+        Block [] blocks, expected;
+
+        expected = new Block[]{
+            new TextBlock( "My summer house: " ),
+            new ImageBlock( "images/summerhouse.png" ),
+            new TextBlock( " isn't it great?!" ),
+        };
+        blocks = (Block[]) textParser.parse(
+            "My summer house: <img class=\"some_class\" src=\"images/summerhouse.png\"/>
isn't it great?!").toArray( TOARRAY );
+        assertTrue( Arrays.equals( expected, blocks ) );
+    }
 }



Mime
View raw message