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

Decimals not supported in width and height attributes #66

Closed
hbatagelo opened this issue Sep 3, 2021 · 0 comments · Fixed by #74
Closed

Decimals not supported in width and height attributes #66

hbatagelo opened this issue Sep 3, 2021 · 0 comments · Fixed by #74

Comments

@hbatagelo
Copy link

It looks like the function get_length_value_unit doesn't work with decimals (e.g. "1.5em"). I'd suggest modifying the regex a little bit. As a suggestion:

get_length_value_unit <- function(css_length) {

  if (!grepl("^[0-9]+(\\.[0-9]+)?[a-z]+$", css_length)) {

    stop(
      "Values provided to `height` and `width` must have a value followed by a length unit",
      call. = FALSE
    )
  }

  unit <- sub("^[0-9]+(\\.[0-9]+)?", "", css_length)

  if (!(unit %in% css_length_units)) {
    stop(
      "The provided CSS length unit is not valid.",
      call. = FALSE
    )
  }

  list(
    value = as.numeric(sub("[a-z]+$", "", css_length)),
    unit = unit
  )
}

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants