summaryrefslogtreecommitdiffstats
path: root/kjsembed/docs/examples/htmlinfo/htmlinfo.js
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /kjsembed/docs/examples/htmlinfo/htmlinfo.js
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kjsembed/docs/examples/htmlinfo/htmlinfo.js')
-rwxr-xr-xkjsembed/docs/examples/htmlinfo/htmlinfo.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/kjsembed/docs/examples/htmlinfo/htmlinfo.js b/kjsembed/docs/examples/htmlinfo/htmlinfo.js
new file mode 100755
index 00000000..6b5609ca
--- /dev/null
+++ b/kjsembed/docs/examples/htmlinfo/htmlinfo.js
@@ -0,0 +1,63 @@
+#!/usr/bin/env kjscmd
+
+//
+// Script to report info about an HTML file.
+//
+
+function parse_attrs( src )
+{
+ var attrs = new Array();
+ var attr_name;
+ var attr_value;
+
+ while ( src.length > 0 ) {
+ // Attr name
+ var am = src.match( /^\s*(\w+)\s*(=?)\s*/ );
+ attr_name = am[1];
+ src = src.slice( am[0].length );
+
+ // If attr has a value
+ if ( am[2] == '=' ) {
+
+ if ( src.charAt(0) == '"' ) {
+ vm = src.match( /(\"[^\"]*\")\s*/ );
+ attr_value = vm[1];
+ src = src.slice( vm[0].length );
+ }
+ else {
+ vm = src.match( /(\S+)\s*/ );
+ attr_value = vm[1];
+ src = src.slice( vm[0].length );
+ }
+
+ }
+ else {
+ attr_value = null;
+ }
+ src.replace( /^\s*/m, '' );
+
+ attrs.push( [ attr_name, attr_value ] );
+ }
+
+ return attrs;
+}
+
+function process_tag_img( src )
+{
+ var tag = src.match( /<\s*(img)\s*([^>]*)\s*>/i );
+ var elem = tag[1];
+ var attrs = parse_attrs( tag[2] );
+
+ warn( 'Element: '+elem );
+ for ( var i=0 ; i < attrs.length; i++ ) {
+ warn( '\t '+attrs[i][0]+' = '+attrs[i][1] );
+ }
+}
+
+var file = application.args[0];
+var text = System.readFile( file );
+var imgs = text.match( /<\s*img\s*[^>]*\s*>/ig );
+
+for ( var i=0 ; i < imgs.length ; i++ ) {
+ process_tag_img( imgs[i] );
+}