Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
legTools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leg
legTools
Commits
4e76bb02
Commit
4e76bb02
authored
9 years ago
by
Walmes Zeviani
Browse files
Options
Downloads
Patches
Plain Diff
Improve RWordPress allowing proper code highlight when using Crayon.
parent
9943c91e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/knit2wpCrayon.R
+82
-0
82 additions, 0 deletions
R/knit2wpCrayon.R
with
82 additions
and
0 deletions
R/knit2wpCrayon.R
0 → 100644
+
82
−
0
View file @
4e76bb02
#' @title knit to wordpress that uses crayon sintax highlight
#'
#' @name knit2wpCrayon
#'
#' @description This function improves the \code{RWordPress::knit2wp} to
#' allow properly render code when using Crayon Sintax Highlighter.
#'
#' @param input a markdown or Rmarkdown file.
#' @param title title for the post.
#' @param ... other meta information of the post. See
# \link[RWordPress]{knit2wp}.
#' @param action indicates a new post, a edition of the post or a new
#' page.
#' @param postid number of the post.
#' @param encoding ht encoding of the input file.
#' @param upload logical, if the file is to be updated to the blog.
#' @param publish logical, if the post is to be published or stay in
#' draft mode.
#' @param write logical, is the result of knit be written to a html
#' file. This is useful to copy from this file and paste inside the
#' wordpress post editor (on text mode, not visual mode).
#'
#' @return None is returned by the function.
#'
#' @author Walmes Zeviani, \email{walmes@@ufpr.br}
#'
#' @import knitr RWordPress
#' @export
#' @examples
#' \donttest{
#'
#' library(knitr)
#' library(RWordPress)
#'
#' post <- "2015-08-24_polyGui.Rmd"
#' title <- "Interface para regressão polinomial"
#' categ <- c("gui", "rbloggers_pt")
#' keywd <- c("gWdigets", "legTools", "lm", "poly")
#'
#' pass <- scan(n=1, what=character())
#' options(WordpressLogin=c(walmes=pass),
#' WordpressURL="http://blog.leg.ufpr.br/xmlrpc.php")
#'
#' knit2wpCrayon(post, title=title,
#' action="editPost", postid=179,
#' categories=categ, mt_keywords=keywd,
#' ## write=TRUE, upload=FALSE,
#' write=FALSE, upload=TRUE,
#' publish=FALSE)
#'
#' }
knit2wpCrayon
<-
function
(
input
,
title
=
"A post from knitr"
,
...
,
action
=
c
(
"newPost"
,
"editPost"
,
"newPage"
),
postid
,
encoding
=
getOption
(
"encoding"
),
upload
=
FALSE
,
publish
=
FALSE
,
write
=
TRUE
){
out
<-
knit
(
input
,
encoding
=
encoding
)
on.exit
(
unlink
(
out
))
con
<-
file
(
out
,
encoding
=
encoding
)
on.exit
(
close
(
con
),
add
=
TRUE
)
content
<-
knitr
:::
native_encode
(
readLines
(
con
,
warn
=
FALSE
))
content
<-
paste
(
content
,
collapse
=
"\n"
)
content
<-
markdown
::
markdownToHTML
(
text
=
content
,
fragment.only
=
TRUE
)
content
<-
gsub
(
pattern
=
"<pre><code class=\"([[:alpha:]]+)\">(.+?)</code></pre>"
,
replacement
=
"<pre class=\"lang:\\1 decode:true\">\\2</pre>"
,
x
=
content
)
content
=
knitr
:::
native_encode
(
content
,
"UTF-8"
)
title
=
knitr
:::
native_encode
(
title
,
"UTF-8"
)
if
(
write
){
writeLines
(
text
=
content
,
con
=
gsub
(
x
=
out
,
pattern
=
"\\.md$"
,
replacement
=
".html"
))
}
if
(
upload
){
action
=
match.arg
(
action
)
WPargs
=
list
(
content
=
list
(
description
=
content
,
title
=
title
,
...
),
publish
=
publish
)
if
(
action
==
"editPost"
)
WPargs
=
c
(
postid
=
postid
,
WPargs
)
do.call
(
"library"
,
list
(
package
=
"RWordPress"
,
character.only
=
TRUE
))
print
(
do.call
(
action
,
args
=
WPargs
))
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment