How to move the caret from markup to markup, forward delete the markup and simulate a keystroke?
Example string on the clipboard and in the editor:
Blue¥green¥white¥purple¥black
The number of markups ¥ can vary. The number of characters between the markups will vary too.
When the macro is launched, the caret is at the beginning of the string. Firstly, the caret is moved 4 characters (positions) to the right. Secondly, a forward delete is simulated. Thirdly, a keystroke Control+Option+9 is simulated to insert a tag.
Then the cursor is moved 5 positions to the right, a forward delete is simulated, a keystroke Control+Option+9 is simulated to insert a tag etc. until all markups are ‘visited’ and converted to tags.
If I’m right, the macro would at least exist of the following steps:
Save the positions of all markups in the string (5,11,17,24 in the example).
Calculate and save the numbers of characters between the start of the string and the first markup, and between the remaining markups in the string (4,5,5,6,5 in the example).
Move the caret n positions to go to the next markup.
Forward delete and insert a tag at every n positions.
In fact, this would be a faster alternative for this macro, that repeats the steps of selecting and copying the whole string and moves the caret from the beginning of the string every time.
Alas, such a feature isn't available. (But I've requested it.)
With native CafeTran Espresso tags, such an approach would be simple to implement (these tags are simple, there's no grouping/pairing). A problem is in the numbering of the tags. This would have to be implemented with a counter/loop? (I'd appreciate a hint here )
Blauw¥groen¥wit¥paars¥zwart
Has to be transformed to:
Blauw<x1/>groen<x2/>wit<x3/>paars<x4/>zwart
Things start to get complicated with third-party tags (e.g. in SDLXLIFF files from market leader Trados Studio). Because of CafeTran Espresso's smart tag grouping and leaving out tags at the beginning and endings of segments, a segment that looks 'simple' in CafeTran Espresso, has a complicated (messy?) underlaying structure.
></x1><x2> 1 Stk</x2>. <x3>Heizfolie</x3> 2200x590x0,4 mm
(LxBxH) (1,3 m<x4>2</x4>), 36 Volt, elektr.-
Leistung 132 W/m (elek.-Leistung
220 W/m²) beidseitig Kontaktiert<x5>
</x5><x6>></x6><x7> </x7><x8>Netzteil</x8> 300 Watt mit Stecker<x9>
</x9><x10>></x10><x11> </x11>1 Stk. <x12>WIFI Touch Thermostat</x12>
und gesondertem, im Lieferum-
fang enthaltenen Schaltrelais<x13>
</x13><x14>></x14><x15> 1 Stk. 1</x15>0m <x16>Zwillingsan-
schlussleitung</x16> <x17>2 x 2,5mm²<x18>
</x18></x17><x19>></x19><x20> </x20>1 Beutel CRIMP 2,5 mm² (5 Stk.)
Here the proces of moving the caret around and simulate pressing of CTRL+OPTION+9 (to transfer the current tag - which can actually be a tag group) ensures that the correct tag(s) are transferred (inserted).
BTW: The tag mess in this SDLXLIFF file is the result of a conversion of a catalogue in InDesign format. These are actually rogue codes that in 98 % of the cases have no meaning. Problem is often to spot the one that actually starts a relevant font change etc. (like here x17).