Tapatalk

How to insert special formatted links in HTML files?

How to insert special formatted links in HTML files?

7
NewbieNewbie
7

PostFeb 28, 2025#1

Hello,

I'm trying to automate the procedure to insert links in HTML files, so they will be relative to site root (in my case d:\localsite).

For example, in a file stored in

Code: Select all

d:\localsite\folder1\subfolder1\subfoldera\file1.html
I would like to insert a link for a file

Code: Select all

d:\localsite\folder2\subfolder2\file2.html
So, in file1.html the HTML code should be:

Code: Select all

<a href="/folder2/subfolder2/file2.html">link text</a>
What I have done so far:
  1. Firstly, I've added a tag in tag list with begin tag: <a href=""> / end tag: </a>.
  2. Then I highlight some text in file1.html and insert the above link.
  3. In File explorer right click the file2.html > Insert into file > Full path, to get a link like

    Code: Select all

    <a href="d:\localsite\folder2\subfolder2\file2.html">link text</a>
  4. Manually delete the first part of the path (d:\localsite) and then replace backslashes with slashes to end up with the link I want:

    Code: Select all

    <a href="/folder2/subfolder2/file2.html">link text</a>
Is there something faster?

6,823625
Grand MasterGrand Master
6,823625

PostMar 01, 2025#2

Yes, the task can be done much faster using a small macro which is executed, for example, by pressing a hotkey assigned to the macro which is stored together with other often needed macros in a single macro file which is configured to be automatically loaded on startup of UltraEdit.

The macro code for usage with UltraEdit for Windows v2024.3.0.8 is:

Code: Select all

InsertMode
ColumnModeOff
PerlReOn
Find Up Select "D:\localsite"
Find MatchCase SelectText "\\"
Replace All "/"
Find RegExp SelectText "D:/localsite(/(?:.+/)*[0-9a-z\-._]+)"
Replace "<a href=\"\1\"></a>"
Find MatchCase RegExp Up "(?=</a>)"
The macro properties must be configured as follows:
  • [  ] Show cancel dialog for this macro
  • [  ] Continue if search string not found
  • [x] Disable screen refresh during macro playback
The macro can be named like Reformat to link. Which hotkey or chord is assigned to the macro for fast execution by key is your choice. It should not be one of the hotkeys assigned by default to a command or plugin of UltraEdit.

This macro must be executed after inserting a file/folder name beginning case insensitive with D:\localsite and the text cursor (caret) is blinking after just inserted file/folder name with full path.

The first non regular expression find searches upwards for the string D:\localsite and selects everything from current caret position to the beginning of the found string. An error message is shown and the macro execution is exited if the string D:\localsite cannot be found upwards to top of the file from current caret position like on execution of the macro by hotkey by mistake.

If the just inserted file/folder name beginning with D:\localsite is found and selected, a non regular expression replace all is executed just on the selected file/folder string for replacing all backslashes by slashes. That macro action produces the first undo record caused by the macro execution.

Then a case insensitive Perl regular expression is executed to replace D:\localsite by <a href=" and keeping the relative path and the file/folder name and inserting additionally "></a>. That replace execution produces the second undo record caused by the macro execution.

The last Perl regular expression find is for positioning the caret left to </a> where the link text can be inserted next.

The macro execution can be done also with a double click on its name in the Macro List view or using the Play Macro dialog window or with a click on the macro item on a custom ribbon tab or a customized toolbar.

Please post the used version of UltraEdit as shown in the About window (can be selected in this window and copied with Ctrl+C to the clipboard) and the used user interface mode (ribbon mode, toolbar/menu mode with contemporary menus, toolbar/menu mode with traditional menus) if you need detailed instructions on how to create this macro stored in a macro file with perhaps other macros and how to configure this macro file for being loaded automatically on startup of UltraEdit.

7
NewbieNewbie
7

PostMar 01, 2025#3

I'm in awe.
This is not an answer. It's a complete user manual!
It's already running with a click on a button in a custom group of the Coding ribbon tab.
 
Thank you so much for your time.