[rkward-cvs] SF.net SVN: rkward:[3991] trunk/rkward/packages/XiMpLe
m-eik at users.sourceforge.net
m-eik at users.sourceforge.net
Sun Oct 23 17:16:43 UTC 2011
Revision: 3991
http://rkward.svn.sourceforge.net/rkward/?rev=3991&view=rev
Author: m-eik
Date: 2011-10-23 17:16:43 +0000 (Sun, 23 Oct 2011)
Log Message:
-----------
XiMpLe: indent comments, tidy "&" symbol
Modified Paths:
--------------
trunk/rkward/packages/XiMpLe/ChangeLog
trunk/rkward/packages/XiMpLe/DESCRIPTION
trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R
trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R
trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R
trunk/rkward/packages/XiMpLe/inst/CITATION
trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd
trunk/rkward/packages/XiMpLe/man/pasteXMLTag.Rd
Modified: trunk/rkward/packages/XiMpLe/ChangeLog
===================================================================
--- trunk/rkward/packages/XiMpLe/ChangeLog 2011-10-23 16:16:01 UTC (rev 3990)
+++ trunk/rkward/packages/XiMpLe/ChangeLog 2011-10-23 17:16:43 UTC (rev 3991)
@@ -1,5 +1,9 @@
ChangeLog for package XiMpLe
+## 0.03-7 (2011-10-23)
+ - added "&" to the special characters for "tidy" (only applies if theres space before and after)
+ - "tidy" now also indents text in comments and CDATA if it includes the newline character
+
## 0.03-6 (2011-10-09)
- added "tidy" option to the paste functions, which is TRUE by default since "<" and ">" are
invalid in attributes and text anyway
Modified: trunk/rkward/packages/XiMpLe/DESCRIPTION
===================================================================
--- trunk/rkward/packages/XiMpLe/DESCRIPTION 2011-10-23 16:16:01 UTC (rev 3990)
+++ trunk/rkward/packages/XiMpLe/DESCRIPTION 2011-10-23 17:16:43 UTC (rev 3991)
@@ -19,8 +19,8 @@
URL: http://rkward.sourceforge.net
Authors at R: c(person(given="Meik", family="Michalke",
email="meik.michalke at hhu.de", role=c("aut", "cre")))
-Version: 0.03-6
-Date: 2011-10-09
+Version: 0.03-7
+Date: 2011-10-23
Collate:
'XiMpLe.node-class.R'
'XiMpLe.doc-class.R'
Modified: trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R 2011-10-23 16:16:01 UTC (rev 3990)
+++ trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R 2011-10-23 17:16:43 UTC (rev 3991)
@@ -108,7 +108,7 @@
# with harmless entities
xml.tidy <- function(text){
if(is.character(text)){
- tidy.text <- gsub("<", "<", gsub(">", ">", text))
+ tidy.text <- gsub("<", "<", gsub(">", ">", gsub("([[:space:]])&([[:space:]])", "\\1&\\2", text, perl=TRUE)))
} else {
return(text)
}
Modified: trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R 2011-10-23 16:16:01 UTC (rev 3990)
+++ trunk/rkward/packages/XiMpLe/R/XiMpLe-package.R 2011-10-23 17:16:43 UTC (rev 3991)
@@ -3,8 +3,8 @@
#' \tabular{ll}{
#' Package: \tab XiMpLe\cr
#' Type: \tab Package\cr
-#' Version: \tab 0.03-6\cr
-#' Date: \tab 2011-10-09\cr
+#' Version: \tab 0.03-7\cr
+#' Date: \tab 2011-10-23\cr
#' Depends: \tab R (>= 2.9.0),methods\cr
#' Enhances: \tab rkward\cr
#' Encoding: \tab UTF-8\cr
Modified: trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R 2011-10-23 16:16:01 UTC (rev 3990)
+++ trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R 2011-10-23 17:16:43 UTC (rev 3991)
@@ -20,8 +20,9 @@
#' \item{2}{Nodes will be indented and each attribute gets a new line.}
#' }
#' @param indent.by A charachter string defining how indentation should be done. Defaults to tab.
-#' @param tidy Logical, if \code{TRUE} the special characters "<" and ">" will be replaced with the entities
-#' "<" and "gt;" in attribute values.
+#' @param tidy Logical, if \code{TRUE} the special characters "<", ">" and "&" will be replaced with the entities
+#' "<", ">" and "&" in attribute values. For comment or CDATA tags, if the text includes newline characters
+#' they will also be indented.
#' @export
pasteXMLTag <- function(tag, attr=NULL, child=NULL, empty=TRUE, level=1, allow.empty=FALSE, rename=NULL, shine=2, indent.by="\t", tidy=TRUE){
# what attributes do we have?
@@ -37,14 +38,33 @@
new.attr.indent <- ifelse(shine > 1, indent(level, by=indent.by), "")
attr.space <- ifelse(nchar(all.attributes) > 0, " ", "")
new.cmmt.indent <- ifelse(shine > 1, indent(level + 1, by=indent.by), "")
+ comment.indent <- ifelse(shine > 0, indent(level + 1, by=indent.by), "")
# three special cases: value pseudotags, comments and CDATA
if(isTRUE(nchar(tag) == 0) | length(tag) == 0){
full.tag <- paste(new.indent, child, new.node, sep="")
} else if(identical(tag, "!--")){
- full.tag <- paste(new.indent, "<!-- ", new.attr, new.cmmt.indent, if(!is.null(child)){trim(child)}, " ", new.attr, new.attr.indent, "-->", new.node, sep="")
+ # clean up value if needed
+ if(!is.null(child)){
+ child <- trim(child)
+ if(isTRUE(tidy)){
+ child <- gsub("\n", paste("\n", comment.indent, sep=""), child)
+ }
+ } else {}
+ full.tag <- paste(new.indent, "<!-- ", new.attr, new.cmmt.indent,
+ child, " ", new.attr, new.attr.indent,
+ "-->", new.node, sep="")
} else if(identical(tag, "![CDATA[")){
- full.tag <- paste(new.indent, "<![CDATA[ ", new.attr, new.cmmt.indent, if(!is.null(child)){trim(child)}, " ", new.attr, new.attr.indent, "]]>", new.node, sep="")
+ # clean up value if needed
+ if(!is.null(child)){
+ child <- trim(child)
+ if(isTRUE(tidy)){
+ child <- gsub("\n", paste("\n", comment.indent, sep=""), child)
+ }
+ } else {}
+ full.tag <- paste(new.indent, "<![CDATA[ ", new.attr, new.cmmt.indent,
+ child, " ", new.attr, new.attr.indent,
+ "]]>", new.node, sep="")
} else {
# only put attributes in new lines if there's more than one
new.attr <- ifelse((length(attr) > 1), new.attr, "")
Modified: trunk/rkward/packages/XiMpLe/inst/CITATION
===================================================================
--- trunk/rkward/packages/XiMpLe/inst/CITATION 2011-10-23 16:16:01 UTC (rev 3990)
+++ trunk/rkward/packages/XiMpLe/inst/CITATION 2011-10-23 17:16:43 UTC (rev 3991)
@@ -2,12 +2,12 @@
title="XiMpLe: A simple XML tree parser and generator",
author="Meik Michalke",
year="2011",
- note="(Version 0.03-6)",
+ note="(Version 0.03-7)",
url="http://rkward.sourceforge.net",
textVersion =
paste("Michalke, M. (2011). ",
- "XiMpLe: A simple XML tree parser and generator (Version 0.03-6). ",
+ "XiMpLe: A simple XML tree parser and generator (Version 0.03-7). ",
"Available from http://rkward.sourceforge.net",
sep=""),
Modified: trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd 2011-10-23 16:16:01 UTC (rev 3990)
+++ trunk/rkward/packages/XiMpLe/man/XiMpLe-package.Rd 2011-10-23 17:16:43 UTC (rev 3991)
@@ -8,8 +8,8 @@
}
\details{
\tabular{ll}{ Package: \tab XiMpLe\cr Type: \tab
- Package\cr Version: \tab 0.03-6\cr Date: \tab
- 2011-10-09\cr Depends: \tab R (>= 2.9.0),methods\cr
+ Package\cr Version: \tab 0.03-7\cr Date: \tab
+ 2011-10-23\cr Depends: \tab R (>= 2.9.0),methods\cr
Enhances: \tab rkward\cr Encoding: \tab UTF-8\cr License:
\tab GPL (>= 3)\cr LazyLoad: \tab yes\cr URL: \tab
http://rkward.sourceforge.net\cr }
Modified: trunk/rkward/packages/XiMpLe/man/pasteXMLTag.Rd
===================================================================
--- trunk/rkward/packages/XiMpLe/man/pasteXMLTag.Rd 2011-10-23 16:16:01 UTC (rev 3990)
+++ trunk/rkward/packages/XiMpLe/man/pasteXMLTag.Rd 2011-10-23 17:16:43 UTC (rev 3991)
@@ -39,8 +39,10 @@
indentation should be done. Defaults to tab.}
\item{tidy}{Logical, if \code{TRUE} the special
- characters "<" and ">" will be replaced with the entities
- "<" and "gt;" in attribute values.}
+ characters "<", ">" and "&" will be replaced with the
+ entities "<", ">" and "&" in attribute values.
+ For comment or CDATA tags, if the text includes newline
+ characters they will also be indented.}
}
\description{
Creates a whole XML tag with attributes and, if it is a
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list