HTML Code in Word Documents

neonlyte

Bailing Out
Joined
Apr 17, 2004
Posts
8,009
Ever had punctuate a .doc document with HTML code?

It's a pain to say the least. I wrote this applescript code to take out a lot of the effort, it works for Word running on Mac computers, I can't test it on a PC. Save the code to the applescript folder under User>Documents>Microsoft User Data>Word Script Menu Items.

To use it, highlight the text in the word.doc, and run the script from the top menu bar on word.

I'd recommend <p> and </p> (or any non-punctation mark up) first, as it gets a little difficult to read 'speech' once the mark up takes place.

Notice there are two operations, the first replaces ';' terminates, then runs the rest of the code to avoid changing all the ';' in ASCII codes into meaningless gibberish.

/.....
Fixed - don't forget to remove blank spaces in the code
tell application "Microsoft Word"
set findRange to find object of selection
tell findRange
execute find find text ";" replace with "& # 5 9 ;" replace replace all
end tell

tell findRange
execute find find text "," replace with "& # 4 4 ;" replace replace all
execute find find text "." replace with "& # 4 6 ;" replace replace all
execute find find text "'" replace with "& # 3 9 ;" replace replace all
execute find find text "‘" replace with "& # 8 2 1 6 ;" replace replace all
execute find find text "’" replace with "& # 8 2 1 7 ;" replace replace all
execute find find text "-" replace with "& # 4 5 ;" replace replace all
execute find find text "—" replace with "& # 8 2 1 2 ;" replace replace all
execute find find text "“" replace with "& # 8 2 2 0 ;" replace replace all
execute find find text "”" replace with "& # 8 2 2 1 ;" replace replace all
execute find find text "…" replace with "& # 8 2 3 0 ;" replace replace all
execute find find text "?" replace with "& # 6 3 ;" replace replace all
execute find find text "!" replace with "& # 3 3 ;" replace replace all
execute find find text ":" replace with "& # 5 8 ;" replace replace all
end tell
end tell

...../

Have fun!
 
Last edited:
Ever had punctuate a .doc document with HTML code?

It's a pain to say the least. I wrote this applescript code to take out a lot of the effort, it works for Word running on Mac computers, I can't test it on a PC. Save the code to the applescript folder under User>Documents>Microsoft User Data>Word Script Menu Items.

To use it, highlight the text in the word.doc, and run the script from the top menu bar on word.

I'd recommend <p> and </p> (or any non-punctation mark up) first, as it gets a little difficult to read 'speech' once the mark up takes place.

Notice there are two operations, the first replaces ';' terminates, then runs the rest of the code to avoid changing all the ';' in ASCII codes into meaningless gibberish.

/.....
Fixed - don't forget to remove blank spaces in the code
tell application "Microsoft Word"
set findRange to find object of selection
tell findRange
execute find find text ";" replace with "& # 5 9 ;" replace replace all
end tell

tell findRange
execute find find text "," replace with "& # 4 4 ;" replace replace all
execute find find text "." replace with "& # 4 6 ;" replace replace all
execute find find text "'" replace with "& # 3 9 ;" replace replace all
execute find find text "‘" replace with "& # 8 2 1 6 ;" replace replace all
execute find find text "’" replace with "& # 8 2 1 7 ;" replace replace all
execute find find text "-" replace with "& # 4 5 ;" replace replace all
execute find find text "—" replace with "& # 8 2 1 2 ;" replace replace all
execute find find text "“" replace with "& # 8 2 2 0 ;" replace replace all
execute find find text "”" replace with "& # 8 2 2 1 ;" replace replace all
execute find find text "…" replace with "& # 8 2 3 0 ;" replace replace all
execute find find text "?" replace with "& # 6 3 ;" replace replace all
execute find find text "!" replace with "& # 3 3 ;" replace replace all
execute find find text ":" replace with "& # 5 8 ;" replace replace all
end tell
end tell

...../

Have fun!

I've found it's just easier to add the tags for bold, italics, or whatever as I go. That way, I can just copy and paste the story/chapter into the story field and all the formatting is already there. I use the find and replace all thing quite a bit on MS Word and Word Pad, too. Doesn't it work the same way for a MAC?
 
I've found it's just easier to add the tags for bold, italics, or whatever as I go. That way, I can just copy and paste the story/chapter into the story field and all the formatting is already there. I use the find and replace all thing quite a bit on MS Word and Word Pad, too. Doesn't it work the same way for a MAC?
For Lit, that's fine and is the way I do it. If you want to post something yourself to the Internet, using HTML, you need to hand code all the punctuation. Believe me, that is a chore and a half. Even with the code above you need to add <p>, <i>, <b> etc, coding the punctuation and getting all those numbers correct is a nightmare for anything more than a couple of paragraphs, unless you do it as a PDF file, which has limitations in respect of posting clickable links within the body of the text.

The example paragraph below contains 18 punctuation codes, imagine having to do that for an entire story!

<p>& #8220;Settle down& #44; Fifi& #44;& #8221; she told the cat knowing she& #39;d be scratching his head and around his ears for a few minutes before the cat would decide to sleep on the cushion on her lap& #46; <i>& #39;For Isabella Fourgers& #39;</i> the cover proclaimed& #46; It wasn& #39;t her name four years ago when the notebook was found& #44; Fourgers had never been her name yet there was never a shadow of doubt that the notebook was intended for her& #46; With a sigh& #44; Isabella opened the notebook& #44; skipped the crude and hastily scribbled introduction that pleaded for forgiveness& #44; and began reading Larson& #39;s neat& #45;pencilled script& #46;</p>
 
For Lit, that's fine and is the way I do it. If you want to post something yourself to the Internet, using HTML, you need to hand code all the punctuation. Believe me, that is a chore and a half. Even with the code above you need to add <p>, <i>, <b> etc, coding the punctuation and getting all those numbers correct is a nightmare for anything more than a couple of paragraphs, unless you do it as a PDF file, which has limitations in respect of posting clickable links within the body of the text.

The example paragraph below contains 18 punctuation codes, imagine having to do that for an entire story!

<p>& #8220;Settle down& #44; Fifi& #44;& #8221; she told the cat knowing she& #39;d be scratching his head and around his ears for a few minutes before the cat would decide to sleep on the cushion on her lap& #46; <i>& #39;For Isabella Fourgers& #39;</i> the cover proclaimed& #46; It wasn& #39;t her name four years ago when the notebook was found& #44; Fourgers had never been her name yet there was never a shadow of doubt that the notebook was intended for her& #46; With a sigh& #44; Isabella opened the notebook& #44; skipped the crude and hastily scribbled introduction that pleaded for forgiveness& #44; and began reading Larson& #39;s neat& #45;pencilled script& #46;</p>

That does suck. I have very limited knowledge of HTML, but it gets me by. Usually, if I have to "move" a page, or update something, I'll copy the old code, paste it into a new word document, make the changes necessary then paste the whole thing back into where the code gets typed.
 
Ok... solved the next part of the problem <p> and </br> [paragraph & line breaks]

This site: http://www.textfixer.com/tools/convert-line-breaks-br.php

has a nice little routine that inserts the <p> and </br> tags. I've tested it on dialogue and it works just fine. Using my applescript routine and the tool above 95% of the work is taken out of hand coding text to HTML. I've saved days of work :)
 
Back
Top