Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline rmarkdown results inserted in wrong place #1353

Closed
hadley opened this issue May 22, 2022 · 9 comments · Fixed by #1391
Closed

Inline rmarkdown results inserted in wrong place #1353

hadley opened this issue May 22, 2022 · 9 comments · Fixed by #1391
Labels
bug an unexpected problem or unintended behavior rd ✍️
Milestone

Comments

@hadley
Copy link
Member

hadley commented May 22, 2022

Something is going wrong with the Rd snipped generated by the link() function:

Screen Shot 2022-05-22 at 10 05 31

And message needs to mention "v" and "!", I'd suggest something like: Elements named "*", "i", "v", and "x", "!", are formatted as regular, info, success, failure, and error bullets respectively.

lionel- referenced this issue in r-lib/rlang May 25, 2022
@lionel-
Copy link
Member

lionel- commented May 25, 2022

This looks like a roxygen2 issue. This:

#' Topic
#' @name topic2
#' @param message foo
#'   . bar `r "\\ifelse{foo}{bar}{baz}"`.
NULL

Generates

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-abort.R
\name{topic2}
\alias{topic2}
\title{Topic}
\arguments{
\item{message}{foo
. ba\ifelse{foo}{bar}{baz}"`.}
}
\description{
Topic
}

It seems the . and newlines are necessary to cause the bug.

@lionel- lionel- transferred this issue from r-lib/rlang May 25, 2022
@hadley
Copy link
Member Author

hadley commented May 28, 2022

Probably in bug in str_set_all_pos(). I have a vague recollection of hitting this bug elsewhere. Maybe in downlit?

...

Maybe r-lib/downlit@3254d19 ?

@hadley hadley added bug an unexpected problem or unintended behavior rd ✍️ labels Jun 24, 2022
@hadley hadley added this to the 7.2.1 milestone Jun 24, 2022
@hadley
Copy link
Member Author

hadley commented Jul 6, 2022

Hmmm, I can't reprex:

library(roxygen2)

roc_proc_text(rd_roclet(), r"(
#' Topic
#' @name topic2
#' @param message foo
#'   . bar `r "\\ifelse{foo}{bar}{baz}"`.
NULL
)")[[1]]
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{topic2}
#> \alias{topic2}
#> \title{Topic}
#> \arguments{
#> \item{message}{foo
#> . bar `r "\\ifelse{foo}{bar}{baz}"`.}
#> }
#> \description{
#> Topic
#> }

Created on 2022-07-06 by the reprex package (v2.0.1)

@hadley
Copy link
Member Author

hadley commented Jul 6, 2022

Ah, needed to force md on:

library(roxygen2)

roc_proc_text(rd_roclet(), r"(
#' Topic
#' @md
#' @name topic2
#' @param message foo
#'   . bar `r "\\ifelse{foo}{bar}{baz}"`.
NULL
)")[[1]]
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{topic2}
#> \alias{topic2}
#> \title{Topic}
#> \arguments{
#> \item{message}{foo
#> . ba\ifelse{foo}{bar}{baz}"`.}
#> }
#> \description{
#> Topic
#> }

Created on 2022-07-06 by the reprex package (v2.0.1)

@hadley
Copy link
Member Author

hadley commented Jul 6, 2022

Somewhat simpler reprex:

library(roxygen2)

roc_proc_text(rd_roclet(), r"(
#' Title
#'
#' line1
#'    111 `r "222"` 333
#' @md
foo <- function() {}
)")[[1]]
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{foo}
#> \alias{foo}
#> \title{Title}
#> \usage{
#> foo()
#> }
#> \description{
#> line1
#> 12222"` 333
#> }

Created on 2022-07-06 by the reprex package (v2.0.1)

It's something to do with the leading indent — if you change the number of spaces, the corruption changes.

@hadley
Copy link
Member Author

hadley commented Jul 6, 2022

Probably related to this comment in str_set_all_pos():

  # Cmark has a bug when reporting source positions for multi-line
  # code tags, and it does not count the indenting space in the
  # continuation lines. However, the bug might get fixed later, so
  # for now we just simply error for multi-line inline code.

@hadley hadley changed the title inform() documentation problems Inline rmarkdown results inserted in wrong place Jul 7, 2022
@gaborcsardi
Copy link
Member

Yeah, unfortunately this seems to be a cmark bug:

src <- "Title\n\nline1\n   111 `r \"222\"` 333\n"
cat(src)
Title

line1
   111 `r "222"` 333
cat(commonmark::markdown_xml(src, sourcepos = TRUE))
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "CommonMark.dtd">
<document sourcepos="1:1-4:20" xmlns="http://commonmark.org/xml/1.0">
  <paragraph sourcepos="1:1-1:5">
    <text sourcepos="1:1-1:5" xml:space="preserve">Title</text>
  </paragraph>
  <paragraph sourcepos="3:1-4:20">
    <text sourcepos="3:1-3:5" xml:space="preserve">line1</text>
    <softbreak />
    <text sourcepos="4:1-4:4" xml:space="preserve">111 </text>
    <code sourcepos="4:6-4:12" xml:space="preserve">r &quot;222&quot;</code>
    <text sourcepos="4:14-4:17" xml:space="preserve"> 333</text>
  </paragraph>
</document>

The sourcepos of the last line is clearly off. Let me see if a newer cmark version fixes this.

@gaborcsardi
Copy link
Member

Seems that the R package uses https://github.com/github/cmark-gfm, for the GFM extensions, I guess and there is no fix for this: https://github.com/github/cmark-gfm/releases

I'll report it upstream.

As for roxygen2, let me see if we can work around this.

@gaborcsardi
Copy link
Member

Found it in the cmark issue tracker, it does not seem like a thing that will be fixed soon: commonmark/cmark#296

hadley pushed a commit that referenced this issue Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior rd ✍️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants