You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by vs...@apache.org on 2008/10/15 23:41:42 UTC
svn commit: r705062 - in
/maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser:
ParagraphBlockParser.java TextParser.java XHTMLBlock.java
Author: vsiveton
Date: Wed Oct 15 14:41:42 2008
New Revision: 705062
URL: http://svn.apache.org/viewvc?rev=705062&view=rev
Log:
DOXIA-261: The Twiki noautolink is not used at all
DOXIA-153: HTML tags in twiki not rendered correctly
o take care of html tags
o take care of noautolink
Added:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/XHTMLBlock.java (with props)
Modified:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/ParagraphBlockParser.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/ParagraphBlockParser.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/ParagraphBlockParser.java?rev=705062&r1=705061&r2=705062&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/ParagraphBlockParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/ParagraphBlockParser.java Wed Oct 15 14:41:42 2008
@@ -94,6 +94,7 @@
* 1. Skip begininig new lines
* 2. Get the text, while \n\n is not found
*/
+ boolean pre = false;
String l = line;
do
{
@@ -128,7 +129,25 @@
else
{
sb.append( l );
- sb.append( " " );
+ // specific
+ if ( l.indexOf( "<pre>" ) != -1 )
+ {
+ pre = true;
+ }
+ if ( l.indexOf( "</pre>" ) != -1 )
+ {
+ pre = false;
+ }
+
+ if ( !pre )
+ {
+ sb.append( " " );
+ }
+ else
+ {
+ // TODO use EOL
+ sb.append( "\n" );
+ }
}
}
l = source.getNextLine();
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=705062&r1=705061&r2=705062&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 Wed Oct 15 14:41:42 2008
@@ -71,11 +71,17 @@
private static final Pattern IMAGE_TAG_PATTERN =
Pattern.compile( "<img\\b.*?\\bsrc=([\"'])(.*?)\\1.*>", Pattern.CASE_INSENSITIVE );
+ /** HTML tag pattern */
+ private static final Pattern HTML_TAG_PATTERN = Pattern.compile( "<(/?)([\\w]*)(.*?)(/?)>", Pattern.DOTALL );
+
/**
* resolves wikiWordLinks
*/
private final WikiWordLinkResolver wikiWordLinkResolver;
+ /** resolves noautolink tag */
+ private boolean noautolink;
+
/**
* Creates the TextParser.
* @param resolver resolver for wikiWord links
@@ -100,11 +106,25 @@
final Matcher urlMatcher = URL_PATTERN.matcher( line );
final Matcher imageTagMatcher = IMAGE_TAG_PATTERN.matcher( line );
- if ( linkMatcher.find() )
+ final Matcher tagMatcher = HTML_TAG_PATTERN.matcher( line );
+ Matcher xhtmlMatcher = null;
+ if ( tagMatcher.find() )
+ {
+ String tag = tagMatcher.group( 2 );
+
+ Pattern pattern =
+ Pattern.compile( "(\\<" + tag + ".*\\>)(.*)?(\\<\\/" + tag + "\\>)(.*)?", Pattern.DOTALL );
+ xhtmlMatcher = pattern.matcher( line );
+ }
+
+ if ( xhtmlMatcher!= null && xhtmlMatcher.find() ) {
+ parseXHTML( line, ret, xhtmlMatcher );
+ }
+ else if ( linkMatcher.find() )
{
parseLink( line, ret, linkMatcher );
}
- else if ( wikiMatcher.find() && startLikeWord( wikiMatcher, line ) )
+ else if ( wikiMatcher.find() && startLikeWord( wikiMatcher, line ) && !noautolink )
{
parseWiki( line, ret, wikiMatcher );
}
@@ -310,6 +330,39 @@
ret.addAll( parse( line.substring( linkMatcher.end(), line.length() ) ) );
}
+
+ /**
+ * Parses xhtml.
+ *
+ * @param line the line to parse
+ * @param ret where the results live
+ * @param xhtmlMatcher xhtml matcher
+ */
+ private void parseXHTML( final String line, final List ret, final Matcher xhtmlMatcher )
+ {
+ if ( xhtmlMatcher.group( 1 ).indexOf( "noautolink" ) != -1 )
+ {
+ noautolink = true;
+ }
+ else
+ {
+ ret.add( new XHTMLBlock( xhtmlMatcher.group( 1 ) ) );
+ }
+
+ ret.addAll( parse( xhtmlMatcher.group( 2 ) ) );
+
+ if ( xhtmlMatcher.group( 1 ).indexOf( "noautolink" ) != -1 )
+ {
+ noautolink = false;
+ }
+ else
+ {
+ ret.add( new XHTMLBlock( xhtmlMatcher.group( 3 ) ) );
+ }
+
+ ret.addAll( parse( xhtmlMatcher.group( 4 ) ) );
+ }
+
/**
* @param m matcher to test
* @param line line to test
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/XHTMLBlock.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/XHTMLBlock.java?rev=705062&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/XHTMLBlock.java (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/XHTMLBlock.java Wed Oct 15 14:41:42 2008
@@ -0,0 +1,84 @@
+package org.apache.maven.doxia.module.twiki.parser;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+/**
+ * An XHTML Block
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+class XHTMLBlock implements Block
+{
+ private final String tag;
+
+ /**
+ * Creates the XHTMLBlock.
+ *
+ * @param tag the tag, eg: <pre>
+ * @throws IllegalArgumentException if the arguments are <code>null</code>
+ */
+ XHTMLBlock( final String tag ) throws IllegalArgumentException
+ {
+ if ( tag == null )
+ {
+ throw new IllegalArgumentException( "argument can't be null" );
+ }
+ this.tag = tag;
+ }
+
+ /** {@inheritDoc}*/
+ public final void traverse( final Sink sink )
+ {
+ if ( tag.trim().length() == 0)
+ {
+ return;
+ }
+
+ sink.rawText( tag );
+ }
+
+ /** {@inheritDoc}*/
+ public final boolean equals( final Object obj )
+ {
+ boolean ret = false;
+
+ if ( obj == this )
+ {
+ ret = true;
+ }
+ else if ( obj instanceof XHTMLBlock )
+ {
+ final XHTMLBlock a = (XHTMLBlock) obj;
+
+ ret = tag.equals( a.tag );
+ }
+
+ return ret;
+ }
+
+ /** {@inheritDoc}*/
+ public final int hashCode()
+ {
+ return tag.hashCode();
+ }
+}
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/XHTMLBlock.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/XHTMLBlock.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision