Linking to url with rmarkdown using Knit Word in Rstudio - r-markdown

Is there an easy way to link to a webpage in rmarkdown without displaying the link?
For example, putting "https://www.google.com/" in a .rmd file renders as the entire website, but I want something analogous to ABC instead.
The html method above, i.e., <a href= ... works when I knit to html, but it does not work when I knit to a word document.

Markdown provides two ways to create a link as you mention (and I suppose that is supported on rmarkdown).
Markdown way:
[ABC](http://example.com)
HTML way:
ABC
The first way is native and the second way is supported since Markdown allows every HTML code.

Related

R Blogdown with different Rmarkdown outputs

I built a blogdown site using Hugo and it has multiple sections, posts all written in Rmarkdown with outputs designed as html_document. It works fine.
In parallel, I designed an HTML dashboard using Rmarkdown with an output designed as flex_dashboard. It generates an HTML file working fine.
I wanted to integrate the dashboard directly within the building of the site but unfortunately by simply adding the Rmarkdown file in the blogdown structure it knits it as an html document and not as a flex_dashboard. So, I have the content within my website but not at all as dashboard but more like a traditional html_document. So no luck with that :(
I tried then copying the dashboard html under /static/html and create a brand new Rmarkdown just invoking my html within an iframe:
---
output: html_document
---
<link rel="preload" href="/html/OpenDashboard.html" as="document">
<iframe width="100%" height="600" name="iframe" src="/html/OpenDashboard.html"></iframe>
Looked good to me and was pretty happy even in inelegant but performance is bad. It takes a long time to load (+10sec) even if the file is not that big (only 6Mb). Size of the html will grow a lot in the future and I can't hope viewers will wait that long.
I read it was possible to clarify the type of knitting we want within a build.R file but I am clueless on how to specify I want html_document knitting for some Rmarkdowns and flex_dashboard for some others.
To answer your last question: in Section 2.7 of the blogdown book, it mentions that you could use blogdown::build_dir() in R/build.R to build arbitrary Rmd files under the static/ directory.

How to have the Layout convert a Page written in Markdown to HTML (using Zurb Foundation Panini)

I am using Zurb's Panini site generator. I am using a CMS that outputs a html file written in markdown to the pages folder. My goal was to have the template file convert the markdown to html.
I've tried to have the markdown get converted before it enters the template file but haven't found a way with the CMS I am using (NetlifyCMS). The CMS also needs to be very user friendly for non-technical users.
<!-- This is the part of the template file -->
<article class="cell medium-5 cell-block-y location-info-container">
<h1 class="location">{{title}}</h1>
{{#markdown}}
{{> body}}
{{/markdown}}
</article>
When running foundation build everything works as expected except for the markdown content is still markdown. I have tried to find a workaround but with no luck so I am open to a solution or workaround. Also, a quick apology in advanced, due to client restrictions I am unable to post links and have the project on a private repository.
You have to add a markdown helper using marked or another markdown library.
https://github.com/zurb/panini/blob/dev/readme.md

TinyMCE, Django and python-docx

I'm looking into using a rich text editor in my Django project. TinyMCE looks like the obvious solution, however i see that the output format is html (here). Goal is to store user input and then serve it inside a word document using python-docx( which is not html).
Do you know of any solution for this? Either a feature of tinyMCE or a html to word-format converter which keeps styles, or maybe another rich text editor similar to tinymce?
UPDATE:
This is another option which i found to be working fine. Still at the point of trying to convert HTML to Word without losing styles. A solution for this may be pywin32 as stated here but it doesn't help me that much + it's Windows only.
Update2
After quite some digging i found pandoc and pypandoc which appear to be able to translate in any of these output formats:
"asciidoc, beamer, commonmark, context, docbook, docbook4, docbook5, docx, dokuwiki, dzslides, epub, epub2, epub3, fb2, gfm, haddock, html, html4, html5, icml, jats, json, latex, man, markdown, markdown_github, markdown_mmd, markdown_phpextra, markdown_strict, mediawiki, ms, muse, native, odt, opendocument, opml, org, plain, pptx, revealjs, rst, rtf, s5, slideous, slidy, tei, texinfo, textile, zimwiki"
I haven't figured out how to integrate such an input to python-docx.
I had the same challenge. You'll want to use Python's Beautiful Soup library to iterate through the content in your HTML editor (I use Summernote, but any HTML editor should work) then parse HTML tags into a usable format for python-docx. Pandoc and Pypandoc will convert files for you (e.g. you start with a LateX file and need to convert it to Word), but will not provide the tools to need to convert to and from xml/html.
Good luck!

How to change image urls in a markdown string

I am working on a nodejs CMS where users write blog posts in Markdown locally, after uploading we process the post in an HTML file. Sometimes users will add a picture like my dog.jpg to the post by copying the image and writing:
![a picture of my dog](my dog.jpg)
I use uslug to convert all filenames so that my dog.jpg becomes my-dog.jpg. However I also need to update the link in the blogpost using uslug, because a) otherwise the link would break because we just changed the filename and b) because most markdown parsers for node will skip the above image syntax because of the whitespace (while the image does get previewed in a lot of local Markdown editors, like Mou).
Does anybody know how I can achieve this using regex?
You'll need a lot of slashes:
string.replace(/(!\[.*?\]\()(.+?)(\))/g, function(whole, a, b, c) {
return a + addDashesOrWhatever(b) + c;
});

Getting markdown and urlize template tags to play nice

I'm using markdown to format some comments in a Django app.
If I try to combine markdown and urlize, inevitably bad formatting errors happen (links get added where they don't belong or aren't recognized, and of course the errors change depending on which filter I use first).
Basically I'd like a filter that does markdown and automatically turns links into hyperlinks if not done so by markdown.
Otherwise, I suppose I'll have to roll my own filter, which I would so rather not do.
What I do is use the Markdown urlize extension.
Once installed, you can use it in a Django template like this:
{{ value|markdown:"urlize" }}
Or in Python code like this:
import markdown
md = markdown.Markdown(safe_mode=True, extensions=['urlize'])
converted_text = md.convert(text)
Here is the start of the Markdown extension docs in case you need more info.