Giter Site home page Giter Site logo

Comments (7)

eliocamp avatar eliocamp commented on June 12, 2024 1

Here: https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#text-references it states that "The text can contain anything that Markdown supports, as long as it is one single paragraph."

In markdown (at least the flavour used by bookdown) sentences belonging to the same paragraph can be each in its own line. You need two newlines to define a new paragraph. (You can see that in the bad example, the text reference is rendered as a single paragraph).

Also, PDF output does work. This seems to be an issue for HTML (gitbook and epub) and word formats only.

image

from bookdown.

mschilli87 avatar mschilli87 commented on June 12, 2024

@eliocamp: Do you mind linking the documentation you mentioned? I always assumed this was by design. Either way, I can definitely confirm the behaviour you describe for as long as I remember using text references.

from bookdown.

eliocamp avatar eliocamp commented on June 12, 2024

The issue is around here:

bookdown/R/html.R

Lines 807 to 821 in 52c31aa

parse_ref_links = function(x, regexp) {
r = sprintf(regexp, reg_ref_links)
if (length(i <- grep(r, x)) == 0) return()
tags = gsub(r, '\\1', x[i])
txts = gsub(r, '\\2', x[i])
if (any(k <- duplicated(tags))) {
warning('Possibly duplicated text reference labels: ', paste(tags[k], collapse = ', '))
k = !k
tags = tags[k]
txts = txts[k]
i = i[k]
}
x[i] = ''
list(content = x, tags = tags, txts = txts, matches = i)
}

At this point x has one element per line instead of one element per paragraph; like this:

<p>(ref:caption) Here is a nice figure!
And this is a second sentence.</p>

So grep(r, x) doesn't find it (the line doesn't match r = "^<p>(\\(ref:[-/[:alnum:]]+\\)) (.+)</p>$"). The fix might be to join each p block in its own line, but I don't know if that could break other stuff.

Using --wrap none here actually solves the issue, but it might create others.

bookdown/R/html.R

Lines 80 to 82 in 52c31aa

pandoc_args2 = function(args) {
if (pandoc2.0() && !length(grep('--wrap', args))) c('--wrap', 'preserve', args) else args
}

from bookdown.

eliocamp avatar eliocamp commented on June 12, 2024

Ok. It seems that --warp=preserve was introduced to fix #504. But that's only related to LaTeX, which doesn't have this problem.
Removing this option only for HTML documents seems to solve the issue in HTML and all tests pass (at least locally on my machine).

That would just pass pandoc_args directly in all HTML functions instead of passing it through pandoc_args2(). For instance, in this line:

bookdown/R/html.R

Lines 59 to 62 in 52c31aa

config = get_base_format(base_format, list(
toc = toc, number_sections = number_sections, fig_caption = fig_caption,
self_contained = FALSE, lib_dir = lib_dir,
template = template, pandoc_args = pandoc_args2(pandoc_args), ...

As a workaround, one can set

  pandoc_args:
    - --wrap=none

on the output format options in the YAML.

Don't know how you feel about this. If you agree with the fix, I can sent a PR.

from bookdown.

cderv avatar cderv commented on June 12, 2024

Thanks for the investigation. I think we should have used --wrap=none for HTML output instead of --preserve.

This is part of change in HTML output with pandoc 2.17 where wrap has now effect.
I wanted to do that in #1304 but preserve was already set. You reminded us why (#504)

from bookdown.

king-of-poppk avatar king-of-poppk commented on June 12, 2024

I've got a similar issue when embedding \n's in fig.cap: the Figure x.y caption prefix is not resolved. Is this related or is it a separate issue?

from bookdown.

cderv avatar cderv commented on June 12, 2024

@king-of-poppk please open a new issue with a reproducible example and we can have a look

from bookdown.

Related Issues (20)

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.