-
Notifications
You must be signed in to change notification settings - Fork 232
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
Line break in Markdown link text deletes whitespace between words #628
Comments
Here's a somewhat shorter demonstration of the problem: roc_proc_text(rd_roclet(), "
#' Title
#'
#' Link text [broken
#' across lines](url) doesn't preserve whitespace.
#' @md
foo <- function() {}")[[1]] gives
|
@jennybc Here's a little patch to markdown.R, which I think resolves the issue. The problem Unpacking the (internal) function invisible(markdown_on(TRUE))
markdown("[broken\nacross lines](URL)", markdown_tags)
#> [1] "\\href{URL}{brokenacross lines}"
xml2::xml_text(xml)
#> [1] "brokenacross lines" where x <-
'<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "CommonMark.dtd">
<document xmlns="http://commonmark.org/xml/1.0">
<paragraph>
<link destination="URL" title="">
<text>broken</text>
<softbreak />
<text>across lines</text>
</link>
</paragraph>
</document>'
# Unwinding the call markdown("[broken\nacross lines](URL)", markdown_tags) ...
xml <- with(markdown_tags,
paragraph(document(xml2::read_xml(x))[[1]])[[2]]) The problem seems to be that xml2::xml_contents(xml)
#> {xml_nodeset (3)}
#> [1] <text>broken</text>
#> [2] <softbreak/>
#> [3] <text>across lines</text> whereas xml2::xml_text(xml2::xml_contents(xml))
#> [1] "broken" "" "across lines" The patch I don't see a way to get
The corrected Rd output With this modification, we get markdown("[broken\nacross lines](URL)", markdown_tags)
#> [1] "\\href{URL}{broken across lines}" The roxygen block roc_proc_text(rd_roclet(), "
#' Title
#'
#' Link text [broken
#' across lines](url) preserve whitespace.
#' @md
foo <- function() {}")[[1]] now gives % Generated by roxygen2: do not edit by hand
% Please edit documentation in RtmpIIl60i/file698e6ecd627f
\name{foo}
\alias{foo}
\title{Title}
\usage{
foo()
}
\description{
Link text \href{url}{broken across lines} preserve
whitespace.
} which matches your expectation. (I haven't yet tested whether the patch is robust. But at least it doesn't break existing tests.) |
If line wrapping causes a line break in the text of a Markdown link, the associated space between words goes missing. This does not happen with Rd syntax.
Example of the roxygen comment:
Screenshot of the help. Note "Sheets v4API" (no space, from Markdown) versus "Sheets v4 API" (with space, from Rd), despite a line break falling in exactly the same place.
The text was updated successfully, but these errors were encountered: