Fix Implicitly Closed Tags script needeed for XHTML

11 views
Skip to first unread message

RobS

unread,
Mar 22, 2010, 9:30:50 AM3/22/10
to BBEdit Talk
Hi,

I come to beg...

I used to use the old (came with BBE 6) Fix Implicitly Closed Tags
script alot. Doing poetry on-line, I often have to use spans to indent
lines, and poetry being poetry, there is no predictability to it, so I
need to manually paste in the span at the start of the line. To avoid
having to go over the poem again manually pasting in the /span part of
the tag set, I used to run the script. Sahzaam! Closed tags.

But, the script says right in its comments that it doesn't work with
XHTML. I can't see from reading the script why it doesn't. Certainly
the syntax warnings it requires work fine. Does anyone know how to
modify the script to work with XHTML?

Rob (running BBEdit 9.3.1)

Carlton Gibson

unread,
Mar 22, 2010, 9:47:57 AM3/22/10
to bbe...@googlegroups.com
This isn't an exact answer but, does the Tidy command help you at all? (Inserting missing tags is one thing it's good at...)

> --
> You received this message because you are subscribed to the
> "BBEdit Talk" discussion group on Google Groups.
> To post to this group, send email to bbe...@googlegroups.com
> To unsubscribe from this group, send email to
> bbedit+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/bbedit?hl=en
> If you have a feature request or would like to report a problem,
> please email "sup...@barebones.com" rather than posting to the group.
>
> To unsubscribe from this group, send email to bbedit+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

RobS

unread,
Mar 22, 2010, 10:00:00 AM3/22/10
to BBEdit Talk
Thanks for the suggestion Carlton. I had a quick look at Tidy and its
selectable options under Markup > Tidy ... but I saw nothing there
that would just close tags. I'm fussy about how my code is laid out so
I've never used Tidy except in extremis. Will it work on just the
selected text? If so, what options do I need to chose for it to only
close tags?

Perhaps a simpler approach...

Can someone suggest a grep that will select all text on one line which
follows an opening span tag (see example below) and which precedes a
closing tag which is not a span?

Example...

<p>First line<br />
another line<br />
another line<br />
another line<br />
last line.</p>

That's what I always start with. Then I add some spans manually...

<p>First line<br />
another line<br />
<span class="ind2">another line<br />
another line<br />
<span class="ind2">last line.</p>

...and I need to close the spans.

That's simpler and more limited in scope (always a good thing) than
the close tags script I used to use -- though it had its charms. ;-)

Rob

Kerri Hicks

unread,
Mar 22, 2010, 10:10:00 AM3/22/10
to bbe...@googlegroups.com
On Mon, Mar 22, 2010 at 10:00 AM, RobS <rstev...@accesscable.net> wrote:

> <p>First line<br />
> another line<br />
> another line<br />
> another line<br />
> last line.</p>
>
> That's what I always start with. Then I add some spans manually...
>
> <p>First line<br />
> another line<br />
> <span class="ind2">another line<br />
> another line<br />
> <span class="ind2">last line.</p>
>
> ...and I need to close the spans.
>
> That's simpler and more limited in scope (always a good thing) than
> the close tags script I used to use -- though it had its charms. ;-)

Where are the spans supposed to close? A computer can't guess. :-) If
it's, say, always before the next <br />, it should be pretty easy to
write a script that looks for an open span tag, then follows it to the
next line break, and inserts a close tag before it.

--Kerri

Bill

unread,
Mar 22, 2010, 12:34:52 PM3/22/10
to BBEdit Talk
I would love to have this too for various html tags but I know
logically it isn't possible to do after the text is already there.

As mentioned elsewhere the problem with <span> is there is no way for
it to be programatically closed since <span> is by default inline - it
could close after the first letter... I suppose even before the first
letter. Manually inserting the closing tag is the only logical
solution unfortunately. There is a "Close Current Tag" command under
the Markup menu which you could assign a keystroke to if you don't
want to worry about making sure you have the right thing in the
clipboard to paste. It still requires you to specify where to close
the span by clicking there but you are way smarter and intuitive than
the computer.

I suppose there would be a way to script it so that you could select
the text you want a span to surround, hit a key combo and it puts the
span around the text but I will leave that to people who like writing
scripts for BBEdit.

RobS

unread,
Mar 22, 2010, 1:58:05 PM3/22/10
to BBEdit Talk
To complete my example, and to clarify the confusion, I want the
closing span to always be just in front of the tag -- be it <br /> or
</p> -- at the end of each line. So this is the desired result...

<p>First line<br />
another line<br />

<span class="ind2">another line</span><br />
another line<br />
<span class="ind2">last line.</span></p>

I can see it would be difficult to make a general purpose script, but
remember, the old script did work fine; it just doesn't work for XHTML
docs. But as I mention in my second post above, a grep would do what I
need just as well. But my brain doesn't seem to be able to grasp grep.

So can someone tell me the grep to "select all the text after an
opening span tag and before the tag at the end of that line"? With
that in hand I can probably put it into a copy of a working script
that will iterate through the selection. I used to be able to script,
a bit.

Rob

Robert A. Rosenberg

unread,
Mar 22, 2010, 11:36:06 PM3/22/10
to bbe...@googlegroups.com
At 10:58 -0700 on 03/22/2010, RobS wrote about Re: Fix Implicitly
Closed Tags script needeed for XHTML:

>To complete my example, and to clarify the confusion, I want the
>closing span to always be just in front of the tag -- be it <br /> or
></p> -- at the end of each line. So this is the desired result...
>
><p>First line<br />
>another line<br />
><span class="ind2">another line</span><br />
>another line<br />
><span class="ind2">last line.</span></p>

While I can not come up with a grep command to do this, I feel it
might be simpler to grab everything from the <span tag to the end of
line and then output the </span> AFTER the captured data (ie: as the
start of the NEXT line). This way the end of line tag can be either a
<br /> or a </p>. You output the </span> tag followed by a another
end of line so it is a complete line.
--

Robert A. Rosenberg
RAR Programming Systems Ltd.
Home: 845-357-0931
Cell: 646-479-1984
Fax: 646-349-4025

Roland Küffner

unread,
Mar 23, 2010, 4:35:16 AM3/23/10
to bbe...@googlegroups.com

Am 22.03.2010 um 15:00 schrieb RobS:
> Can someone suggest a grep that will select all text on one line which
> follows an opening span tag (see example below) and which precedes a
> closing tag which is not a span?
>
> <p>First line<br />
> another line<br />
> <span class="ind2">another line<br />
> another line<br />
> <span class="ind2">last line.</p>
>
> ...and I need to close the spans.

To come up with a quick and dirty grep solution:

Search:
(<span.+?>.+?)(<.+>)
Replace:
\1</span>\2

this pattern might misbehave on certain circumstances:
- it assumes that the opening span tags contain arguments
- it assumes that each line has a tag at it's end

But maybe it does work for you.

Regards
Roland Küffner

Miraz Jordan

unread,
Mar 23, 2010, 2:57:29 PM3/23/10
to bbe...@googlegroups.com
On Tue, Mar 23, 2010 at 02:30, RobS <rstev...@accesscable.net> wrote:
> Doing poetry on-line, I often have to use spans to indent
> lines, and poetry being poetry, there is no predictability to it, so I
> need to manually paste in the span at the start of the line.

How about changing your workflow? Use Clippings or use Applescript to
insert both opening and closing span tags. Or use TextExpander.

1] Clippings
Make a clipping similar to this: <span
class="ind2">#insertion#</span>. Set a keystroke for the clipping to
make it even easier to use. Type the keystroke. <span
class="ind2"></span> is inserted and the cursor is placed inside the
tag, ready for your text.

2] TextExpander
Do much the same with TextExpander: set up the keystroke and text to
insert. Use the new ummm text box feature. When you type the keystroke
a dialog box appears. Enter your indented line of poetry in the text
box and press Return. The complete span tag and your line of poetry
are inserted and the cursor is placed *after* it ready for your break
tag. I use this a lot for wrapping text in <code> tags.

3] Applescript
I use Applescript all the time for adding tags to text selections when
I work with text others have sent me.

The following script (for italics) can surely be improved by the
experts on this list, but it works for me. I select the script
manually from the menu but you could assign a keystroke. You'd need to
edit it slightly for your span. remove the Say line if you don't like
chatty scripts.

-- This script adds <span></span> tags to selected text.
-- It adds style="font-style: italic;" to the span.
-- It removes and existing <i></i> tags if they are included in the selection.
-- Use this for italicising text, not for emphasis
-- for example, a book title.
-- A book title *class* would be better....

tell application "BBEdit"

tell text window 1

if selection is "" then

say "Oops, you need to select the text."
return
end if

replace "</?i>" using "" searching in selection options {search
mode:grep, starting at top:true, wrap around:false, backwards:false,
case sensitive:false, match words:false, extend selection:false}
set selection to ¬
"<span style=\"font-style: italic;\">" & selection & "</span>"

end tell

say "Here's your italic."

end tell

Cheers,

Miraz


--
Miraz Jordan

MacTip: Log In or Out automatically -
http://mactips.info/2010/03/log-in-or-out-automatically

KnowIT: Remember to check and empty your WordPress spam -
http://knowit.co.nz/2010/03/remember-to-check-and-empty-your-wordpress-spam

The Dog Lobby: http://doglobby.org

RobS

unread,
Mar 25, 2010, 7:44:08 AM3/25/10
to BBEdit Talk
On Mar 23, 5:35 am, Roland Küffner <medienmeis...@googlemail.com>
wrote:

>
> To come up with a quick and dirty grep solution:
>
> Search:
> (<span.+?>.+?)(<.+>)
> Replace:
> \1</span>\2
>
> this pattern might misbehave on certain circumstances:
> - it assumes that the opening span tags contain arguments
> - it assumes that each line has a tag at it's end

Thank you Roland. That does exactly what I need and complies with the
correct assumptions.

Rob

PS
I do also have a clipping which works on one pre-selected line at a
time, but depending on the complexity of the poem, I sometimes find it
far easier to insert the opening span by manually copying and pasting
and then close all the spans after.

The results of all this effort can be found at www.jottings.ca/john/voices/reservoir1.html

I expect poetry coding to be well served by XHTML v4.1 and CSS5, in
about 2025.

Reply all
Reply to author
Forward
0 new messages