use data files for tag info

This commit is contained in:
Chris Wanstrath 2025-11-05 15:50:08 -08:00
parent 6114e5cf5e
commit 260e2c7480
4 changed files with 562 additions and 17 deletions

155
data/attrs.json Normal file
View File

@ -0,0 +1,155 @@
[
"accesskey",
"autocapitalize",
"autofocus",
"class",
"contenteditable",
"dir",
"draggable",
"enterkeyhint",
"hidden",
"id",
"inert",
"inputmode",
"is",
"itemid",
"itemprop",
"itemref",
"itemscope",
"itemtype",
"lang",
"nonce",
"part",
"popover",
"slot",
"spellcheck",
"style",
"tabindex",
"title",
"translate",
"data-*",
"aria-activedescendant",
"aria-atomic",
"aria-autocomplete",
"aria-busy",
"aria-checked",
"aria-colcount",
"aria-colindex",
"aria-colspan",
"aria-controls",
"aria-current",
"aria-describedby",
"aria-details",
"aria-disabled",
"aria-errormessage",
"aria-expanded",
"aria-flowto",
"aria-haspopup",
"aria-hidden",
"aria-invalid",
"aria-keyshortcuts",
"aria-label",
"aria-labelledby",
"aria-level",
"aria-live",
"aria-modal",
"aria-multiline",
"aria-multiselectable",
"aria-orientation",
"aria-owns",
"aria-placeholder",
"aria-posinset",
"aria-pressed",
"aria-readonly",
"aria-relevant",
"aria-required",
"aria-roledescription",
"aria-rowcount",
"aria-rowindex",
"aria-rowspan",
"aria-selected",
"aria-setsize",
"aria-sort",
"aria-valuemax",
"aria-valuemin",
"aria-valuenow",
"aria-valuetext",
"onabort",
"onauxclick",
"onbeforeinput",
"onbeforematch",
"onbeforetoggle",
"onblur",
"oncancel",
"oncanplay",
"oncanplaythrough",
"onchange",
"onclick",
"onclose",
"oncontextlost",
"oncontextmenu",
"oncontextrestored",
"oncopy",
"oncuechange",
"oncut",
"ondblclick",
"ondrag",
"ondragend",
"ondragenter",
"ondragleave",
"ondragover",
"ondragstart",
"ondrop",
"ondurationchange",
"onemptied",
"onended",
"onerror",
"onfocus",
"onformdata",
"oninput",
"oninvalid",
"onkeydown",
"onkeypress",
"onkeyup",
"onload",
"onloadeddata",
"onloadedmetadata",
"onloadstart",
"onmousedown",
"onmouseenter",
"onmouseleave",
"onmousemove",
"onmouseout",
"onmouseover",
"onmouseup",
"onmousewheel",
"onpaste",
"onpause",
"onplay",
"onplaying",
"onprogress",
"onratechange",
"onreset",
"onresize",
"onscroll",
"onscrollend",
"onsecuritypolicyviolation",
"onseeked",
"onseeking",
"onselect",
"onselectionchange",
"onselectstart",
"onslotchange",
"onstalled",
"onsubmit",
"onsuspend",
"ontimeupdate",
"ontoggle",
"onvolumechange",
"onwaiting",
"onwebkitanimationend",
"onwebkitanimationiteration",
"onwebkitanimationstart",
"onwebkittransitionend",
"onwheel"
]

16
data/self-closing.json Normal file
View File

@ -0,0 +1,16 @@
[
"area",
"base",
"br",
"col",
"embed",
"hr",
"img",
"input",
"link",
"meta",
"param",
"source",
"track",
"wbr"
]

387
data/tags.json Normal file
View File

