Smart Definition List Creation Clip

This clip will create a definition list in html coding.

Features:

  • it will create a blank list with specified number of dt and dd tags in ratio to each other
  • it will create a dl from a highlighted list using either every other, a set ratio or custom set determination of what is a dt and what is a dd
  • it will specify an id or class for the dl for those using css

;*** Effort by Don Passenger
;*** don a-t htmlfixit d-o-t com
;*** discuss things live in chat at http://htmlfixit.com
;*** donations welcome at http://htmlfixit.com
;*** Create a Definition List (DL) in HTML file v2.0
;*** based on the ordered/unordered clip shipped w/ Notetab
;*** posted here: http://htmlfixit.com/blog/index.php?p=331
;*** this version 2.0 involves some code improvements suggested
;*** or inspired by Bob McCallister fortiter at gmail dot com

;START
; Clear variables
^!ClearVariables
^!Set %listID%=^?{Give list an ID (or leave blank)=}; %listClass%=^?{Give list a Class (or leave blank)=}
^!If "^%listID%" = "" skip
^!Set %listID%=" id='^%listID%'"
^!If "^%listClass%" = "" skip
^!Set %listClass%=" class='^%listClass%'"
^!If ^$GetSelSize$ > 0 FormatSelection

;line 22
:CreateBlank
^!Set %CountDT%=^?{How many Definition Terms (DT):?=1|2|_3|4|5|6|7|8|9}
^!Set %CountDD%=^?{How many Definition Descriptions (DD) per (DT)?=_1|2|3|4|5|6|7|8|9}
^!InsertHtml <dl^%listID%^%listClass%>^P^$StrFill(  <dt></dt>^P^$StrFill(    <dd></dd>^P;^%CountDD%)$;^%CountDT%)$</dl>^P
^!Goto End

;line 29
:FormatSelection
;Divide selection at paragraph marks to make list
^!SetListDelimiter ^p
^!SetArray %delimited_data%=^$GetSelection$

;figure out if it is just every other one?
^!Set %pattern%="^$StrUpper("^?{Is There a Set Pattern?=_Every Other|Set Ratio|NO}")$"
;^!Set %pattern%=^$StrUpper("^?{Is There a Set Pattern?=_Every Other|Set Ratio|NO]")
^!If "^%pattern%" = "NO" BuildCustom
^!If "^%pattern%" = "SET RATIO" SetRatio
;set to one for every other
^!Set %dd%="1"
^!Goto BuildRatio

:SetRatio
^!Set %dd%=^?{How many (DD) Per (DT):?=1|_2|3|4|5|6|7|8|9}
^!Goto BuildRatio

;line 49
:BuildRatio
;should I test if the ratio works?
;maybe modulus on number if items

^!Set %Count%="1"
:CreateRatioDL
^!InsertHtml <dl^%listID%^%listClass%>^P
:CreateRatioDT
^!InsertHtml ^$StrFill(" ";2)$<dt>^%delimited_data^%Count%%</dt>^P
^!Inc %Count%
^!Set %CountDD%=^%dd%

:CreateRatioDD
^!InsertHtml ^$StrFill(" ";4)$<dd>^%delimited_data^%Count%%</dd>^P
^!Dec %CountDD%
^!Inc %Count%
^!If ^%CountDD% = 0 TestDT ELSE CreateRatioDD

:TestDT
^!If ^%Count% < ^%delimited_data0% CreateRatioDT

^!InsertHtml </dl>^P
;end of Build Ratio
^!Goto End

;line 77
:BuildCustom
^!Set %Count%="1"
:CreateCustomDL
^!InsertHtml <dl^%listID%^%listClass%>^P
:CreateCustomSwitch
^!Set %ThisItem%=^?{Is ^%delimited_data^%Count%% a(DT) or (DD):?=T|_D}
^!If "^%ThisItem%" = "D" CreateCustomDD ELSE CreateCustomDT

:CreateCustomDT
^!InsertHtml ^$StrFill(" ";2)$<dt>^%delimited_data^%Count%%</dt>^P
^!Goto TestCustomDT

:CreateCustomDD
^!InsertHtml ^$StrFill(" ";4)$<dd>^%delimited_data^%Count%%</dd>^P
^!Goto TestCustomDT

:TestCustomDT
^!Inc %Count%
^!If ^%Count% > ^%delimited_data0% CreateCustomDone
^!Goto CreateCustomSwitch

;line 101
:CreateCustomDone
^!InsertHtml </dl>^P
^!Goto Done

:Done
;if done say so
^!Info Done
;========= End =========
;line 111

Leave a Reply

Recent Posts

Archives

Topics