|
|
Extending Dreamweaver with its JavaScript API Extracting and transforming HTML textBecause we have an HTML code substring now, we need to apply regular expressions to extract the text. We start by eliminating all tags, the regexp used makes things easier, as Dreamweaver will complain about incorrect source code structure. The next step is, due to HTML's syntax, very important: All entities have to be converted because the special characters Now, let's count the word boundaries, and we're almost done. This isn't as obvious as it might seem. The special character Fortunately this is also very simple as the special character for word boundaries, To find the length of a string, we can eliminate all white spaces in the last step and count the length of the resulting string. ConclusionThe complete source code of the command can be found in our library. For instructions on how to incorporate it into your Dreamweaver program, you should refer to the preceding column. As you can see, it's rather simple to take advantage of an open system like Dreamweaver because it uses a lot of standards you probably already know. You only have to learn about the basic framework and the custom APIs used. While today's lesson was fairly simple, we'll talk about the file I/O APIs next time so that you can access the files of your site. We'll also show you how to create a full-featured, tree-view menu object with just a few lines of code. Stay tuned! Claus Augusti is O'Reilly Network's JavaScript editor. Read more Essential JavaScript columns. Return to the JavaScript and CSS DevCenter. |
|
|
|
|
||||||||