Hmm... although I have extensive documentation on the overall function
(which I wrote quite a few years ago), I didn't document the regexp in
detail. My notes (which are obviously ancient, based on the browsers
mentioned) refer to the various ways that different browsers report
transparency, such as "transparent" -or- "rgba(0, 0, 0, 0)" -or- other
variations... let me now quote my old notes verbatim:
BUT would all CSS3 engines format the transparency string precisely that
way? I’m pretty sure they’d start with “rgba” and end with “,0) or maybe “,
0 )”, but I’m not so sure about what might come in between. It might be
safer to use a regexp something like:
var css3Transp= /^rgba.*,\s?0\s?\)$/i
or maybe combine the two possible formulations of ‘transparent’ (the
traditional form and the CSS3 form) into:
var noCol = /^transparent|rgba.*,\s?0\s?\)$/i
[Back to the present] Yes, it looks weird, and I'm not entirely sure what
I was doing, but it seems to work.
New problem: Actually I just discovered that the function _does_ have a
problem: it sometimes hangs up (at least in current browsers), but I'm not
sure that has anything to do with the regexp itself. Now it seems that as
the overall function keeps calling itself, recursing (looking for an
element ancestor that has a real background-color, i.e. maybe white but not
"transparent" or an equivalent), if it happens to go all the way back to
the Window element without finding a real color, it throws:
TypeError: Argument 1 of Window.getComputedStyle is not an object
...which I haven't tracked down/fully comprehended yet. (Arrgh!) However,
the fact that it _does_ work provided it finds some ancestor (no matter how
many recursions are needed), prior to Window, that has a definable CSS
"background-color", and correctly returns that ancestor's color... makes me
infer that the regexp itself is not the problem.
The real problem is that I didn't write the overall getStyle function from
scratch, I borrowed someone else's (that I never fully understood) and
started inserting my own polyfills into it. Such is the nightmare of the
kludge style of coding...
Anyway I feel a little guilty even inflicting this on you because this has
turned into a JS torment, not really BBEdit at all, and I think I'm getting
way off-topic here... :(
On Tue, Jan 20, 2015 at 6:52 PM, Ronald J Kimball <[email protected]> wrote:
> On Sun, Jan 18, 2015 at 06:12:21PM -0800, San wrote:
> > Thanks, I'm sure you're right. I should have seen that.
> >
> > On the broader question of whether I need to "fix" this at all... does
> the
> > fact that a function doesn't balance in BBEdit imply that the function is
> > brittle, i.e. might throw an error under some circumstances, even though
> > I'm not seeing any errors?
>
> It actually implies that the Balance Tags feature is brittle. It has to
> deal with double-quoted strings, single-quoted strings, regular
> expressions, comments, and so on, and sometimes it gets it wrong.
>
> An alternative way to resolve this is to use "\x29" instead of "\)" in the
> regular expression, as \x29 is the hexadecimal escape sequence for a right
> parenthesis:
>
> /^transparent|rgba.*,\s?0\s?\x29$/i
>
>
> By the way, I'm concerned about the structure of this regular expression.
> It matches either:
>
> 1) "transparent" at the start of the string; or
> 2) "rgba", followed by any number of characters, then ",", an optional
> whitespace character, "0", an optional whitespace character, and ")", at
> the end of the string.
>
> For example, it would match both of these strings:
>
> "transparent blah blah blah"
> "blah blah blah rgba blah blah blah, 0 )"
>
> Is that really what is intended?
>
> Ronald
>
>
--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].