Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Extracting tag attributes from source code
Hi, tag experts. I have a question.
Is there a way to programmaticaly extract tags and their valid attributes from our source code? I asked this in a different format way back in 2012 here and subsequently made a tag + attribute matrix which I updated manually. It has since been deleted and was hideously out of date, so nothing of real value has been lost.
One thing I would very much like to do as part of the docs refresh effort is to ensure our own documentation includes examples and explanations for folks wishing to make better use of Textpattern tags. One of the ways we can do this is to ensure that tags have their valid attributes listed — comprehensively so — and to ensure common attributes work across similar tags where necessary.
I need to warm up my brain to this project, and rather than manually chewing through taghandlers.php
& friends, I’m paging the forum hive mind to see if there’s a smarter, more automated way to achieve a list of Textpattern tags and their attributes in a vaguely human-friendly text list.
This also has the added benefit of being useful for more automated testing as we get closer to that. Take a look at #671 if you want to know more about that.
Last edited by gaekwad (2021-01-29 10:32:48)
Offline
Re: Extracting tag attributes from source code
Dunno if it’s fully accurate, but here we are:
{"article_custom":{"allowoverride":false,"author":"","break":"","breakby":"","breakclass":"","breakform":"","category":"","class":"","custom1":null,"custom2":null,"depth":0,"excerpted":"","expired":"0","fields":null,"form":"default","frontpage":false,"id":"","keywords":"","label":"","labeltag":"","limit":10,"match":"Category","month":"","offset":0,"pageby":null,"pgonly":0,"searchall":false,"section":"","sort":"","status":4,"time":null,"wraptag":""},"article_image":{"class":"","escape":true,"height":"","html_id":"","loading":null,"style":"","thumbnail":0,"title":"","width":"","wraptag":""},"author":{"escape":"html","format":"","link":0,"section":"","this_section":0,"title":1},"author_email":{"escape":"html","link":""},"authors":{"break":"","class":"","form":"","group":"","label":"","labeltag":"","limit":"","name":"","offset":"","sort":"name ASC","wraptag":""},"breadcrumb":{"category":"","class":"","label":"My site","limit":null,"link":1,"linkclass":"","offset":0,"section":"articles","separator":" » ","title":"","type":"article","wraptag":"p"},"category":{"class":"","link":0,"name":"","section":"articles","this_section":0,"title":0,"type":"article","url":0,"wraptag":""},"category1":{"class":"","escape":true,"link":0,"number":1,"section":"","this_section":0,"title":0,"wraptag":""},"category2":{"class":"","escape":true,"link":0,"number":1,"section":"","this_section":0,"title":0,"wraptag":""},"category_list":{"active_class":"","break":"<br \/>","categories":"","children":1,"class":"category_list","exclude":"","form":"","html_id":"","label":"","labeltag":"","limit":"","offset":"","parent":"","section":"","sort":"name ASC","this_section":0,"type":"article","wraptag":""},"comment_email_input":{"aria_label":"","class":"","placeholder":"","size":null},"comment_message_input":{"aria_label":"","class":"","cols":null,"placeholder":"","rows":null},"comment_name":{"link":1},"comment_name_input":{"aria_label":"","class":"","placeholder":"","size":null},"comment_permlink":{"anchor":true},"comment_preview":{"class":"","label":null},"comment_remember":{"class":"","forgetlabel":null,"rememberlabel":null},"comment_submit":{"class":"","label":null},"comment_time":{"format":"%b %Oe, %I:%M %p","gmt":"","lang":""},"comment_web_input":{"aria_label":"","class":"","placeholder":"","size":null},"comments":{"break":"li","class":"comments","form":"comments","limit":0,"offset":0,"sort":"posted ASC","wraptag":"ol"},"comments_error":{"break":"br","class":"comments_error","wraptag":"div"},"comments_form":{"class":"comments_form","forgetlabel":"Forget","form":"comment_form","isize":"25","msgcols":"25","msgrows":"5","msgstyle":"","previewlabel":"Preview","rememberlabel":"Remember","show_preview":true,"submitlabel":"Submit","wraptag":""},"comments_invite":{"class":"comments_invite","showalways":false,"showcount":true,"textonly":false,"wraptag":""},"css":{"format":"url","media":"screen","name":"default","rel":"stylesheet","theme":"four-point-seven","title":""},"custom_field":{"default":"","escape":null,"name":"custom1"},"email":{"email":"","linktext":"Contact","title":""},"evaluate":{"query":null,"test":true},"expires":{"format":"","gmt":"","lang":""},"feed_link":{"category":"","flavor":"rss","format":"a","label":"","limit":"","section":"articles","title":"RSS feed"},"file_download":{"filename":"","form":"files","id":""},"file_download_author":{"link":0,"section":"","this_section":"","title":1},"file_download_category":{"title":0},"file_download_created":{"format":""},"file_download_description":{"escape":null},"file_download_link":{"filename":"","id":""},"file_download_list":{"author":"","auto_detect":"category, author","break":"<br \/>","category":"","class":"file_download_list","form":"files","id":"","limit":10,"month":"","offset":0,"pageby":"","realname":"","sort":"filename asc","status":4,"time":null,"wraptag":""},"file_download_modified":{"format":""},"file_download_name":{"title":0},"file_download_size":{"decimals":2,"format":""},"header":{"break":"","name":"Content-Type","replace":1,"value":"text\/html; charset=utf-8"},"if_article_author":{"name":""},"if_article_category":{"name":"","number":""},"if_article_id":{"id":37},"if_article_list":{"type":""},"if_article_section":{"name":""},"if_author":{"name":"","type":"article"},"if_category":{"category":false,"name":false,"parent":0,"type":false},"if_custom_field":{"match":"exact","name":"custom1","separator":"","value":null},"if_description":{"type":null},"if_different":{"not":"","test":null},"if_keywords":{"keywords":""},"if_logged_in":{"group":"","name":""},"if_plugin":{"name":"","version":""},"if_request":{"match":"exact","name":"","separator":"","type":"request","value":null},"if_section":{"name":false,"section":false},"if_status":{"status":"200"},"if_variable":{"match":"exact","name":"","separator":"","value":false},"if_yield":{"else":false,"item":null,"name":"","value":null},"image":{"class":"","escape":true,"height":"","html_id":"","id":"","link":0,"link_rel":"","loading":null,"name":"","poplink":0,"style":"","thumbnail":null,"title":"","width":"","wraptag":""},"image_author":{"id":"","link":0,"name":"","section":"","this_section":"","title":1},"image_date":{"format":"","id":"","name":""},"image_index":{"break":"<br \/>","category":"","class":"image_index","limit":0,"offset":0,"sort":"name ASC","wraptag":""},"image_info":{"break":"","class":"","escape":true,"id":"","name":"","type":"caption","wraptag":""},"image_url":{"id":"","link":"auto","name":"","thumbnail":0},"images":{"author":"","auto_detect":"article, category, author","break":"<br \/>","category":"","class":"images","extension":"","form":"","html_id":"","id":"","limit":0,"name":"","offset":0,"pageby":"","realname":"","size":"","sort":"name ASC","thumbnail":"","wraptag":""},"keywords":{"break":",","class":"","wraptag":""},"link":{"escape":true,"id":"","name":"","rel":""},"link_author":{"link":0,"section":"","this_section":"","title":1},"link_category":{"title":0},"link_date":{"format":"since","gmt":"","lang":""},"link_description":{"escape":null},"link_feed_link":{"category":"","class":"link_feed_link","flavor":"rss","format":"a","label":"","title":"RSS feed","wraptag":""},"link_name":{"escape":null},"link_to_home":{"class":false},"link_to_prev":{"class":"","context":null,"id":"","style":"","title":""},"linkdesctitle":{"escape":true,"rel":""},"linklist":{"author":"","auto_detect":"category, author","break":"","category":"","class":"linklist","form":"plainlinks","id":"","limit":0,"month":"","offset":0,"pageby":"","realname":"","sort":"linksort asc","time":null,"wraptag":""},"meta_author":{"escape":null,"format":"meta","title":0},"meta_description":{"escape":null,"format":"meta","type":null},"meta_keywords":{"escape":null,"format":"meta","separator":null},"modified":{"format":"","gmt":"","lang":""},"newer":{"break":"","escape":"html","limit":0,"link":false,"rel":"","shift":false,"showalways":false,"title":""},"older":{"break":"","escape":"html","limit":0,"link":false,"rel":"","shift":false,"showalways":false,"title":""},"page_title":{"separator":" | "},"page_url":{"context":null,"default":false,"escape":null,"type":null},"pages":{"break":"","escape":"html","limit":0,"link":false,"rel":"","shift":false,"showalways":false,"title":""},"password_protect":{"login":null,"pass":null,"privs":null},"permlink":{"class":"","context":null,"id":"","style":"","title":""},"popup":{"class":"","label":"Browse","section":"","this_section":0,"type":"category","wraptag":""},"posted":{"format":"","gmt":"","lang":""},"recent_articles":{"allowoverride":false,"author":"","break":"","breakby":"","breakclass":"","breakform":"","category":"","class":"","custom1":null,"custom2":null,"depth":0,"excerpted":"","expired":"0","fields":null,"form":"default","frontpage":false,"id":"","keywords":"","label":"","labeltag":"","limit":10,"match":"Category","month":"","offset":0,"pageby":null,"pgonly":0,"searchall":false,"section":"","sort":"","status":4,"time":null,"wraptag":""},"recent_comments":{"break":"<br \/>","class":"recent_comments","form":"","limit":10,"offset":0,"sort":"posted DESC","wraptag":""},"related_articles":{"allowoverride":false,"author":"","break":"","breakby":"","breakclass":"","breakform":"","category":"","class":"","custom1":null,"custom2":null,"depth":0,"excerpted":"","expired":"0","fields":null,"form":"default","frontpage":false,"id":"","keywords":"","label":"","labeltag":"","limit":10,"match":"Category","month":"","offset":0,"pageby":null,"pgonly":0,"searchall":false,"section":"","sort":"","status":4,"time":null,"wraptag":""},"search_input":{"aria_label":"","button":"","class":"search_input","form":null,"html_id":"","label":"Search","match":"exact","placeholder":"","section":"","size":"15","wraptag":"p"},"search_result_date":{"format":"","gmt":"","lang":""},"search_result_excerpt":{"break":" …","hilight":"strong","limit":5,"separator":" …"},"search_result_title":{"class":"","context":null,"id":"","style":"","title":""},"search_result_url":{"class":"","context":null,"id":"","style":"","title":""},"section":{"class":"","link":0,"name":"","title":0,"url":0,"wraptag":""},"section_list":{"active_class":"","break":"<br \/>","class":"section_list","default_title":"My site","exclude":"","form":"","html_id":"","include_default":"","limit":"","offset":"","sections":"","sort":"","wraptag":""},"site_url":{"type":""},"text":{"escape":"html","item":""},"thumbnail":{"class":"","escape":true,"height":"","html_id":"","id":"","link":0,"link_rel":"","loading":null,"name":"","poplink":0,"style":"","thumbnail":null,"title":"","width":"","wraptag":""},"title":{"escape":null,"no_widow":""},"variable":{"add":null,"escape":null,"name":"","output":null,"reset":null,"separator":null,"value":null},"yield":{"default":false,"else":false,"item":null,"name":""}}
Offline
Offline
Re: Extracting tag attributes from source code
And inquiring minds want to know how you generated that list, Oleg. Namely, mine!
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Extracting tag attributes from source code
Bloke wrote #328397:
And inquiring minds want to know how you generated that list, Oleg. Namely, mine!
The way you suggested: loop through all registered tags, after a small modification in lAtts()
that makes it store the default attributes in a global array. The longest part was patching most context-sensitive tags (like <txp:comments_invite />
etc) that simply kill php 8 when out of their context.
I’m currently exploring try/catch
tags processing.
Offline
Re: Extracting tag attributes from source code
etc wrote #328398:
The way you suggested: loop through all registered tags, after a small modification in
lAtts()
that makes it store the default attributes in a global array.
Way cool! Awesome if you’ve got code on-the-go to commit to 4.9.0 that helps with this.
Although off the critical path and called manually through a helper class on an ad-hoc basis, it’d be super handy if we could utilise this periodically to rebuild the atts list in txp_tags.php too. So the tags we choose to expose in the tag builders will have the up-to-date attributes available after we’ve run the ‘sync atts to tag builder’ helper script (or whatever mechanism we choose to run it).
Further, this might be handy to periodically build the ‘gold master’ unit testing framework for front-end tag testing… when it’s finished. Again, running the ‘fetch lastest tag atts’ could collate the latest list of attributes and show the differences between what tests we have compared to what’s new. So we can add coverage tests to cater to newer attribute functionality and remove/tweak tests where changes or deprecation have occured.
The longest part was patching most context-sensitive tags (like
<txp:comments_invite />
etc) that simply kill php 8 when out of their context. I’m currently exploretry/catch
tags processing.
Oooooft, yeah, those tags are a pain. And I expect article(_custom) would be annoying too as that’s separately handled. Try… catch sounds like a winning combo! Looking forward to seeing this in action, thank you.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Extracting tag attributes from source code
Bloke wrote #328399:
it’d be super handy if we could utilise this periodically to rebuild the atts list in txp_tags.php too.
We could pull atts from a json file supplied with the package. The problem is dynamic default attributes, e.g. the localized ones.
Offline
Re: Extracting tag attributes from source code
For humans among us:
article
- allowoverride="1"
- break=""
- breakby=""
- breakclass=""
- breakform=""
- class=""
- custom1=null
- custom2=null
- depth="0"
- excerpted=""
- fields=null
- form="default"
- frontpage="1"
- id=""
- keywords=""
- label=""
- labeltag=""
- limit="10"
- listform=""
- match="Category"
- offset="0"
- pageby=null
- pgonly="0"
- searchall=""
- searchform=""
- searchsticky="0"
- sort=""
- status="4"
- time=null
- wraptag=""
article_custom
- allowoverride=""
- author=""
- break=""
- breakby=""
- breakclass=""
- breakform=""
- category=""
- class=""
- custom1=null
- custom2=null
- depth="0"
- excerpted=""
- expired="0"
- fields=null
- form="default"
- frontpage=""
- id=""
- keywords=""
- label=""
- labeltag=""
- limit="10"
- match="Category"
- month=""
- offset="0"
- pageby=null
- pgonly="0"
- searchall=""
- section=""
- sort=""
- status="4"
- time=null
- wraptag=""
article_image
- class=""
- escape="1"
- height=""
- html_id=""
- loading=null
- style=""
- thumbnail="0"
- title=""
- width=""
- wraptag=""
author
- escape="html"
- format=""
- link="0"
- section=""
- this_section="0"
- title="1"
author_email
- escape="html"
- link=""
authors
- break=""
- class=""
- form=""
- group=""
- label=""
- labeltag=""
- limit=""
- name=""
- offset=""
- sort="name ASC"
- wraptag=""
breadcrumb
- category=""
- class=""
- label="My site"
- limit=null
- link="1"
- linkclass=""
- offset="0"
- section="articles"
- separator=" » "
- title=""
- type="article"
- wraptag="p"
category
- class=""
- link="0"
- name=""
- section="articles"
- this_section="0"
- title="0"
- type="article"
- url="0"
- wraptag=""
category1
- class=""
- escape="1"
- link="0"
- number="1"
- section=""
- this_section="0"
- title="0"
- wraptag=""
category2
- class=""
- escape="1"
- link="0"
- number="1"
- section=""
- this_section="0"
- title="0"
- wraptag=""
category_list
- active_class=""
- break=" "
- categories=""
- children="1"
- class="category_list"
- exclude=""
- form=""
- html_id=""
- label=""
- labeltag=""
- limit=""
- offset=""
- parent=""
- section=""
- sort="name ASC"
- this_section="0"
- type="article"
- wraptag=""
comment_email_input
- aria_label=""
- class=""
- placeholder=""
- size=null
comment_message_input
- aria_label=""
- class=""
- cols=null
- placeholder=""
- rows=null
comment_name
- link="1"
comment_name_input
- aria_label=""
- class=""
- placeholder=""
- size=null
comment_permlink
- anchor="1"
comment_preview
- class=""
- label=null
comment_remember
- class=""
- forgetlabel=null
- rememberlabel=null
comment_submit
- class=""
- label=null
comment_time
- format="%b %Oe, %I:%M %p"
- gmt=""
- lang=""
comment_web_input
- aria_label=""
- class=""
- placeholder=""
- size=null
comments
- break="li"
- class="comments"
- form="comments"
- limit="0"
- offset="0"
- sort="posted ASC"
- wraptag="ol"
comments_error
- break="br"
- class="comments_error"
- wraptag="div"
comments_form
- class="comments_form"
- forgetlabel="Forget"
- form="comment_form"
- isize="25"
- msgcols="25"
- msgrows="5"
- msgstyle=""
- previewlabel="Preview"
- rememberlabel="Remember"
- show_preview="1"
- submitlabel="Submit"
- wraptag=""
comments_invite
- class="comments_invite"
- showalways=""
- showcount="1"
- textonly=""
- wraptag=""
css
- format="url"
- media="screen"
- name="default"
- rel="stylesheet"
- theme="four-point-seven"
- title=""
custom_field
- default=""
- escape=null
- name="custom1"
- email=""
- linktext="Contact"
- title=""
evaluate
- query=null
- test="1"
expires
- format=""
- gmt=""
- lang=""
feed_link
- category=""
- flavor="rss"
- format="a"
- label=""
- limit=""
- section="articles"
- title="RSS feed"
file_download
- filename=""
- form="files"
- id=""
file_download_author
- link="0"
- section=""
- this_section=""
- title="1"
file_download_category
- title="0"
file_download_created
- format=""
file_download_description
- escape=null
file_download_link
- filename=""
- id=""
file_download_list
- author=""
- auto_detect="category, author"
- break=" "
- category=""
- class="file_download_list"
- form="files"
- id=""
- limit="10"
- month=""
- offset="0"
- pageby=""
- realname=""
- sort="filename asc"
- status="4"
- time=null
- wraptag=""
file_download_modified
- format=""
file_download_name
- title="0"
file_download_size
- decimals="2"
- format=""
header
- name="Content-Type"
- replace="1"
- value="text/html; charset=utf-8"
if_article_author
- name=""
if_article_category
- name=""
- number=""
if_article_id
- id="37"
if_article_list
- type=""
if_article_section
- name=""
if_author
- name=""
- type="article"
if_category
- category=""
- name=""
- parent="0"
- type=""
if_custom_field
- match="exact"
- name="custom1"
- separator=""
- value=null
if_description
- type=null
if_different
- not=""
- test=null
if_keywords
- keywords=""
if_logged_in
- group=""
- name=""
if_plugin
- name=""
- version=""
if_request
- match="exact"
- name=""
- separator=""
- type="request"
- value=null
if_section
- name=""
- section=""
if_status
- status="200"
if_variable
- match="exact"
- name=""
- separator=""
- value=""
if_yield
- else=""
- item=null
- name=""
- value=null
image
- class=""
- escape="1"
- height=""
- html_id=""
- id=""
- link="0"
- link_rel=""
- loading=null
- name=""
- poplink="0"
- style=""
- thumbnail=null
- title=""
- width=""
- wraptag=""
image_author
- id=""
- link="0"
- name=""
- section=""
- this_section=""
- title="1"
image_date
- format=""
- id=""
- name=""
image_index
- break=" "
- category=""
- class="image_index"
- limit="0"
- offset="0"
- sort="name ASC"
- wraptag=""
image_info
- break=""
- class=""
- escape="1"
- id=""
- name=""
- type="caption"
- wraptag=""
image_url
- id=""
- link="auto"
- name=""
- thumbnail="0"
images
- author=""
- auto_detect="article, category, author"
- break=" "
- category=""
- class="images"
- extension=""
- form=""
- html_id=""
- id=""
- limit="0"
- name=""
- offset="0"
- pageby=""
- realname=""
- size=""
- sort="name ASC"
- thumbnail=""
- wraptag=""
keywords
- break=","
- class=""
- wraptag=""
link
- escape="1"
- id=""
- name=""
- rel=""
link_author
- link="0"
- section=""
- this_section=""
- title="1"
link_category
- title="0"
link_date
- format="since"
- gmt=""
- lang=""
link_description
- escape=null
link_feed_link
- category=""
- class="link_feed_link"
- flavor="rss"
- format="a"
- label=""
- title="RSS feed"
- wraptag=""
link_name
- escape=null
link_to_home
- class=""
link_to_prev
- class=""
- context=null
- id=""
- style=""
- title=""
linkdesctitle
- escape="1"
- rel=""
linklist
- author=""
- auto_detect="category, author"
- break=""
- category=""
- class="linklist"
- form="plainlinks"
- id=""
- limit="0"
- month=""
- offset="0"
- pageby=""
- realname=""
- sort="linksort asc"
- time=null
- wraptag=""
meta_author
- escape=null
- format="meta"
- title="0"
meta_description
- escape=null
- format="meta"
- type=null
meta_keywords
- escape=null
- format="meta"
- separator=null
modified
- format=""
- gmt=""
- lang=""
newer
- break=""
- escape="html"
- limit="0"
- link=""
- rel=""
- shift=""
- showalways=""
- title=""
older
- break=""
- escape="html"
- limit="0"
- link=""
- rel=""
- shift=""
- showalways=""
- title=""
page_title
- separator=" | "
page_url
- context=null
- default=""
- escape=null
- type=null
pages
- break=""
- escape="html"
- limit="0"
- link=""
- rel=""
- shift=""
- showalways=""
- title=""
password_protect
- login=null
- pass=null
- privs=null
permlink
- class=""
- context=null
- id=""
- style=""
- title=""
popup
- class=""
- label="Browse"
- section=""
- this_section="0"
- type="category"
- wraptag=""
posted
- format=""
- gmt=""
- lang=""
recent_articles
- allowoverride=""
- author=""
- break=""
- breakby=""
- breakclass=""
- breakform=""
- category=""
- class=""
- custom1=null
- custom2=null
- depth="0"
- excerpted=""
- expired="0"
- fields=null
- form="default"
- frontpage=""
- id=""
- keywords=""
- label=""
- labeltag=""
- limit="10"
- match="Category"
- month=""
- offset="0"
- pageby=null
- pgonly="0"
- searchall=""
- section=""
- sort=""
- status="4"
- time=null
- wraptag=""
recent_comments
- break=" "
- class="recent_comments"
- form=""
- limit="10"
- offset="0"
- sort="posted DESC"
- wraptag=""
related_articles
- allowoverride=""
- author=""
- break=""
- breakby=""
- breakclass=""
- breakform=""
- category=""
- class=""
- custom1=null
- custom2=null
- depth="0"
- excerpted=""
- expired="0"
- fields=null
- form="default"
- frontpage=""
- id=""
- keywords=""
- label=""
- labeltag=""
- limit="10"
- match="Category"
- month=""
- offset="0"
- pageby=null
- pgonly="0"
- searchall=""
- section=""
- sort=""
- status="4"
- time=null
- wraptag=""
search_input
- aria_label=""
- button=""
- class="search_input"
- form=null
- html_id=""
- label="Search"
- match="exact"
- placeholder=""
- section=""
- size="15"
- wraptag="p"
search_result_date
- format=""
- gmt=""
- lang=""
search_result_excerpt
- break=" …"
- hilight="strong"
- limit="5"
- separator=" …"
search_result_title
- class=""
- context=null
- id=""
- style=""
- title=""
search_result_url
- class=""
- context=null
- id=""
- style=""
- title=""
section
- class=""
- link="0"
- name=""
- title="0"
- url="0"
- wraptag=""
section_list
- active_class=""
- break=" "
- class="section_list"
- default_title="My site"
- exclude=""
- form=""
- html_id=""
- include_default=""
- limit=""
- offset=""
- sections=""
- sort=""
- wraptag=""
site_url
- type=""
text
- escape="html"
- item=""
thumbnail
- class=""
- escape="1"
- height=""
- html_id=""
- id=""
- link="0"
- link_rel=""
- loading=null
- name=""
- poplink="0"
- style=""
- thumbnail=null
- title=""
- width=""
- wraptag=""
title
- escape=null
- no_widow=""
variable
- add=null
- escape=null
- name=""
- output=null
- reset=null
- separator=null
- value=null
yield
- default=""
- else=""
- item=null
- name=""
Offline