Created
July 31, 2012 17:53
-
-
Save dwoll/3218931 to your computer and use it in GitHub Desktop.
knit2wp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
knit2wp <- function(file) { | |
require(XML) | |
content <- readLines(file) | |
content <- htmlTreeParse(content, trim=FALSE) | |
content <- paste(capture.output(print(content$children$html$children$body, | |
indent=FALSE, tagSeparator="")), | |
collapse="\n") | |
content <- gsub("<?.body>", "", content) | |
content <- gsub("<?pre><code class=\"r\">", "\\[code lang='r'\\]\\\n", | |
content) | |
content <- gsub("<?pre><code class=\"no-highlight\">", "\\[code\\]\\\n", | |
content) | |
content <- gsub("<?pre><code>", "\\[code\\]\\\n", content) | |
content <- gsub("<?/code></pre>", "\\[/code\\]\\\n", content) | |
return(content) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment