xml editing (and xhtml also)

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Mike Lippert

xml editing (and xhtml also)

Post by Mike Lippert »

The one thing I'd really like my xml/html/xhtml editor to do is add end tags after I type a start tag.

So when I type a '>' it checks the previous character, and if it's not a '/', then it figures out what that tag was and writes the end tag following the cursor. OK if the tag were a processing instruction it should try to write an end tag either.

So type:
<table>
get </table> appended.
type <a href="#there">
get </a> appended.
type <img src="smile.gif" />
get nothing append.
type <!-- so this will work even with IE -->
get nothing appended.
type <?php echo( 'PHP test' ); ?>
get nothing appended.
type <foobar crack="14" wide="Y">
get </foobar> appended.

I don't know if this is even possible for TextPad, I just downloaded and installed it on the recommendation of someone from usenet who had gotten tired of CodeWright which is what I have been an still am using.
Mike Lippert

Re: xml editing (and xhtml also)

Post by Mike Lippert »

oops, that isn't displaying as I meant.
that missing image was
type <img src="smile.gif" /> get nothing appended.
Mark Schnitzius

Re: xml editing (and xhtml also)

Post by Mark Schnitzius »

Look for the thread entitled "Variables in Macros? Possible?" for a 90% solution. You'll have to hit an extra key to play it back, and it won't handle the <standalonetag/> case.

I think what you want is possible -- it involves recording a macro and doing a regular-expression replace command or two, and then assigning the macro to a keystroke (under Configure|Preferences|Keyboard). The regular expression(s) are the tricky part. Will ponder.
Mike Lippert

Re: xml editing (and xhtml also)

Post by Mike Lippert »

If it requires an extra keystroke on my part then the smarts of when it writes the end tag and when it doesn't don't have to be in code, because I can make that judgement myself and hit the key or not.

I would of course prefer it to be completely automatic so I don't have to think about hitting another key to get the end tag however, it's acceptable.

I'm not bad w/ regular expressions although I don't know the TextPad variations.
to match a start tag and extract the name it would be something like
<([^ >]+)[^>]*>

ie left angle bracket
--start the tag name select which will be the
following 1 or more characters that are not either a space or right angle bracket
followed by zero or more characters that aren't a right angle bracket
followed by a right angle bracket.

However I don't know TextPad enough to know how this could be used to create the macro you're talking about. I haven't looked at the thread you mentioned yet though.

Thanks,
Mike
Mark Schnitzius

Re: xml editing (and xhtml also)

Post by Mark Schnitzius »

Textpad uses the posix standard on regular expressions, AFAIK, which is pretty widely used. And having it happen automatically isn't a problem, either; you can just assign the macro to the ">" key. The tricky part is the regular expression. There are four cases to worry about, which look essentially like these:

<tag>
<tag/>
<tag blah="blah">
<tag blah="blah"/>

You want to do something like; start defining a macro, search backwards for a "<" (extending selection), and then doing a replace (within the selection) that's something like this:

Replace: <\([^ \>]+\)\(.*\)\([^/]\)>
With: <\1\2\3></\1>

This ALMOST works, but misses on some of the cases. Unfortunately you can't do multiple replaces for the different cases, because macro execution ceases when a search fails.
Post Reply