Code Monkey home page Code Monkey logo

conflr's Introduction

⚠️ conflr is retired! ⚠️

conflr is an R package to post R Markdown documents to Confluence, a content collaboration tool by Atlassian.

While the package still can be found useful, we decided to archive the project at the beginning of July 2023.

The main reason is that conflr will be superseded by Quarto. Quarto v1.3 gained the functionality to publish documents into Confluence (the official announcement. This looks promising. At the moment, there might be some missing features compared to conflr, but it should be just a matter of time before Quarto supersedes conflr in all aspects, considering it’s one of Posit’s flagship projects.

Another reason is that conflr has a technical debt; the primary target of conflr was the on-premise version of Confluence. The on-premise version will be sunset in Feb 2024, so conflr should also switch to the cloud version. However, since the on-premise version and the cloud version have different syntax and plugins, it’s not easy to migrate. Considering we don’t have much development bandwidth for this project, we conclude it’s not really feasible to support the cloud version.

Thank you for all your support on conflr. While it’s a bit sad to announce the retirement, we are very happy to see this great evolution in the documentation ecosystem!


Installation

Install conflr from CRAN with:

install.packages("conflr")

Alternatively, if you need the development version, install it with:

# install.packages("devtools")
devtools::install_github("line/conflr")

Preparation

conflr uses these environmental variables to access your Confluence.

  • CONFLUENCE_URL: The base URL of your Confluence. e.g. https://confluence.example.com (On Atlassian Cloud, https://<your-domain>.atlassian.net/wiki).
  • CONFLUENCE_USERNAME: Your username (On Atlassian Cloud, your email address).
  • CONFLUENCE_PASSWORD: Your password (On Atlassian Cloud, your API token. For more details about API token, please read the official document).

There are several ways to set these environmental variables. The quickest way is to enter in the popups that are displayed when you run the addin (see Usages section below). The inputs are cached in the environmental variables listed above by default.

Another way is to set the variables in the .Renviron file (you can open the file with usethis::edit_r_environ()). For example, you can set the base URL in the file as the following.

CONFLUENCE_URL=https://confluence.example.com

Usages

conflr provides the following ways to post R Markdown documents to Confluence.

  1. Use an RStudio Addin
  2. Run confl_create_post_from_Rmd() on console
  3. Specify conflr::confluence_document on the YAML front-matter

RStudio Addin

1. Move focus to the .Rmd file and click “Post to Confluence” Addin

(Caution for those who are not familiar with R Markdown: R Markdown’s powerfulness allows you to execute arbitrary code; be sure about what the code does before clicking “Post to Confluence”!)

Then, you will be asked your username and password.

2. Check the preview and click “Publish”

  • type: The type of the page (page means a normal wiki page, whereas blogpost mean a blog post, not a page).
  • Space Key: The key of the space you want to post.
  • Parent page ID: (optional): The ID of the parent page to the page.
  • Use original image sizes: If checked, do not resize the images.
  • Fold code blocks: If checked, code blocks are folded by default.
  • TOC: If checked, add a Table of Contents.
  • TOC depth: The lowest heading level to include in the Table of Contents.

3. Check the result

confl_create_post_from_Rmd()

If you don’t use RStudio, you can use confl_create_post_from_Rmd(). The basic usage is

confl_create_post_from_Rmd("~/path/to/your.Rmd")

Batch use

If you want to use this function without interaction, specify interactive = FALSE. This skips any confirmations or previews.

confl_create_post_from_Rmd("~/path/to/your.Rmd", interactive = FALSE)

Note that, if you want to run this periodically, you also need to set update = TRUE to allow conflr to overwrite the existing page.

confl_create_post_from_Rmd("~/path/to/your.Rmd", interactive = FALSE, update = TRUE)

conflr::confluence_document

conflr’s functionality is also available as a custom R Markdown format; You can specify conflr::confluence_document to output in the front matter of your R Markdown document.

For example, if you set the following front matter, pressing Knit button on RStudio (or running rmarkdown::render()) will publish the R Markdown document to Confluence.

---
title: "title1"
output:
  conflr::confluence_document:
    space_key: "space1"
    update: true
---

...

For the detail about available options, please refer to ?confluence_document.

Options

conflr recognizes these options:

  • conflr_supported_syntax_highlighting: A character vector of languages that your Confluence supports the syntax highlighting in addition to the default languages (by default, sql, cpp, python, html, css, bash, and yaml are supported).
  • conflr_addin_clear_password_after_success: If TRUE, unset CONFLUENCE_PASSWORD after the page is successfully uploaded via addin.

Know limitations

LaTeX support

conflr supports Math expressions to some extent. But, it requires LaTeX Math addon installed. Otherwise, you will see “unknown macro” errors on the page.

htmlwidgets (e.g. leaflet, plotly)

conflr doesn’t support htmlwidgets-based packages like leaflet and plotly. Instead, you can embed the screenshot by setting screenshot.force = TRUE in the chunk option (c.f. https://bookdown.org/yihui/bookdown/html-widgets.html).

Advanced Usages

conflr is also a (non-complete) binding to Confluence’s REST API. These low-level functions might be useful when you need to access to your Confluence programmatically.

library(conflr)

# list pages
res <- confl_list_pages(spaceKey = "foo")
purrr::map_chr(res$results, "id")

# get page info
page <- confl_get_page(res$results[[2]]$id)
page$title

# create a page
new_page <- confl_post_page(
  spaceKey = "foo",
  title = "Test",
  body = glue::glue(
    '<ac:structured-macro ac:name="code">
     <ac:plain-text-body><![CDATA[this is my code]]></ac:plain-text-body>
     </ac:structured-macro>
    '))
new_page$`_links`

How to contribute

See CONTRIBUTING.md

License

Copyright (C) 2019 LINE Corporation

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

See LICENSE.md for more detail.

conflr's People

Contributors

daroczig avatar davidchall avatar dlependorf avatar ellisvalentiner avatar kazutan avatar yutannihilation avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

conflr's Issues

Regression: raw tags should not be escaped

This should add TOC, not a string of "<ac:structured-macro ac:name="toc" ac:schema="1"></ac:structured-macro>"

---
title: test
---

```{r echo=FALSE}
library(htmltools)
p(tag("ac:structured-macro",list("ac:name"="toc", "ac:schema"="1")))
```

### A

### B

### C

Warning: Error in parse_url: length(url) == 1 is not TRUE

Hi. I tried to post to our company Confluence page yesterday and am experiencing the error above. I'm not sure if it's an issue per se or just unique to my set up, any guidance would be much appreciated.

Duplicate post on rstudio community: https://community.rstudio.com/t/conflr-errors-when-trying-to-publish-a-rmd-page-to-confluence/61832

I have created a Rmd doc and using output: github_document I was also able to generate a readme for a Github repo.

Some folk in our company do not have access to Github and they wouldlike me to publish the Rmd documentation of a project to Confluence. I found the https://github.com/line/conflr library for doing this.

I've followed the set up guidelines and added global variables to my .Renviron, including

CONFLUENCE_URL="https://confluence.somecompany.com"
CONFLUENCE_USERNAME="doug"
CONFLUENCE_PASSWORD="[my pass]"

I then used the conflr add in to attempt to post to a page. I entered the Space of the page which is called 'Analytics' and then the parent page ID (Which I found after clicking on 'page info' in Confluence on the parent page I'd like to post to). After I click publish I get this output in the console:

No encoding supplied: defaulting to UTF-8.
Listening on http://127.0.0.1:3415
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
Warning: Error in parse_url: length(url) == 1 is not TRUE
65:

I tried Google searching for this error but did not find anything in relation to it within the context of conflr. How should I interpret this error and how can I overcome it?

I tried some other functions from the package just to see if it recognized by credentials in .Renviron (I restarted R after updating .Renviron with my credentials).

e.g. list pages in a space

confl_list_pages(spaceKey = 'Analytics')
No encoding supplied: defaulting to UTF-8.
{html_document}
<html>
[1] <head>\n<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n<title>Sign in ・ Cloudflare Access</title ...
[2] <body>\n    <div class="Surface">\n      <div class="AuthBox">\n        <div class="AuthBox-body">\n          <a class ...

I'm not sure if this means there's a successful read of my credentials or not?

How can I post my Rmd file to Confuence?

Images displayed on "large" size instead of original

First off, thanks for your work on this package, I'm very excited about it!

After trying to upload a page, I noticed that all the images were resized to "large" in confluence causing them to become unreadable/not match the preview. Is it possible to set them to display at "original" size without manually editing the page?

Thanks!

Single sign on

How can I use this package to access an installation that doesn't support user-password authentication? Is this a mode of operation you would support?

Merge addin.R and console.R

As we keep adding many features, I think it's a matter of time until they get diverged and behave inconsistently. Let's figure out the steps needed and merge these two files.

Unexpected close tag?

Getting an error when trying to publish. Not sure if related to #45 ?

Listening on http://127.0.0.1:7685
Warning: Error in confl_verb: Error in stop(httr::http_condition(res, type = "error"), httr::content(res)): Bad Request (HTTP 400).
400list(authorized = FALSE, valid = TRUE, errors = list(), successful = FALSE)com.atlassian.confluence.api.service.exceptions.BadRequestException: Error parsing xhtml: Unexpected close tag </ac:structured-macro>; expected </p>.
 at [row,col {unknown-source}]: [22,21]
  78: stop
  77: confl_verb
  76: confl_update_page
  75: observeEventHandler
   4: shiny::runApp
   3: shiny::runGadget
   2: confl_addin_upload
   1: conflr::confl_create_post_from_Rmd

Error in doc_parse_raw() when using manual <br> page breaks

I'm getting an error when trying to post a markdown file that includes manual page breaks (<br>) in it. See the reproducible example below.

library(conflr)
md_text <- c("`Test Markdown`",
             "==============",
             "",
             "This is a test file.",
             "<br>",
             "It has a break in it.")
html_text <- commonmark::markdown_html(md_text)


page <- confl_update_page(
  id = "244877109",
  title = "Test",
  body = html_text)
#> Error in doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html = as_html, : Opening and ending tag mismatch: br line 3 and p [76]

Created on 2019-03-08 by the reprex package (v0.2.1)

It looks like this error occurs in the private function translate_to_confl_macro, specifically in line 2 below:

html_doc <- xml2::read_xml(html_text, options = c("RECOVER", "NOERROR", "NOBLANKS"))

It seems like I can resolve this error by replacing xml2::read_xml with xml2::read_html, which doesn't seem to check to make sure every tag has a closing pair (which is not needed for manual breaks using <br>).

Is it possible to replace xml2::read_xml with xml2::read_html in the package source?

confluence_document

Probably we can do this by setting some post_processor.

---
title: "foo"
output:
  confluence_document:
    space_key: "my_space"
    parent_id: "123456789"
    ...
---

Error when I try to publish page on Confluence

Hello !

Everything works fine until I try to "publish" my page on confluence. The process seems to be stuck and I have only one warning which is not very helpful :

Warning: Error in : Condition message must be a string
86: <Anonymous>

I integrate "confluence_document: " on my rmarkdown, I log in to confluence directly on the command line, I have access to the preview before publishing. It's just when I click on "Publish" that the issue appears. I use the following parameters :

    parent_id: 436666369
    toc: TRUE
    toc_depth: 4
    code_folding: hide
    supported_syntax_highlighting:
      r: r
      foo: bar
    update: true 
    use_original_size: true 

Does anyone have any idea ?

Support update wiki from Rmarkdown

currently, I can not update an existing Wiki by conflr directly.

I wish to use conflr in Rscript and directly update the content with function.

it looks like this:

conflr::confl_login(username = "xxx",passwd = "xxx",url = "xxx.com")
conflr::confl_update_post_from_Rmd("test.Rmd",space = "xxx",page_id = 123456)

Hello how can I create/update a confluence page from the R console ?

Hello, I am using the nvimr plugin and not Rstudio.
I'd like to be able to create/update a confluence page from the R console.
I tried to do

R> conflr::confl_create_post_from_Rmd(here::here("fi_aware.Rmd")) 
Error: RStudio not running
In addition: Warning message:
In stop(e, call. = FALSE) : additional arguments ignored in stop()

Is there a function I can use that would be like

conflr::confl_create_post_from_Rmd(Rmd_file, spaceId, username, ...)

that would allow me to work without any rstudio ?

Images are uploaded but dont show up in page

I am using knitr::include_graphics() with .png files to include graphics in the confluence page. The images are uploaded but don't show up in the page. I am able to manually edit the page to put the images in without having to re-upload them.

convenient access to pageID and space names ?

Thanks for this great package I think it'll help me a lot.

Maybe I'm using the wrong workflow but I'm experiencing some awkwardness with space names and page ids.

As a test I opened a confluence page and decide to use it as a parent for the page I wish to create. I believe the full information is in the url, however I have to extract the space name (easy enough as it's in my url), and find the page id, which I do by finding the page nformation here :

image

Then copy paste the id from the URL, Is there a way to get the pageId and space right from the url ? Or maybe even better, could I provide in the UI the url instead of space and pageID ?

Now the other way around, I wanted to delete the page I created (or maybe I'd want to use it as a new parent), but I don't know its id, so I have to go manually on the page and do the same process.

The most convenient option for me would be to have the choice between inputing space and pageId, or just inputing an "url" parameter. In any case a get_pageId_from_url() function would help.

I'd also appreciate having the pageId logged in the console when running confl_create_post_from_Rmd_addin(), and returned invisibly by confl_create_post_from_Rmd()

Again apologies if I'm just using it wrong, and looking forward for the CRAN release.

Using conflr does not seem to work well with data.table

I looks like when I use data.table in the Rmd that I want to push on confluence I get issues with data.table. Typically the attributes of the data.table might be messed up.
I add similar issues before when writing my own packages and I had to add Depends: data.table in DESCRIPTION

Support TOC

Add this tag

<ac:structured-macro ac:name="toc" />

Wrong escaping of CDATA

Example document:

---
title: "test page"
output:
  conflr::confluence_document:
    space_key: "***"
---

<ac:structured-macro ac:name="expand">
  <ac:parameter ac:name="title">hidden stuff below</ac:parameter>
  <ac:rich-text-body><![CDATA[<p>foo</p>]]></ac:rich-text-body>
</ac:structured-macro>

Note the CDATA section for passing in HTML.

This fails with:

Error in doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html = as_html,  : 
  Opening and ending tag mismatch: confl-ac-rich-text-body line 1 and p [76]
Calls: render ... read_xml.character -> read_xml.raw -> doc_parse_raw

And renders a markdown file as:

<ac:structured-macro ac:name="expand"> <ac:parameter ac:name="title">hidden stuff below</ac:parameter> <ac:rich-text-body><![CDATA[<p>foo

</p>

\]\]\></ac:rich-text-body> </ac:structured-macro>

Note that the closing tag of the CDATA is somehow got escaped.

Not sure what's causing the problem, as conflr:::restore_cdata seems to match it and run correctly (after patching to work with rich-text-body as well besides plain-text-body), but some other mechanism might mess up the closing CDATA tag later on in the process?

Support toc_depth

maxLevel seems the corresponding parameter.

<ac:structured-macro ac:name="toc">
  <ac:parameter ac:name="maxLevel">3</ac:parameter>
</ac:structured-macro>

Cannot upload LaTex

I can not use conflr to upload LaTex.

here is my latex content:

$$ y = \frac {1 }{2}$$

result in wiki:

image

it seems that the latex macro is wrong

Add dynamic title functionality

When I tried to use a YAML param to create a dynamic title, it showed up fine when I knit it, but in the confluence page, it just showed the R code. (added quotes to syntax for formatting)

---
output: html_document
params:
  peril: 'Peril Name'
  version: 0.03
title: "`r paste0(params$peril,' - v', params$version,'a')`"
---

URL from published page no longer returned

Hello!

It looks like confl_create_post_from_Rmd() no longer returns the URL of the published page? Is there a way to get that URL still? I was sending it along with an alert that a page was published.

Thanks!

Support code folding

This is easy with expand macro.

<ac:structured-macro ac:name="expand">
  <ac:parameter ac:name="title">title1</ac:parameter>
  <ac:rich-text-body>
    <p>aaa</p>
  </ac:rich-text-body>
</ac:structured-macro>

Add Hex Sticker

conflr is great package to talk to Wiki in my daily job. Wish someone can propose a lovely hex sticker like bookdown logo.

conflr with Plotly

Plotly is a great and versatile plotting tool for R, especially in R markdown.

I think conflr does not currently support plotly graphs...

However, this would be a fantastic addition to an awesome and much needed tool!

Support tabset

This might be good to have, but this requires non-default macro. What's tougher is that the type of macro is different between the Server version and the Cloud version...

<ac:structured-macro ac:name="deck">
  <ac:parameter ac:name="id">card1</ac:parameter>
  <ac:rich-text-body>
    <ac:structured-macro ac:name="card">
      <ac:parameter ac:name="label">aaa</ac:parameter>
      <ac:rich-text-body>
        <p>aaa</p>
      </ac:rich-text-body>
    </ac:structured-macro>

    <ac:structured-macro ac:name="card">
      <ac:parameter ac:name="label">bbb</ac:parameter>
      <ac:rich-text-body>
        <p>bbb</p>
      </ac:rich-text-body>
    </ac:structured-macro>
  </ac:rich-text-body>
</ac:structured-macro>

Call to confl_create_post_from_Rmd (not interactive) returns browser error

When I call confl_create_post_from_Rmd(interactive=F) from a terminal R session, I receive the following error.

Error in browseURL(result_url) : 
  'browser' must be a non-empty character string

The function works when I call it from the command line in R studio, opening a browser with the created page. But this is a behavior I do not need or want in "Batch Use". I want to create large numbers of pages without R attempting to open a browser to them.
I troubleshooted in two ways.
First, I tried setting the environmental variable R_BROWSER=FALSE in my .Rprofile (to suppress showing URLs altogether).
Second, I commented out #readLines(paste0(output_file, "_result_url"), warn = FALSE) in the function and had it return a number. This produced another error message.
I think the issue is the render function in rmarkdown.

Can I use this function or your package to create / publish pages without R trying to open the page in a browser?

Option to turn off "Notify watchers"

Hi,

First of - 'conflr' is a real time saver for me!
Your work is appreciated!

I am facing similar issue are described here:
https://jira.atlassian.com/browse/CONFSERVER-38804

i.e. watchers are being notifed not only when I post new page but also when I add content or modify it. This seems to be resulting in sending notification each time I invoke knitr::include_graphics().
According to the link provided this ca be partially solved by using "minorEdit" : true .
Do you plan on implementing it or having any other workaround for the problem ?

Best regards,
P.

Release conflr 0.1.0

Prepare for release:

  • Check that description is informative
  • Check licensing of included files
  • usethis::use_cran_comments()
  • devtools::check()
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • Polish pkgdown reference index
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • Update cran-comments.md
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Update install instructions in README
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Add support for language option in confluence code block macro

Currently, it seems the language of an rmarkdown code chunk is lost in translation between the Rmd to md conversion, and then can't be reported to html conversion, and finally confluence post processing of html to create xml storage format.

However, it is possible to add the option to code block macro using

<ac:structured-macro ac:name="code">
  <ac:parameter ac:name="language">r</ac:parameter>
  <ac:plain-text-body><![CDATA[this is my code]]></ac:plain-text-body>
</ac:structured-macro>

https://confluence.atlassian.com/conf59/code-block-macro-792499083.html#CodeBlockMacro-Storageformatexample

I think it could be possible to add such support. I can look into it, but first what do you think ?
Did you already try something ?

Thanks.

Hide warning about missing personal space

The default value of the Shiny UI component for the Confluence space is the user's personal space. The conflr package attempts to use the username as the space key, but personal spaces often a numeric space key (see here).

It would be good to suppress the warning message like:

Warning message:
In confl_verb("GET", glue::glue("/space/{spaceKey}"), query = purrr::compact(query)) :
  Error in stop(httr::http_condition(res, type = "error"), httr::content(res)): Not Found (HTTP 404).
404list(authorized = FALSE, valid = TRUE, errors = list(), successful = FALSE)No space found with key : ~david.hall

Disables some data.table functionality

Hi,
I really like the project by the way. Thank you very much for sharing it. You had a data.table issue a while back that you couldn't recreate so I've supplied a sample that fails.

I've attached a txt file - just change the extension to .rmd. The data.table operations work under knitr but fail under conflr saying that dt is not a data.table.

TestDataTable.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.