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

div fences are capped at 80 characters #128

Open
zkamvar opened this issue Jun 29, 2023 · 0 comments
Open

div fences are capped at 80 characters #128

zkamvar opened this issue Jun 29, 2023 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@zkamvar
Copy link
Contributor

zkamvar commented Jun 29, 2023

Problem

As reported in carpentries/workbench#62, if someone writes a closing div fence that is more than 80 characters wide, they encounter an error of a missing div tag.

I can construct a reproducible example that demonstrates this pattern with 91 closing colons:

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: instructor

test

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
tmp <- withr::local_tempfile()
open <- paste(paste(rep(":", 80), collapse = ""), "instructor")
close <- paste(rep(":", 91), collapse = "")
writeLines(c(open, "\ntest\n", close), tmp)
pegboard::Episode$new(tmp)$label_divs()
#> ✖ A section (div) tag mis-match was detected.
#> ✖ There are not enough close tags (0) for the number of open tags (2).
#> Error: Missing close section (div) tag in /tmp/RtmpBS9YrF/file8e3174daa911.
#> Here is a list of all the tags in the file:
#> /tmp/RtmpBS9YrF/file8e3174daa911:1   | tag: instructor
#> /tmp/RtmpBS9YrF/file8e3174daa911:5   | tag: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Created on 2023-06-29 with reprex v2.0.2

Explanation

The reason for this is because the regex (yes, we use regex for this 😨) caps the number of colons at 80 (important part is [:]{3,80}$):

pegboard/R/div.R

Lines 658 to 660 in 3b06f45

div_close_regex <- function() {
"(^ *?[<][/]div[>] *?\n?$|^[:]{3,80}$)"
}

Note, however that this cap is NOT present in the opening div regex (which is even more horrifying than the previous; so much so that it needs 20 lines of explanation) (important part is [:]{3,}):

trimws(sub('^(.+?class[=]["\']|[:]{3,}?\\s*?[{]?\\s*?[.]?)([-a-zA-Z0-9]+).*(["\'].+?|.*?[}]?[:]*?)$', '\\2', div))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant