Jump to content
Macro Express Forums

Inserting HTML tags in a block of text


Recommended Posts

Hi

 

first of all, let me just say that this programme absolutely rocks. It is the best $60 I've ever spent and I couldn't imagine my life without so thank you very much an incredible timesaving program. I have only had it for a couple of months but already I'm finding myself creating multiple macros every day.

 

The problem I'm having is that I need to insert HTML tags into a large block of text automatically. The tags have to be set at the beginning and end of each sentence and each sentence needs to be on a separate line. I'm not good enough programmer to be able to write a macro that recognises full stops. As so if there is a quick way I can copy and paste the macro or if you are a macro template created to enable this type of action to be done easily, could you please point me in the right direction.

 

Also, do you have a guide about how to use the FTP upload macro?

 

I truly hope someone can help.

 

All the best

 

Barry

 

PS -- do you have an affiliate program? this is going straight to my list.

Link to comment
Share on other sites

Barry you raise several issues and I would encourage you in the future to create separate posts for each issue.

 

HTML: I am not certain what you are trying to do but let me take a stab at a hypothetical. Let's say you have a block of text in Notepad and you want to make each line a separate line and mark with a bold tag. I would copy it to the clipboard and manipulate the block of text in variables. I would create an output var and first write <bold> to it. Then I would find the position of the first period and then copy that number of characters to the output var. I would then append the output with </bold> and a CRLF. Then i would inclement the position counter one for the space and delete that many characters. Now just keep doing that until the position comes up zero meaning there are no more periods. I'm busy today or I would write you an example.

 

FTP: FTP commands work very well in MEP but you need to do quite abit of variable manipulation in most cases to do anything more than just dumb copies and such. I do not know of any guides, it works just like the command line FTP. If you look for some tutorials on that online I'm sure you will see how the MEP commands fit.

 

 

Copy and paste: I do not understand what you are doing.

 

Affiliate program: I don't understand. Are you looking for someone to hire or someone to hire you? Or are you talking sales promotion? If you're looking for help I am available for hire. Just send me a PM.

 

FYI I try to spend a little time here every day helping folks but I try to stop short of writing macros for them as this is what I do for a living and if I don't limit myself I could spend all day working for free. Not a good business practice when I have a huge backlog of macro work for my clients:) But if you're a paying customer I'd be happy to spend as much time as you like creating macros for you or teaching you how.

Link to comment
Share on other sites

Hi Corey...

 

Thanks for taking the time to reply. Apologise about multi posting....fair point.

 

Heres what I'm trying to achieve....formatting your block of text.

 

<p>I am not certain what you are trying to do but let me take a stab at a hypothetical. </p>

<p>Let's say you have a block of text in Notepad and you want to make each line a separate line and mark with a bold tag.</p>

<p>I would copy it to the clipboard and manipulate the block of text in variables. </p>

<p>I would create an output var and first write <bold> to it.</p>

 

Every time the sentence is a different length. It isn't all on one line when I start.

 

At present, I scroll to the end of the sentence myself and use this text macro...

 

<p/><ENTER><p>

 

I'm sure there must be a faster way that I can do it all in one go...but I cant figure out how to write it.

 

As for FTP, I think I'll give it a miss...and I found the affiliate program...sweet.

 

All the best

 

Barry

 

PS - Ive no issue paying...I can imagine you;d be here all day working for free. Depends on your rates though. Please PM me.

Link to comment
Share on other sites

Heres what I'm trying to achieve....formatting your block of text.

 

<p>I am not certain what you are trying to do but let me take a stab at a hypothetical. </p>

<p>Let's say you have a block of text in Notepad and you want to make each line a separate line and mark with a bold tag.</p>

<p>I would copy it to the clipboard and manipulate the block of text in variables. </p>

<p>I would create an output var and first write <bold> to it.</p>

 

Every time the sentence is a different length. It isn't all on one line when I start.

 

At present, I scroll to the end of the sentence myself and use this text macro...

 

<p/><ENTER><p>

 

I'm sure there must be a faster way that I can do it all in one go...but I cant figure out how to write it.

 

It is easy to semi-automate the process: you press a key -- let's use F12 -- to trigger the MX script, and it fixes one sentence. So you sit there are press F12 over and over again until the job is done.

 

If it works, you can add a repeat, say, 20 or 50 or 1000 times with each key press. But let's simplify by trying to do one fix per key press:

 

The script would look something like this: (Not tested)

 

// Initiate find

Text Type "<CONTROL>f"

Text Type "<ENTER>"

// Wait for Find dialog to appear

Delay .25

// Search for the end of a sentence: period followed by space. Press Enter to start search...

Text Type ". "

Text Type "<ENTER>"

// Dismiss dialog by pressing Esc

Text Type "<ESC>"

Delay .25

// Type over selection with the HTML...

Text Type ".</p><ENTER><p>"

Link to comment
Share on other sites

FYI I try to spend a little time here every day helping folks but I try to stop short of writing macros for them as this is what I do for a living and if I don't limit myself I could spend all day working for free. Not a good business practice when I have a huge backlog of macro work for my clients:) But if you're a paying customer I'd be happy to spend as much time as you like creating macros for you or teaching you how.

And quite frankly, you're not likely to find anybody on these boards with more expertise with Macro Express (short of the actual ISS programmers, who also frequently monitor the boards) than Cory. I'm sure he's worth the money.

 

With that said, and with absolutely no intention of discouraging a possible paying customer from doing business with Cory, let me also mention that there are a few of us here (like me), who have a fair amount of experience with Macro Express, but are by no means professionals. We enjoy the challenge of working with a new idea or need, as it also stretches our skills and gives us something to do (other than watch tv, play video games, or clean the house... my personal options right now).

 

Blah blah blah... rambling done, I'll get to the point:

 

Based on Cory's hypothetical (which is also how I interpreted your HTML situation), let's say you've got a .txt file that looks like this:

In the beginning... Call me Ishmael... It was a dark and stormy night... It was the best of times, it was the worst of times... The Wheel of Time turns... Once upon a time...

 

And you want to format it with HTML so it looks like this:

In the beginning...

Call me Ishmael...

It was a dark and stormy night...

It was the best of times, it was the worst of times...

The Wheel of Time turns...

Once upon a time...

 

I would probably write something like this:

Variable Set String set %html[1]% to the contents of C:\Users\Steven\Documents\Macros\Macro Test Files\HTML for amberman.txt
Variable Modify String: Replace "... " in %html[1]% with "...<br>" // Be sure to "Replace All Instances."  
Variable Set String %html[2]% to "<html><b>"
Variable Modify String %html[2]%: Append Text (%html[1]%</b></html>)
Variable Modify String: Save %html[2]% to "C:\Users\Steven\Documents\Macros\Macro Test Files\HTML for amberman 2.txt"

The direct editor script looks like this:

<VARIABLE SET STRING Option="\x03" Destination="%html[1]%" Filename="C:\\Users\\Steven\\Documents\\Macros\\Macro Test Files\\HTML for amberman.txt" Strip="FALSE"/>
<VARIABLE MODIFY STRING Option="\x0F" Destination="%html[1]%" ToReplace="... " ReplaceWith="...<br>" All="TRUE" IgnoreCase="FALSE" _COMMENT="Be sure to \"Replace All Instances.\"  "/>
<VARIABLE SET STRING Option="\x00" Destination="%html[2]%" Value="<html><b>"/>
<VARIABLE MODIFY STRING Option="\x06" Destination="%html[2]%" Value="%html[1]%</b></html>"/>
<VARIABLE MODIFY STRING Option="\x11" Destination="%html[2]%" Filename="C:\\Users\\Steven\\Documents\\Macros\\Macro Test Files\\HTML for amberman 2.txt" CRLF="FALSE"/>

 

This code turns this:

In the beginning... Call me Ishmael... It was a dark and stormy night... It was the best of times, it was the worst of times... The Wheel of Time turns... Once upon a time...

into this:

<html><b>In the beginning...<br>Call me Ishmael...<br>It was a dark and stormy night...<br>It was the best of times, it was the worst of times...<br>The Wheel of Time turns...<br>Once upon a time...</b></html>

 

Of course, this is extremely basic. You may want to do more than merely add <br> tabs to a .txt file, but this is at least an idea of what can be done.

Link to comment
Share on other sites

<p>I am not certain what you are trying to do but let me take a stab at a hypothetical. </p>

<p>Let's say you have a block of text in Notepad and you want to make each line a separate line and mark with a bold tag.</p>

<p>I would copy it to the clipboard and manipulate the block of text in variables. </p>

<p>I would create an output var and first write <bold> to it.</p>

 

Every time the sentence is a different length. It isn't all on one line when I start.

 

At present, I scroll to the end of the sentence myself and use this text macro...

 

<p/><ENTER><p>

 

I'm sure there must be a faster way that I can do it all in one go...but I cant figure out how to write it.

Ok... I posted my last reply late... but what you point out here is actually also very easy using the Text File Process command. Using the same example as before, only now starting in this format:

In the beginning...

Call me Ishmael...

It was a dark and stormy night...

It was the best of times, it was the worst of times...

The Wheel of Time turns... Once upon a time...

We do the following:

 

// The first thing I'd do in a case like this, is establish a CR/LF variable.  You do that with the following 3 lines of code:
Variable Set to ASCII Char 13 to %T[1]%
Variable Set to ASCII Char 10 to %T[2]%
Variable Set String %crlf% to "%T[1]%%T[2]%"
Variable Set String %html[1]% to "<p>" // This establishes the opening <p>, to which the rest of the .txt will be appended.
Text File Begin Process: C:\Users\Steven\Documents\Macros\Macro Test Files\HTML for amberman.txt
 Variable Modify String %html[1]%: Append Text (%html[2]%</p>%crlf%<p>)
Text File End Process
// Because of how this macro was built and run, there is a trailing <p> tag that is not needed.  The following 3 command lines will remove it.
Variable Set Integer %NLengthHTML% to the length of variable %html[1]%
Variable Modify Integer: %NDifference% = %NLengthHTML% - 3
Variable Modify String %html[1]%: Delete a substring starting at %NDifference% and 4 characters long
// Now variabel %html[1]% contains exactly the right information. So we save it to a .txt file.
Variable Modify String: Save %html[1]% to "C:\Users\Steven\Documents\Macros\Macro Test Files\HTML for amberman 2.txt"

Direct Editor script:

<COMMENT Value="The first thing I'd do in a case like this, is establish a CR/LF variable.  You do that with the following 3 lines of code:"/>
<VARIABLE SET TO ASCII CHAR Value="13" Destination="%T[1]%"/>
<VARIABLE SET TO ASCII CHAR Value="10" Destination="%T[2]%"/>
<VARIABLE SET STRING Option="\x00" Destination="%crlf%" Value="%T[1]%%T[2]%"/>
<VARIABLE SET STRING Option="\x00" Destination="%html[1]%" Value="<p>" _COMMENT="This establishes the opening <p>, to which the rest of the .txt will be appended."/>
<TEXT FILE BEGIN PROCESS Filename="C:\\Users\\Steven\\Documents\\Macros\\Macro Test Files\\HTML for amberman.txt" Start_Record="1" Process_All="TRUE" Records="1" Variable="%html[2]%"/>
<VARIABLE MODIFY STRING Option="\x06" Destination="%html[1]%" Value="%html[2]%</p>%crlf%<p>"/>
<TEXT FILE END PROCESS/>
<COMMENT Value="Because of how this macro was built and run, there is a trailing <p> tag that is not needed.  The following 3 command lines will remove it."/>
<VARIABLE SET INTEGER Option="\x0D" Destination="%NLengthHTML%" Text_Variable="%html[1]%"/>
<VARIABLE MODIFY INTEGER Option="\x01" Destination="%NDifference%" Value1="%NLengthHTML%" Value2="3"/>
<VARIABLE MODIFY STRING Option="\x0A" Destination="%html[1]%" Start="%NDifference%" Count="4"/>
<COMMENT Value="Now variabel %html[1]% contains exactly the right information. So we save it to a .txt file."/>
<VARIABLE MODIFY STRING Option="\x11" Destination="%html[1]%" Filename="C:\\Users\\Steven\\Documents\\Macros\\Macro Test Files\\HTML for amberman 2.txt" CRLF="FALSE"/>

 

And honestly, when using html, the CR/LF isn't even necessary, as the <p></p> tags will take care of that... though I suppose you want it to be legible in .txt format. Which is reasonable.

Link to comment
Share on other sites

Guys

 

Thanks for the great replies....SUCCESS!

 

I took Corys layout and took out the first <enter> and added a 0.25 sec delay at the end and repeated it multiple times....and its working like a charm! Here it is. Works in word and notepad perfectly. Start off where the cursor is...which is perfect.

 

<TEXT TYPE Action="0" Text="<CONTROL>f"/>

<DELAY Flags="\x01" Time="0.25"/>

<TEXT TYPE Action="0" Text=". "/>

<TEXT TYPE Action="0" Text="<ENTER>"/>

<TEXT TYPE Action="0" Text="<ESC>"/>

<DELAY Flags="\x01" Time="0.25"/>

<TEXT TYPE Action="0" Text=".</p><ENTER><p>"/>

 

 

My other macro puts in the first <p> tag as part of the initial file set up...so thats fine. All I have to do is delete the last instance if the <p> on the last line. I'm happy to do that manually, since getting into the "if" scenarios is a bit above my head.

 

I had to do this about 30 times a day and it took me 5 minutes each time...what more can I say.

 

All the best

 

Barry

Link to comment
Share on other sites

Check out these samples. Macro 1 chews threw the text in a process, Macro 2 does a simple replace routine. In this case 2 is the cleanest but I show one because in many places you need the 1 method due to technicalities.

Amberman.mex

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...