Author: abelevich
Date: 2008-11-17 13:03:17 -0500 (Mon, 17 Nov 2008)
New Revision: 11193
Modified:
trunk/sandbox/ui/editor/src/main/antlr/html-seamtext.g
Log:
Modified: trunk/sandbox/ui/editor/src/main/antlr/html-seamtext.g
===================================================================
--- trunk/sandbox/ui/editor/src/main/antlr/html-seamtext.g 2008-11-17 16:15:17 UTC (rev
11192)
+++ trunk/sandbox/ui/editor/src/main/antlr/html-seamtext.g 2008-11-17 18:03:17 UTC (rev
11193)
@@ -210,7 +210,6 @@
if (!containText) {
result.append("\n").append("<span></span>");
- isHeaderProcessed = true;
}
return result.toString();
}
@@ -226,7 +225,7 @@
token = LT(i);
if (token.getType() == ALPHANUMERICWORD) {
if(!(isParagraph(token) || isHeader(token) || isList(token))) {
- return "\n\n";
+ return BLANK_LINE;
}
break ;
}
@@ -243,8 +242,7 @@
token = LT(i);
if (token.getType() == ALPHANUMERICWORD) {
if(!(isParagraph(token) || isHeader(token))) {
- System.out.println(token);
- return "\n\n";
+ return BLANK_LINE;
}
break;
@@ -309,13 +307,16 @@
if(!isSeamTextElement(name)) {
return true;
}
-
+
+ if(isHeader(name) && !htmlElementStack.isEmpty()) {
+ return true;
+ }
+
if(!htmlElementStack.isEmpty() &&
!"a".equals(name.getText().toLowerCase()) &&
!"p".equals(name.getText().toLowerCase())) {
for(Token token : htmlElementStack) {
- if(token.getText().equals("h1") || token.getText().equals("h2")
|| token.getText().equals("h3")
- || token.getText().equals("h4") || token.getText().equals("li"))
{
+ if(isHeader(token) || isListItem(token)) {
return true;
- }
+ }
}
}
@@ -420,28 +421,26 @@
text: ((seamCharacters|plain|html|htmlSpecialChars) (NEWLINE
{
- Token token = LT(2);
-// newlines++;
- if(!isParagraph(token)) {
- if(isHeaderProcessed) {
+ Token token = LT(2);
+ if(!isParagraph(token) && isHeaderProcessed) {
isHeaderProcessed = false;
- }
- }
+ }
}
)*)+
;
-plain: (word|punctuation|space:SPACE {append(space.getText());})
+plain: (word|punctuation|space:SPACE {
+ append(space.getText());}
+ )
- {
-
- Token token = LT(2);
- if (isList(token)) {
-// append(BLANK_LINE);
- }
- }
+ {
+ Token token = LT(2);
+ if(!isParagraph(token) && isHeaderProcessed) {
+ isHeaderProcessed = false;
+ }
+ }
;
word: an:ALPHANUMERICWORD { append( an.getText() ); } | uc:UNICODEWORD { append(
uc.getText() ); }
@@ -493,10 +492,11 @@
space: s:SPACE {
if(!htmlElementStack.isEmpty()) {
- Token token = htmlElementStack.peek();
- if(!isSeamTextElement(token)) {
- append(s.getText());
- }
+ Token token = htmlElementStack.pop();
+ if(isPlainHMTLRequired(token, htmlElementStack)) {
+ append(s.getText());
+ }
+ htmlElementStack.push(token);
}
}
;
@@ -526,7 +526,7 @@
{
Token token = htmlElementStack.peek();
if(isLink(token)) {
- String message = "unexpected token";
+ String message = "Unexpected token " + "<" + token.getText()
+ ">";
throw new SemanticException(message);
}
}
@@ -570,9 +570,10 @@
append(BLANK_LINE);
} else if (isListItem(name)) {
append(createSeamTextList(name, htmlElementStack));
- }else if (isHeader(name)) {
- append(createSeamTextHeader(name));
- }else if(isParagraph(name)) {
+ } else if (isHeader(name)) {
+ append(createSeamTextHeader(name));
+
+ }else if(isParagraph(name) && !isHeaderProcessed) {
if(!isHeaderProcessed) {
append(BLANK_LINE);
}
@@ -589,7 +590,13 @@
} else {
if(valueCollector != null) {
- append(valueCollector.toString().trim());
+ Token prevToken = htmlElementStack.peek();
+ if(isListItem(prevToken) && valueCollector.toString().trim().length()
== 0) {
+ append(" ");
+ } else {
+ append(valueCollector.toString().trim());
+ }
+
valueCollector = null;
}
append("<");
@@ -634,7 +641,10 @@
closeTagWithBody:
LT SLASH name:ALPHANUMERICWORD GT
{
- htmlElementStack.pop();
+ Token token = htmlElementStack.pop();
+ if(!token.getText().equals(name.getText())) {
+ throw new RecognitionException("Can not convert to the Seam Text:
</" +token.getText() + ">" + " expected");
+ }
String value = "";
if(valueCollector != null) {
value = valueCollector.toString();
@@ -648,23 +658,22 @@
append(value);
if(isHeaderProcessed) {
isHeaderProcessed = false;
- } else {
- append(checkParagraphMarkup());
- }
+ }
+ append(checkParagraphMarkup());
+
- } else {
- append(value.trim());
- }
+ } else {
+ append(value.trim());
+ }
- if(isList(name)) {
- append(checkListMarkup());
- } else if(isListItem(name)) {
- append(checkListItemMarkup());
- } else if(isHeader(name)) {
-// append("\n");
- append(checkHeaderMarkup());
- isHeaderProcessed = true;
- }
+ if(isList(name)) {
+ append(checkListMarkup());
+ } else if(isListItem(name)) {
+ append(checkListItemMarkup());
+ } else if(isHeader(name)) {
+ append(checkHeaderMarkup());
+ isHeaderProcessed = true;
+ }
} else if(isSimpleSeamTextElement(name)) {
append(value.trim());
@@ -695,11 +704,12 @@
attribute: att:ALPHANUMERICWORD (space)* EQ (space)*
DOUBLEQUOTE
{
- Token token = htmlElementStack.peek();
+ Token token = htmlElementStack.pop();
sanitizer.validateHtmlAttribute(token, att);
- boolean isSeamTextProcessed = isSeamTextElement(token);
+// boolean isSeamTextProcessed = isSeamTextElement(token);
+ boolean isPlainHMTLRequired = isPlainHMTLRequired(token,
htmlElementStack);
- if (!isSeamTextProcessed) {
+ if (isPlainHMTLRequired) {
append(att.getText());
append("=\"");
}
@@ -710,7 +720,7 @@
String attValue = endCapture();
sanitizer.validateHtmlAttributeValue(token, att, attValue);
- if (!isSeamTextProcessed) {
+ if (isPlainHMTLRequired) {
append(attValue);
} else if(isLink(token) && "href".equals(att.getText()))
{
@@ -719,9 +729,10 @@
}
DOUBLEQUOTE {
- if(!isSeamTextProcessed) {
+ if(isPlainHMTLRequired) {
append("\"");
}
+ htmlElementStack.push(token);
}
;
exception
Show replies by date