Strip Meta Keyword/Description Tags

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

;effort by don at

;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
;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

;### %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

^!Jump Select_End
^!Goto Loop

;if meta tag, figure out if it is a description
;or a keyword metatag
^!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

;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

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

;we have either description or keywords meta
;so process it
;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 %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
^!If "^%NEEDPROCESSING%" = "2" Next ELSE Skip_1

;replace the existing tag with the words in a comment tag

^!Goto NotTag

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

Leave a Reply

Recent Posts