timdown / rangy

A cross-browser JavaScript range and selection library.
MIT License
2.23k stars 367 forks source link

Add support for CSS text-transform #445

Open mfulton26 opened 6 years ago

mfulton26 commented 6 years ago

I see that CSS text-transform is one of the "factors that are not [currently] taken into consideration" in the Text Range Module.

Can support be added for this? e.g. Using something like the following code:

function transformText(string, parentElement) {
  var computedStyle = window.getComputedStyle(parentElement);
  switch (computedStyle["text-transform"]) {
    case "capitalize":
      return string.replace(/\b\w/g, function (match) {
        return match.toUpperCase();
      });
    case "uppercase":
      return string.replace(/\w/g, function (match) {
        return match.toUpperCase();
      });
    case "lowercase":
      return string.replace(/\w/g, function (match) {
        return match.toLowerCase();
      });
    case "none":
    default:
      return string;
  }
}