Re: (repost): Very tough question, about HTML manipulation

From: Welman Jordan (wmjordanNOSPAM_at_163.com)
Date: 07/13/04


Date: Tue, 13 Jul 2004 22:59:00 +0800

Hello Julian,

Thank you very much for your valuable suggestion!
It somewhat helps....but.....

Now I am posting my WHOLE tough question. The one that
i posted before is a "simplified" one. I am gonna modify the
text with in the document very very heavily with the Regular
Expressions, as a result, character by character modification
can help little in this particular scenario.

Actually, I am dealing with some Unicode strings within
the formatted text. For example, I would like to convert
some punctuations from Western forms (",.?!") into the
form of my language (",.?!" -> "£¬¡££¿£¡(some UNICODE
PUNCTUATIONS"), only if they are behind the characters
in my language, If the ",.?!" are behind /[a-zA-Z0-9]/, they
will be left untouched.

One more thing, my mother tongue is a Far East language,
I can even not be able to use /\b/ in Regular Expressions
to detect word boundaries....

I am afraid that it is really a "Mission Impossible" now.
Nevertheless, Julian, I still, must thank you again and
express my appreciation to your kind help!

Best Regards,
W. Jordan

"Julian Turner" <Julian Turner@discussions.microsoft.com> wrote in message
 news:ADCB8363-FEF1-4FD1-861C-B2B4049D11F4@microsoft.com...
: I have some thoughts for you, but this is not a complete answer. It is
based on something I am working on myself along similar lines.
:
: I assume that all you want to do is change to upper case.
:
: Important facts:-
:
: - A TextRange can be as small as 1 character, or even nothing (i.e. a
cursor insertion point).
:
: - You can have multiple text ranges over the same text.
:
: - setting just one character on the "text" property of the range, I
believe would not affect the mark-up
:
: Suggested method
:
: 1. get the TextRange from the selection object. Let us call this the
"Cursor", which we will use to go character by character.
:
: 2. Create a duplicate of the TextRange using the duplicate() method. You
will use the duplicate to keep a "Reference" of the start and end points of
the range.
:
: 3. Collapse the Cursor range, using the collapse() method, to the start
of the Reference range. This collapses it so the start and end points are
the same.
:
: 3. Expand the Cursor by one character, using the expand() method, and get
the character, i.e. Cursor.text.
:
: 4. Is the character is an a-z character? E.g. in Regular Expression
terms: /[a-z]/gi.test(Cursor.text).
:
: 5. If so, get the character, convert it to upper case (toUpperCase()),
and save it back in Cursor.text. This is the key point, setting just one
character on the text property, I believe would not affect the mark-up.
:
: 6. Collapse the Cursor to the end of the character, using collapse.
:
: 7. Compare the end point of the Cursor to the end point of the Reference
using compareStartPoints method (I think that is what it is called) which
allows you to compare the start and end points of two ranges.
:
: 8. If the Cursor is not at the end of the Reference, go to 3.
:
: It is cumbersome, but it is granularity should help.
:
:
:
:
: "Welman Jordan" wrote:
:
: > Hello,
: >
: > I've posted this thread on IE.scripting for a month, but
: > nobody answered me, thus I reposted it here, I hope
: > somebody can help.
: >
: >
: > I have got a very darn tough question that I can not solve
: > by myself. Any JavaScript gurus please help!
: >
: > Here's the problem:
: >
: > I wanna replace some user selected text in a web page,
: > however, after the replacement, the format of the selection
: > should be preserved if possible.
: > -------------------------------------------
: > For example, here's a piece of code:
: >
: > <P><B>Bold [SELECTION_BEGIN]text</B></P>
: > <UL><LI>list item: item [SELECTION_END]things</LI></UL>
: >
: > If it is rendered on a browser, it should looks like this way:
: > a paragraph, bold text,
: > and then a bulleted list, an item.
: >
: > The selection point begins in the middle of the bold text,
: > and spans into the list item.
: > If I copy the selected text, I will get:
: > text
: > list item: item
: >
: > Now, I wanna do something with the script, replace the
: > selected text from "text", and "list item: item" to uppercase
: > "TEXT", and "LIST ITEM: ITEM". However, the "text"
: > should still be bold, and the "list item: item" should still
: > stay in the bulleted list. How to do so?
: >
: > I know that on IE5, windows.selection.createRange ()
: > might help. However, when I finish modifying the selected
: > text, I don't know how to put them back. Using pasteHTML
: > won't work, since there'll be an extra <P> before "TEXT"
: > and an extra </LI> after "ITEM". Thus the "Bold TEXT" would
: > be broken into two lines.
: >
: > Somebody can think of another way else?
: >
: > W. Jordan
: >
: >
: >
: >



Relevant Pages

  • Re: Identify page on which a bookmark is located
    ... "Collapse" produces nothing in VBA Help). ... for my GoTo Bookmark code. ... Collapses a range or selection to the starting or ending position. ... character by using the MoveEnd method after the range is collapsed, ...
    (microsoft.public.word.vba.general)
  • Re: Identify page on which a bookmark is located
    ... previous character or next character and there are none at the beginning and ... "Collapse" produces nothing in VBA Help). ... for my GoTo Bookmark code. ... Collapses a range or selection to the starting or ending position. ...
    (microsoft.public.word.vba.general)
  • Re: Identify page on which a bookmark is located
    ... "Collapse" produces nothing in VBA Help). ... for my GoTo Bookmark code. ... Collapses a range or selection to the starting or ending position. ... Returns or sets the starting character position of a selection, range, ...
    (microsoft.public.word.vba.general)
  • Re: Identify page on which a bookmark is located
    ... Here is what VBA Help says about the Collapse method: ... Collapses a range or selection to the starting or ending position. ... character by using the MoveEnd method after the range is collapsed, ... In your code, in order to use Ranges and not have to use the Goto Bookmark, ...
    (microsoft.public.word.vba.general)
  • Re: (repost): Very tough question, about HTML manipulation
    ... You need to be able to apply a regular expression to chunks of text, so I can see why my individual character method would not work. ... Again create a Cursor and Reference Range. ...
    (microsoft.public.scripting.jscript)

Loading