Author Topic: Doing stuff to the selected text  (Read 4543 times)


  • Junior Community Member
  • Posts: 4
  • Hero Points: 2
Doing stuff to the selected text
« on: August 17, 2007, 02:52:10 am »
If I were working in WordPerfect I'd know exactly what to do.  But I've done anything with Slick's macros except record them, and the task ahead needs a smarter approach.  So I need help.

I'm doing html markup, and need to do tasks to selected blocks of text:

- search/replace within (e.g., replace <p> with <li>).  That one's easy and can be recorded.
- insert literal text at the beginning of the selection (perhaps opening a new line first)
- insert literal text at the end of the selection (another new line, perhaps?)

For example, given this mess of selected text (hoping the best the html isn't interpreted by the forum):

<p> <strong>3.</strong>Civil Remedies for Violations of the Securities Laws</p>
<p>  pp. 390-412</p>
<p>  pp. 412-18, Problem 9-1<strong></strong></p>
<p><strong>  </strong>pp. 418-438, Problem 9-2</p>

I should produce something more like:

<h3>3. Civil Remedies for Violations of the Securities Laws</h3>
<li>pp. 390-412</li>
<li>pp. 412-18, Problem 9-1</li>
<li>pp. 418-438, Problem 9-2</li>

It's not a sexy task, but I do have a lot of it to do over the next week, so if I could improve my productivity at it, well, that would be so cool.

Help very much appreciated.


  • Senior Community Member
  • Posts: 2752
  • Hero Points: 291
Re: Doing stuff to the selected text
« Reply #1 on: August 17, 2007, 10:57:50 am »
If I get you right you always need to remove all surrounding <p> and <strong> tags.
And you need to re-surround line(s) with new tags.
That's easier than you might think b/c the real meat is already built-in !
Use the 'surround-with' command with selected lines interactively or in a macro.

Note that the spaces in the 'surround-with' list maps to underscores when using a direct maro call.
e.g. 'surround-with' -> 'unordered list with li' -> on cmdline: surround-with unordered_list_with_li' or in a user macro: surround-with ('unordered_list_with_li');

If you miss an entry there the list can be easily extended ('Customize' button using it interactively or 'alias -> html.als' on cmdline.

The regex to strip the unwanted tags can be easily found with the 'Regex Evaluator TB'.
Just as a simple commandline example (Slick regex):

This removes the <p>s (the '\om' flag activates multi-line mode. Should be omitted if only need to convert single lines. The 'M' option at the end restricts the replace to 'visible mark' aka. a selection and could be omitted if applicable.
c|\om(<p>[ \t]*){?*}(</p>)|#0|RM#$
and this all the <strong>s:
c|\om(<strong>[ \t]*){?*}(</strong>)|#0|RM#$
stripping some whitespaces.

After that you can select the appr. lines and surround-with 'em with the tags you want.

Could save at least half of the week ;)
« Last Edit: August 17, 2007, 11:02:02 am by hs2 »


  • Senior Community Member
  • Posts: 238
  • Hero Points: 24
  • User-friendly geek-speak translator extraordinaire
Re: Doing stuff to the selected text
« Reply #2 on: August 17, 2007, 03:16:18 pm »
hs2 said everything I was going to say... so I will share my experience:
I am new to using macros too. One of my jobs is to convert HTML to DocBook, so I am in a similar position. I have to strip a lot of different HTML tags that sometimes span more than one line, and replace them with various Docbook tags, which sometimes also span multiple lines (or include line breaks).

I use SlickEdit regular expressions to search and replace. The documentation is pretty good (look for "regular expressions" in the Help Index). Also the Regex Evaluator helps (Tools > Regex Evaluator). I have a lot of search/replace operations to do, so I put them all in one big macro that I run each time I open a new file to convert.

The hardest part was figuring out the correct regular expression. For example, given the following HTML:
Code: [Select]
Click <font class="
    origTag="guibutton">Save All</font> at

Using the following search/replace operations with SlickEdit regular expressions:
Code: [Select]
Search for: <font class="cguibutton"\om?*origTag="guibutton">
Replace with: <guibutton>
and then:
Search for: {\<guibutton\>?*}\</font>
Replace with: #0</guibutton>

My final code looks like:
Code: [Select]
Click <guibutton>Save All</guibutton> at
I recorded these s/r operations into macros, and instead of saving, I clicked "Edit" to just view the source, and cut/pasted them to my master "named" macro in vusrmacs.e (which you can access if you click Macro > List Macros, select your named macro and click Edit).

The macro code looks like this:
Code: [Select]
replace_buffer_text('<font class="cguibutton"\om?*origTag="guibutton">','RIP*',

Good luck!