@ -0,0 +1,387 @@
{
"a": [
"href",
"target",
"download",
"rel",
"hreflang",
"referrerpolicy",
"ping"
],
"abbr": [],
"address": [],
"area": [
"alt",
"coords",
"shape",
"href",
"target",
"download",
"rel",
"referrerpolicy",
"ping"
],
"article": [],
"aside": [],
"audio": [
"src",
"crossorigin",
"preload",
"autoplay",
"loop",
"muted",
"controls"
],
"b": [],
"base": [
"href",
"target"
],
"bdi": [],
"bdo": [],
"blockquote": [
"cite"
],
"body": [],
"br": [],
"button": [
"disabled",
"form",
"formaction",
"formenctype",
"formmethod",
"formnovalidate",
"formtarget",
"name",
"type",
"value"
],
"canvas": [
"width",
"height"
],
"caption": [],
"cite": [],
"code": [],
"col": [
"span"
],
"colgroup": [
"span"
],
"data": [
"value"
],
"datalist": [],
"dd": [],
"del": [
"cite",
"datetime"
],
"details": [
"open"
],
"dfn": [],
"dialog": [
"open"
],
"div": [],
"dl": [],
"dt": [],
"em": [],
"embed": [
"src",
"type",
"width",
"height"
],
"fieldset": [
"disabled",
"form",
"name"
],
"figcaption": [],
"figure": [],
"footer": [],
"form": [
"accept-charset",
"action",
"autocomplete",
"enctype",
"method",
"name",
"novalidate",
"target"
],
"h1": [],
"h2": [],
"h3": [],
"h4": [],
"h5": [],
"h6": [],
"head": [],
"header": [],
"hr": [],
"html": [],
"i": [],
"iframe": [
"src",
"srcdoc",
"name",
"width",
"height",
"allow",
"loading",
"referrerpolicy",
"sandbox",
"csp"
],
"img": [
"alt",
"src",
"srcset",
"sizes",
"crossorigin",
"usemap",
"ismap",
"width",
"height",
"referrerpolicy",
"decoding",
"loading",
"fetchpriority"
],
"input": [
"accept",
"alt",
"autocomplete",
"checked",
"dirname",
"disabled",
"form",
"formaction",
"formenctype",
"formmethod",
"formnovalidate",
"formtarget",
"height",
"list",
"max",
"maxlength",
"min",
"minlength",
"multiple",
"name",
"pattern",
"placeholder",
"readonly",
"required",
"size",
"src",
"step",
"type",
"value",
"width"
],
"ins": [
"cite",
"datetime"
],
"kbd": [],
"label": [
"for",
"form"
],
"legend": [],
"li": [
"value"
],
"link": [
"href",
"crossorigin",
"rel",
"as",
"media",
"hreflang",
"integrity",
"referrerpolicy",
"sizes",
"imagesrcset",
"imagesizes",
"disabled",
"fetchpriority"
],
"main": [],
"map": [
"name"
],
"mark": [],
"meta": [
"name",
"http-equiv",
"content",
"charset",
"media"
],
"meter": [
"value",
"min",
"max",
"low",
"high",
"optimum",
"form"
],
"nav": [],
"noscript": [],
"object": [
"data",
"type",
"name",
"form",
"width",
"height",
"usemap",
"typemustmatch"
],
"ol": [
"reversed",
"start",
"type"
],
"optgroup": [
"disabled",
"label"
],
"option": [
"disabled",
"label",
"selected",
"value"
],
"output": [
"for",
"form",
"name"
],
"p": [],
"picture": [],
"pre": [],
"progress": [
"value",
"max"
],
"q": [
"cite"
],
"rp": [],
"rt": [],
"ruby": [],
"s": [],
"samp": [],
"script": [
"src",
"type",
"async",
"defer",
"crossorigin",
"integrity",
"nomodule",
"referrerpolicy",
"fetchpriority"
],
"section": [],
"select": [
"autocomplete",
"disabled",
"form",
"multiple",
"name",
"required",
"size"
],
"slot": [
"name"
],
"small": [],
"source": [
"src",
"type",
"srcset",
"sizes",
"media",
"width",
"height"
],
"span": [],
"strong": [],
"style": [
"media",
"nonce",
"type"
],
"sub": [],
"summary": [],
"sup": [],
"table": [],
"tbody": [],
"td": [
"colspan",
"rowspan",
"headers"
],
"template": [],
"textarea": [
"cols",
"rows",
"wrap",
"autocomplete",
"dirname",
"disabled",
"form",
"maxlength",
"minlength",
"name",
"placeholder",
"readonly",
"required"
],
"tfoot": [],
"th": [
"colspan",
"rowspan",
"headers",
"scope",
"abbr"
],
"thead": [],
"time": [
"datetime"
],
"title": [],
"tr": [],
"track": [
"default",
"kind",
"label",
"src",
"srclang"
],
"u": [],
"ul": [],
"var": [],
"video": [
"src",
"crossorigin",
"preload",
"autoplay",
"loop",
"muted",
"controls",
"width",
"height",
"poster",
"playsinline"
],
"wbr": []
}

View File

@ -4,22 +4,9 @@ import { AnsiUp } from 'ansi_up'
const buffer: string[] = []
const NOSPACE_TOKEN = '!!ribbit-nospace!!'
const TAG_TOKEN = '!!ribbit-tag!!'
const SELF_CLOSING = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]
const HTML5_TAGS = [
"a", "abbr", "address", "area", "article", "aside", "audio", "b", "base",
"bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption",
"cite", "code", "col", "colgroup", "data", "datalist", "dd", "del",
"details", "dfn", "dialog", "div", "dl", "dt", "em", "embed", "fieldset",
"figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5",
"h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "img",
"input", "ins", "kbd", "label", "legend", "li", "link", "main", "map",
"mark", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup",
"option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt",
"ruby", "s", "samp", "script", "section", "select", "slot", "small",
"source", "span", "strong", "style", "sub", "summary", "sup", "svg",
"table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead",
"time", "title", "tr", "track", "u", "ul", "var", "video", "wbr"
]
const SELF_CLOSING = await Bun.file('./data/self-closing.json').json()
const HTML5_TAGS = await Bun.file('./data/tags.json').json()
const HTML5_ATTRS = await Bun.file('./data/attrs.json').json()
export function wrapCode(code: string): string {
return "ribbit do:\n " + code + "\nend"
@ -52,7 +39,7 @@ export const ribbitGlobals = {
}
}
for (const name of HTML5_TAGS) {
for (const name of Object.keys(HTML5_TAGS)) {
(ribbitGlobals as any)[name] = (atNamed: {}, ...args: any[]) => tag(name, atNamed, ...args)
; (ribbitGlobals as any)[name].tagName = name
}