jEdit Community - Resources for users of the jEdit Text Editor
How to parse HTML/DOM to set ID attributes
Submitted by takeshin on Thursday, 19 June, 2008 - 09:23
I want to write a macro to automatically add id attribute for all specified tags (h2, h3, h4…),
when it is not set yet. (for example #h2-1, #h2-2, #h2-3…).

I wrote a simple javascript bookmarklet to do it,
but I dont’t know how to do it in beanshell macro.
Set IDs bookmarklet

How to write getElementsByTagName(tag) function?
Maybe just regular expression with returning beanshell replacement will work?
Then how to increment those IDs in regexp?

TIA,
takeshin
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
HTMLDocument
by elberry on Mon, 23/06/2008 - 17:03
Take a look at the HTMLDocument object. If your HTML is pretty standard, you should be able to use it to get all the elements by a certain tag.

http://java.sun.com/javase/6/docs/api/javax/swing/text/html/HTMLDocument.html

Learn from the past. Live in the present. Plan for the future.
11101000
Blog
 
ok
by takeshin on Sat, 05/07/2008 - 17:56
Looks promising, thanks.

--
takeshin
User login
Browse archives
« March 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   82339
Context Free Art (*.cfdg)   0.31   46046
JBuilder scheme   .001   18487
BBEdit scheme   1.0   18108
ColdFusion scheme   1.0   18016
R Edit Mode - extensive version   0.1   17465
Advanced HTML edit mode   1.0   16198
Matlab Edit Mode   1.0   16060
jEdit XP icons   1.0   15221
XP icons for jEdit   1.1   14285