Belicove Gets with FireFox

January 20, 2005 on 10:19 pm | In General | No Comments

My friend Mikal finally (and I mean finally) implemented a Firefox friendly css on his blog. Others should follow suit as our stat show a rapid increase in Firefox users.

Strip HTML except Images and Links

January 14, 2005 on 10:38 pm | In Special Clips - for someone | No Comments

A reader asked if it is possible to strip all html except for image and link tags, and then reformat as a “clean” html page with links and images included in the finished product. I wrote this little script that does it as a notetab clip. It simply substitutes an unusual string for the < and > signs and then resubstitutes those later after removing the html tags. The removal tool is fooled into leaving these in because they are not html tags when they aren’t opened and closed with the <> signs.

;effort by don at htmlfixit.com
;1/13/05

;clip strips html except for image and a href
;tags, reformats to html using notetab
;and then restores fully the image and a href
;tags … note will not preserve tables etc.

;go to start of document
^!Jump Doc_Start
;turn off screen to hasten the job
^!SetScreenUpdate Off

;loop to check each tag to see if it is a meta
:Loop
;set counter to 0 — unless changes will not process
;this tag
^!Set %processtag%=”0″

;find next tag start
^!Find “< " TIS
;quit when no more tags
^!IfError Clean

^!ClearVariables
;### %TAG% will be empty if cursor is not inside a tag.
;determine if tag and get the name of the tag
;if not meta cycle to next via NotTag subroutine
^!Set %TAG%="^$GetHtmlTag(TRUE)$"
^!IfTrue ^$IsEmpty(^%TAG%)$ NotTag
^!Set %TAGNAME%="^$GetHtmlTagName("^%TAG%";UPPERCASE)$"
^!Set %TAG%="^$GetSelection$"

;if tag is A, /A or IMG (no matter on case)
;then go to DOTAG where we will process it
^!If "A" = "^%TAGNAME%" DOTAG
^!If "/A" = "^%TAGNAME%" DOTAG
^!If "IMG" = "^%TAGNAME%" DOTAG

;get here and go to next tag if not a
;special tag to preserve
:NotTag
^!Jump Select_End
^!Goto Loop

;process three special tags by putting
;unusual character sequence before and
;after and then it won't be removed
:DOTAG
^!Set %TAG%=^$StrDeleteLeft("^%TAG";1)$
^!Set %TAG%=^$StrDeleteRight("^%TAG";1)$
^!Set %TAG%=**|[|**^%TAG**|]|**
^!InsertText ^%TAG%
^!Goto NotTag

