better html tags (h-elements)
authorClaus Gittinger <cg@exept.de>
Wed, 12 Sep 2012 12:49:17 +0200
changeset 11801 18a705623785
parent 11800 afee283f9636
child 11802 79d02540b382
better html tags (h-elements)
Tools__TagList.st
--- a/Tools__TagList.st	Wed Sep 12 12:22:52 2012 +0200
+++ b/Tools__TagList.st	Wed Sep 12 12:49:17 2012 +0200
@@ -26,8 +26,8 @@
 		hidePythonClasses hidePythonMethods hidePythonFunctions
 		hideOzClasses hideOzMethods hideOzFunctions hideHTMLTextArea
 		hideHTMLInput hideHTMLTable hideHTMLScript hideHTMLForm
-		usingDefaultCTags ctagsCommand ctagsIsExCtags ctagsIsExCtags5x
-		hideDocumentation remoteTarget hideLocalLabels3'
+		hideHTMLHeaders usingDefaultCTags ctagsCommand ctagsIsExCtags
+		ctagsIsExCtags5x hideDocumentation remoteTarget hideLocalLabels3'
 	classVariableNames:'Sorted CachedTagListsPerFile DefaultSortCriteria DefaultShowOnly
 		TagsSuffixes DefaultGroupBy'
 	poolDictionaries:''
@@ -811,6 +811,18 @@
     "Modified: / 05-05-2011 / 15:22:18 / cg"
 !
 
+hideHTMLHeaders
+    ^ hideHTMLHeaders ? false
+
+    "Created: / 12-09-2012 / 12:29:45 / cg"
+!
+
+hideHTMLHeaders:aBoolean
+    hideHTMLHeaders := aBoolean.
+
+    "Created: / 12-09-2012 / 12:29:52 / cg"
+!
+
 hideHTMLInput
     ^ hideHTMLInput ? false
 
@@ -2613,6 +2625,7 @@
         <input>
         <table>
         <script>
+        <hX>
     "
 
     |targets line l lineNr s tag|
@@ -2637,8 +2650,14 @@
                 'table'         hideHTMLTable
                 'script'        hideHTMLScript  
                 'form'          hideHTMLForm  
+                'h1'            hideHTMLHeaders  
+                'h2'            hideHTMLHeaders  
+                'h3'            hideHTMLHeaders  
+                'h4'            hideHTMLHeaders  
+                'h5'            hideHTMLHeaders  
+                'h6'            hideHTMLHeaders  
             ) pairWiseDo:[:nm :hideInstVarName|
-                |type hideHolder idx tagText doc markup label|
+                |type hideHolder idx tagText doc markup label text markupName markupType|
 
                 type := hideHolder := nil.
 
@@ -2650,25 +2669,33 @@
                     tagText := line copyFrom:idx.
                     doc := HTMLParser new parseText:tagText.
                     markup := doc markup.
+                    markupName := markup name.
+                    markupType := markup type.
                     markup id notEmptyOrNil ifTrue:[
                         label := nm , ' (',markup id,')'
                     ] ifFalse:[
-                        markup name notEmptyOrNil ifTrue:[
-                            label := nm , ' (',markup name,')'
+                        markupName notEmptyOrNil ifTrue:[
+                            label := nm , ' (',markupName,')'
                         ] ifFalse:[
-                            (markup type == #input and:[ markup valueString notEmptyOrNil ]) ifTrue:[
+                            (markupType == #input and:[ markup valueString notEmptyOrNil ]) ifTrue:[
                                 label := nm , ' (',markup valueString,')'
                             ] ifFalse:[
-                                (markup type == #script and:[ markup src notEmptyOrNil ]) ifTrue:[
+                                (markupType == #script and:[ markup src notEmptyOrNil ]) ifTrue:[
                                     label := nm , ' ("',markup src,'")'
                                 ] ifFalse:[
-                                     label := nm
+                                    ( (#(h1 h2 h3 h4 h5 h6) includes:markupType) 
+                                        and:[text := self plainTextBetweenHTMLElement:markup andElementWithTag:('/',markupType).
+                                             text notEmpty 
+                                    ]) ifTrue:[
+                                        label := '"',text,'" (',nm,')'
+                                    ] ifFalse:[
+                                         label := nm
+                                    ]
                                 ]
                             ]
                         ].
                     ].
 
-
                     hideHolder value ~~ true ifTrue:[
                         tag := type 
                                     label:label 
@@ -2685,7 +2712,7 @@
     ^ targets
 
     "Created: / 20-04-2011 / 18:59:29 / cg"
-    "Modified: / 07-05-2011 / 17:04:53 / cg"
+    "Modified: / 12-09-2012 / 12:47:06 / cg"
 !
 
 javaScriptTagsInFile:aFilePath
@@ -3103,6 +3130,34 @@
     ^ targets
 !
 
+plainTextBetweenHTMLElement:startElement andElementWithTag:endTag
+    "applied to an <h1>-tag element, passing '/h1' as endTag,
+     this retrieves the plain text of the headline. Used by the tag list."
+
+    |el collector hasSpace txt|
+
+    collector := WriteStream on:(String new:100).
+    el := startElement next.
+    hasSpace := true.
+    [el tag ~= endTag] whileTrue:[
+        el isTextElement ifTrue:[
+            hasSpace ifFalse:[
+                collector space.
+                hasSpace := true.
+            ].
+            txt := el text withoutSeparators.
+            txt notEmpty ifTrue:[
+                collector nextPutAll:txt.
+                hasSpace := txt endsWith:' '.
+            ]
+        ].
+        el := el next
+    ].
+    ^ collector contents
+
+    "Created: / 12-09-2012 / 12:38:01 / cg"
+!
+
 prologTagsInFile:aFilePath
     "prolog tags:
      naive, q&d scan for lines matching:
@@ -3504,11 +3559,11 @@
 !TagList class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__TagList.st,v 1.16 2012-08-23 21:21:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__TagList.st,v 1.17 2012-09-12 10:49:17 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__TagList.st,v 1.16 2012-08-23 21:21:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__TagList.st,v 1.17 2012-09-12 10:49:17 cg Exp $'
 !
 
 version_SVN