I was dumb enough not to know how to
get R codes into my posts right until in the last few of them.
From the beginning, I wrote my posts in
MS Word and later in Open Office Writer. I created my pictures in
GIMP. Then I copy and paste the text of the post on to the “Compose”
sheet for my new post in Blogger. I never bothered to learn
HTML and so I didn't select
the other option, that is, “HTML”. The text was OK. Next, I
upload my pictures and place them in my post, and it was OK too.
But when I paste my
text containing R code, it went funny. For example
would come out on
the blog as
So, what I did was
make a picture of the R code by first converting the text of the code
in Open Office Writer to pdf format, and then converting it
into a picture with GIMP. It worked, but the resolution of the code
wasn't that good. Also, the downside of it was that you couldn't copy
the code from my post and run it on the R console directly or via a
script file.
Well, that isn't my
problem, I must have thought, until recently. Then, I tried inserting
R code that was more than a page long to my post in the usual way via
an image. But the result turned out to be ugly!
So I tried
processing my post first by converting my draft directly to HTML
in Open Office Writer. But it didn't work. Next I tried using
Notepad++ for conversion to HTML and it didn't
work either. May be because I didn't know them well enough and may be
I should visit them again later.
Now I can see that
the obvious solution will be to type my post out on the “Compose”
sheet of Blogger. But it seemed like the dumbest thing to do, even
for a dummy like me. Since the text of my posts which have been
composed with Open Office Writer could be pasted without problem on
to the compose sheet of Blogger, the next step in my preferred
workflow would be to correctly add my R code by copy and paste from
my R scripts, and finally to upload and paste my pictures. As I've
shown earlier, I would need to format my codes in some way so
that they would be displayed correctly in my post.
So I
looked around for some solution and luckily
found a number of alternatives. Generally I would need to look for
some kind of markdown
language since we were told that the Markdown language
was created with
the
goal of enabling people
"to write using an easy-to-read, easy-to-write plain text
format, and optionally convert it to structurally valid XHTML(or
HTML)".
That led me to StackEdit, though
after a good deal of false leads and frustrations.
To
start with, like a lot of other guys, I thought that if I could
convert my post into Google docs format I would be able copy and
paste it to Blogger. But in reality it was not to be.
Fortunately
I found that I could just copy the content from my Open Office
Writer document and paste it directly to Blogger! However, R
codes
and data tables
will not come out correctly and images will not come out at all.
Anyway, I wanted to confirm if it is really impossible to copy and
paste from Google docs to Blogger and found that it is indeed
impossible (in a post from Blogger Help Forum here).
Besides, a number of alternatives were suggested and there I found
mmplex's suggestion for StackEdit attractive as “a
free online markdown editor that allows directly posting to blogger.
You can edit offline also and synchronize your documents with drive
or dropbox. It even works pretty well in a tablet. Notice that it's
far more powerful than docs if you post math formulas or code
snippets.”
I added StackEdit
application from the chrome web store:
(1) Now let's write
my toy example in Open Office Writer:
(2) Then I copy and
paste it in Blogger compose sheet:
(3) Looks fine, but
… preview gives:
(4) So I open the
StackEdit application and paste my two lines of R code.
(5) Then I click
the hash button in the navigation bar and choose to save it to disk
as HTML.
What I need to do
now is to insert my two lines of R code formatted as HTML into my
unfinished blogger post previewed in step (3) above. To finish it -
(6) I open the
saved HTML file of R code in Chrome, view page source, copy it and
replace the incorrectly formatted lines of R code in the HTML sheet
in Blogger
and finally get it
right!
About
the line “Written
with StackEdit.” added by the StackEdit
application, the answer
by benweet of October 19, 2013 said:
“I'm the creator of
StackEdit, which is designed to write Markdown documents and blog
posts, not to write questions/answers on Stack Exchange. As mentioned
in StackEdit's settings, this footer is to encourage users to support
the project by adding a backlink in their documents/posts. It's there
by default but it's fully removable/customizable.
Since it's a free
application and it has no budget for advertising, I'm opposed to
removing it from the application. However I will add few words about
this issue in the settings or in the welcome document.”
Well, I chose to
delete that line before I was aware of benweet's reply, and still do
so. I hope he won't mind.
As for this post,
you'll have noticed that I said nothing about formatting and other
goodies of StackEdit. That's because I still need to learn … and as
for you, stray further if you like. Have fun, and do experiment!
Still one thing.
Why was such a fuss that Open Office Writer could convert my post to
HTML with ease, but wouldn't come out correctly in Blogger?
This
remark refers to HTML produced by RStudio but it could
as well be applicable to HTML produced by Open Office Writer, or some
other application:
“You
might think that you’d simply be able to open up the source HTML in
a text editor, copy the source code, and paste it into your blog
editor as HTML. But the HTML file that R produces is probably going
to be swarmed with hundreds (or, gasp, thousands) of lines of
disgusting Javascript. This almost certainly won’t be supported by
your blogging site, and you’ll end up with a blank page.”