:Clean
;remove html (won't remove the replaced
;things as it doesn't think they are html
^!Keyboard SHIFT+CTRL+T
;convert document to html document
^!ToolBar Document to HTML
;reinstate the < and > so they
;magically become html tags again
;for the special three A, /A, IMG
^!Replace “**|[|**" >> "< " ATIWS
^!Replace "**|]|**” >> “>” ATIWS
;turn screen back on
^!SetScreenUpdate Off
;finish at the top
^!Jump Doc_Start
;tell em we are done
^!Info [C]finished with this file
;exit the clip
^!Goto EXIT
;line 77 including all blanks and comments

Find Matching HTML Tags

January 13, 2005 on 10:00 pm | In General | 2 Comments

This works to find a matching html tag. Nesting is fine with this as it will work through it. It will highlight the start and end tags and all content in the middle. There is a find closing html tag in the Notetab Utilities Library, but it is fooled by nested tags.

;*** Effort by Don Passenger
;*** don a-t htmlfixit d-o-t com
;*** discuss things live in chat at http://htmlfixit.com
;*** based on work by Larry and Jody and maybe Wayne
;*******************************************************
;*** will check for a matching html tag

^!Continue [C]If cursor is in the tag you want to find a match for click continue

;### initialize everything
;assume we have our cursor in a tag
;look backwards to find the starting < ^!Find "<" TIBS
;exit if find fails
^!IfError EXIT
^!SetScreenUpdate Off
^!ClearVariables

;### %TAG% will be empty if cursor is not inside a tag.
^!Set %TAG%="^$GetHtmlTag(TRUE)$"
^!IfTrue ^$IsEmpty(^%TAG%)$ NotTag
;if self closing get out too
^!If "/>" = "^$StrCopyRight("^$GetSelection$";2)$" SelfClosing


;### So we found a tag.  What tag is it?
^!Set %TAGNAME%="^$GetHtmlTagName("^%TAG%";UPPERCASE)$"
;got to forwards or backwards routine depending if
;start or finish tag is selected at start of clip
^!If "/" = "^$StrCopyLeft("^%TAGNAME%";1)$" FindNextTagBackwards ELSE FindNextTagForwards

:FindNextTagForwards
^!Jump Select_Start
;figure out where cursor is
^!Set %row%="^$GetRow$"
^!Set %column%="^$GetCol$"
^!Find ">" TIS
^!Set %TAGCOUNT%=1
:TagForwardLoop
^!Find "< " TIS
^!IfError UnMatched
^!Set %TAGTEMP%="^$GetHtmlTag(TRUE)$"
^!IfTrue ^$IsEmpty(^%TAGTEMP%)$ NextTag
^!Set %TAGTEMPNAME%="^$GetHtmlTagName("^%TAGTEMP%";UPPERCASE)$"
^!If "/" = "^$StrCopyLeft("^%TAGTEMPNAME%";1)$" EndTag ELSE BeginTag

:EndTag
^!If "^$StrDeleteLeft("^%TAGTEMPNAME%";1)$" <> "^%TAGNAME%" Skip_2
^!Dec %TAGCOUNT%
^!If "^%TAGCOUNT%" = "0" Match
^!Goto NextTag

:BeginTag
^!If "^%TAGTEMPNAME%" <> "^%TAGNAME%" Skip_2
^!Inc %TAGCOUNT%
^!If "^%TAGCOUNT%" = "0" Match
^!Goto NextTag

:NextTag
^!Jump Select_End
^!Goto TagForwardLoop


:FindNextTagBackwards
^!Jump Select_End
;figure out where cursor is
^!Set %row%="^$GetRow$"
^!Set %column%="^$GetCol$"
^!Find "< " TIBS
^!Set %TAGCOUNT%=1
:TagBackwardLoop
^!Find "<" TIBS
^!IfError UnMatched
^!Set %TAGTEMP%="^$GetHtmlTag(TRUE)$"
^!IfTrue ^$IsEmpty(^%TAGTEMP%)$ NextTag2
^!Set %TAGTEMPNAME%="^$GetHtmlTagName("^%TAGTEMP%";UPPERCASE)$"
^!If "/" = "^$StrCopyLeft("^%TAGTEMPNAME%";1)$" EndTag2 ELSE BeginTag2

:EndTag2
^!If "^%TAGTEMPNAME%" <> "^%TAGNAME%" Skip_2
^!Inc %TAGCOUNT%
^!If "^%TAGCOUNT%" = "0" Match
^!Goto NextTag2

:BeginTag2
^!If "^%TAGTEMPNAME%" <> "^$StrDeleteLeft("^%TAGNAME%";1)$" Skip_2
^!Dec %TAGCOUNT%
^!If "^%TAGCOUNT%" = "0" Match
^!Goto NextTag2

:NextTag2
^!Jump Select_START
^!Goto TagBackwardLoop



:Match
^!SetScreenUpdate On
^!Info [C]Bingo, we have a match!.
^!If "/" = "^$StrCopyLeft("^%TAGNAME%";1)$" MatchBackwardJump ELSE MatchForwardJump
:MatchForwardJump
^!Jump SELECT_END
^!Goto MatchFinish
:MatchBackwardJump
^!Jump SELECT_START
:MatchFinish
^!SelectTo ^%row%:^%column%
^!Goto Finish

:UnMatched
^!SetCursor ^%row%:^%column%
^!Info [C]This appears to be an unmatched Tag.  We made it to the end of your document without finding a match.
^!Goto Finish


:NotTag
^!SetCursor ^%row%:^%column%
^!Info [C]This appears to not be an html tag.  Remember have your cursor inside the tag when starting this clip.
^!Goto Finish


:SelfClosing
^!SetCursor ^%row%:^%column%
^!Info [C]Your tag is self closing - quit messing with me!  Self closing tags end in /> like 
;### clean up and go home :Finish ^!SetScreenUpdate On ^!ClearVariables ;line 131 if you have all lines unrapped (including blank lines)

Strip Meta Keyword/Description Tags

January 13, 2005 on 9:15 pm | In Special Clips - for someone | No Comments

This clip will strip the meta tags but preserves the keywords and descriptions as html comments.

;effort by don at htmlfixit.com
;1/13/05

;clip strips html meta tags of type
;keywords and description from a document
;but leaves the keywords or description content
;in a comment with a preceeding comment saying
;what tag it came out of

;go to start of document
^!Jump Doc_Start

;loop to check each tag to see if it is a meta
:Loop
;set counter to 0 -- unless changes will not process
;this tag
^!Set %processmeta%="0"

;find next tag start
^!Find "< " TIS
;quit when no more tags
^!IfError Finish

^!ClearVariables
;### %TAG% will be empty if cursor is not inside a tag.
;determine if tag and get the name of the tag
;if not meta cycle to next via NotTag subroutine
^!Set %TAG%="^$GetHtmlTag(TRUE)$"
^!IfTrue ^$IsEmpty(^%TAG%)$ NotTag
^!Set %TAGNAME%="^$GetHtmlTagName("^%TAG%";UPPERCASE)$"
^!If "META" = "^%TAGNAME%" Meta ELSE NotTag

:NotTag
^!Jump Select_End
^!Goto Loop

;if meta tag, figure out if it is a description
;or a keyword metatag
:Meta
^!Set %METATAG%="^$GetSelection$"
;two long lines follow
^!Set %METAHTTP%="^$StrPos("HTTP-EQUIV=";"^$StrUpper("^%METATAG%")$";False)$"
^!Set %METADESCRIPTION%="^$StrPos("Description";"^$StrUpper("^%METATAG%")$";False)$"

;if description click the counter to one so we know what it is
^!If "^%METADESCRIPTION%" <> "0" next ELSE Skip_1
^!Set %NEEDPROCESSING%="1"

;if it is keyword click the counter to two so we know what it is
;long line follows
^!Set %METAKEYWORDS%="^$StrPos("Keywords";"^$StrUpper("^%METATAG%")$";False)$"
^!If "^%METAKEYWORDS%" <> "0" next ELSE Skip_1
^!Set %NEEDPROCESSING%="2"

^!If "^%NEEDPROCESSING%" = "0" Loop ELSE ProcessMeta

;we have either description or keywords meta
;so process it
:ProcessMeta
;trim out everything before and after content
;using left and right trims or copies
;long line follows
^!Set %METACONTENT%="^$StrPos("CONTENT=";"^$StrUpper("^%METATAG%")$";False)$"
^!Set %METACONTENT%=^$Calc(^%METACONTENT%+7)$
^!Set %METATAG%=^$StrDeleteLeft("^%METATAG";^%METACONTENT%)$
^!Set %QUOTE%="^$StrCopyLeft("^%METATAG";1)$"
^!Set %METATAG%=^$StrDeleteLeft("^%METATAG";1)$
^!Set %CLOSEQUOTE%="^$StrPos("^%QUOTE%";"^%METATAG%";False)$"
^!Set %METATAG%=^$StrCopyLeft("^%METATAG%";^$Calc(^%CLOSEQUOTE%-1)$)$

;insert proper comment for type of tag being cleaned
^!If "^%NEEDPROCESSING%" = "1" Next ELSE Skip_1
^!InsertHtml 
^!If "^%NEEDPROCESSING%" = "2" Next ELSE Skip_1
^!InsertHtml 

;replace the existing tag with the words in a comment tag
^!InsertHtml 

^!Goto NotTag


:Finish
^!Info [C]finished with this file
^!Goto EXIT
;line 86 including all blanks and comments

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^

Bad Behavior has blocked 382 access attempts in the last 7 days.