Index: src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java =================================================================== --- src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java (revision 618659) +++ src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java Tue Feb 05 17:47:33 CET 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( "", 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 ) @@ -125,6 +135,19 @@ } /** + * 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() ) ) ); + } + + /** * Parses the url * @param line the line to parse * @param ret where the results live Index: src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java =================================================================== --- src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java (revision 618659) +++ src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java Tue Feb 05 17:49:59 CET 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: isn't it great?!").toArray( TOARRAY ); + assertTrue( Arrays.equals( expected, blocks ) ); -} + } +}