From: <ad...@us...> - 2010-11-26 04:08:29
|
Revision: 1237 http://jtidy.svn.sourceforge.net/jtidy/?rev=1237&view=rev Author: aditsu Date: 2010-11-26 04:08:23 +0000 (Fri, 26 Nov 2010) Log Message: ----------- fixed test 588061 (and partly 1603538-1) - added isPushedLast (only in tidy compat mode), and iToken and related logic in getToken Modified Paths: -------------- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Lexer.java branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/ParserImpl.java Modified: branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Lexer.java =================================================================== --- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Lexer.java 2010-11-26 00:21:24 UTC (rev 1236) +++ branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Lexer.java 2010-11-26 04:08:23 UTC (rev 1237) @@ -310,6 +310,8 @@ * current node. */ protected Node token; + + protected Node itoken; /** * Lexer character buffer parse tree nodes span onto this buffer which contains the concatenated text contents of @@ -1584,30 +1586,37 @@ * </ul> * @return next Node */ - public Node getToken(short mode) - { - int c = 0; - int badcomment = 0; - // pass by reference - boolean[] isempty = new boolean[1]; - AttVal attributes = null; - - if (this.pushed) - { + public Node getToken(short mode) { + if (pushed || itoken != null) { + /* Deal with previously returned duplicate inline token */ + if (itoken != null) { + /* itoken rejected */ + if (pushed) { + pushed = false; + return itoken; + } + /* itoken has been accepted */ + itoken = null; + } // duplicate inlines in preference to pushed text nodes when appropriate - if (this.token.type != NodeType.TextNode || (this.insert == -1 && this.inode == null)) - { - this.pushed = false; - return this.token; + pushed = false; + if (token.type != NodeType.TextNode || (insert == -1 && inode == null)) { + return token; } + return itoken = insertedToken(); } // at start of block elements, unclosed inline // elements are inserted into the token stream - if (this.insert != -1 || this.inode != null) - { - return insertedToken(); + if (this.insert != -1 || inode != null) { + return token = insertedToken(); } + + int c = 0; + int badcomment = 0; + // pass by reference + boolean[] isempty = new boolean[1]; + AttVal attributes = null; this.lines = this.in.getCurline(); this.columns = this.in.getCurcol(); @@ -3453,6 +3462,16 @@ } /** + * Tests whether the last element on the stack has the same type as "node". + */ + protected boolean isPushedLast(final Node element, final Node node) { + if (element != null && !element.isPushable()) { + return false; + } + return !istack.isEmpty() && istack.peek().tag == node.tag; + } + + /** * This has the effect of inserting "missing" inline elements around the contents of blocklevel elements such as P, * TD, TH, DIV, PRE etc. This procedure is called at the start of ParseBlock. When the inline stack is not empty, as * will be the case in: <code><i><h1>italic heading</h1></i></code> which is then treated as Modified: branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java =================================================================== --- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-26 00:21:24 UTC (rev 1236) +++ branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/Node.java 2010-11-26 04:08:23 UTC (rev 1237) @@ -1455,4 +1455,8 @@ } next = node; } + + protected boolean isPushable() { + return tag != null && hasCM(Dict.CM_INLINE) && !hasCM(Dict.CM_OBJECT); + } } Modified: branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/ParserImpl.java =================================================================== --- branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/ParserImpl.java 2010-11-26 00:21:24 UTC (rev 1236) +++ branches/CodeUpdateAndJava5/src/main/java/org/w3c/tidy/ParserImpl.java 2010-11-26 04:08:23 UTC (rev 1237) @@ -1514,11 +1514,10 @@ lexer.report.warning(lexer, element, node, ErrorCode.MISSING_ENDTAG_BEFORE); } - if (element.is(TagId.A)) - { + if (lexer.configuration.isTidyCompat() ? lexer.isPushedLast(element, node) + : element.is(TagId.A)) { lexer.popInline(element); } - lexer.ungetToken(); if (!((mode & Lexer.PREFORMATTED) != 0)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |