{"id":15056317,"url":"https://github.com/bel-framework/bel-dom","last_synced_at":"2026-01-02T05:23:19.948Z","repository":{"id":233898650,"uuid":"787735022","full_name":"bel-framework/bel-dom","owner":"bel-framework","description":"DOM (Document Object Model) API for Erlang","archived":false,"fork":false,"pushed_at":"2024-04-17T14:26:03.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-21T00:50:14.970Z","etag":null,"topics":["css","css-parser","css3","dom-manipulation","erlang","erlang-library","html","html-parser","html5","parser"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bel-framework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["williamthome"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":["https://www.buymeacoffee.com/williamthome"]}},"created_at":"2024-04-17T04:46:16.000Z","updated_at":"2024-04-17T14:39:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"957a035a-515e-42e7-b6dd-4a95f4d8ad9a","html_url":"https://github.com/bel-framework/bel-dom","commit_stats":null,"previous_names":["bel-framework/bel-dom"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bel-framework%2Fbel-dom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bel-framework%2Fbel-dom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bel-framework%2Fbel-dom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bel-framework%2Fbel-dom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bel-framework","download_url":"https://codeload.github.com/bel-framework/bel-dom/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243532562,"owners_count":20306156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","css-parser","css3","dom-manipulation","erlang","erlang-library","html","html-parser","html5","parser"],"created_at":"2024-09-24T21:49:52.961Z","updated_at":"2026-01-02T05:23:19.908Z","avatar_url":"https://github.com/bel-framework.png","language":"Erlang","funding_links":["https://github.com/sponsors/williamthome","https://www.buymeacoffee.com/williamthome"],"categories":[],"sub_categories":[],"readme":"# bel-framework/bel-dom\n\nDOM (Document Object Model) API for Erlang.\n\n## HTML\n\n### Scanner and Parser\n\n#### Example\n\n```erlang\n1\u003e String = \u003c\u003c\"\n   \u003c!DOCTYPE html\u003e\n   \u003chtml lang=\\\"en\\\"\u003e\n   \u003c!-- Comment --\u003e\n   \u003chead\u003e\n       \u003ctitle\u003e\u003cb\u003econtent inside \u003ctitle\u003e must be treated as plaintext\u003c/b\u003e\u003c/title\u003e\n       \u003cscript src=\\\"assets/foo.js\\\"\u003e\u003c/script\u003e\n       \u003cstyle\u003e\n           :root {\n               --foo: 0;\n           }\n       \u003c/style\u003e\n   \u003c/head\u003e\n   \u003cbody\u003e\n       \u003ch1\u003eForm\u003c/h1\u003e\n       \u003cbr\u003e\n       \u003cbr/\u003e\n       \u003cform\u003e\n           \u003cdiv\u003eFoo Form\u003c/div\u003e\n           \u003cinput id=\\\"foo\\\" class=' foo   bar   ' name='foo' value='\\\"b\\ar\\\"' /\u003e\n           \u003cinput type=\\\"number\\\" value=10 /\u003e\n       \u003c/form\u003e\n   \u003c/body\u003e\n   \u003c/html\u003e\n   \"\u003e\u003e.\n\n2\u003e Tokens = bel_dom:scan_document(String).\n[{open,{{2,4},undefined,undefined},\n       {\u003c\u003c\"!DOCTYPE\"\u003e\u003e,[{\u003c\u003c\"html\"\u003e\u003e,{true,{2,4}}}]}},\n {open,{{3,4},undefined,undefined},\n       {\u003c\u003c\"html\"\u003e\u003e,[{\u003c\u003c\"lang\"\u003e\u003e,{\u003c\u003c\"en\"\u003e\u003e,{3,4}}}]}},\n {comment,{{4,4},undefined,undefined},\u003c\u003c\" Comment \"\u003e\u003e},\n {open,{{5,4},undefined,undefined},{\u003c\u003c\"head\"\u003e\u003e,[]}},\n {open,{{6,8},undefined,undefined},{\u003c\u003c\"title\"\u003e\u003e,[]}},\n {text,{{6,15},undefined,undefined},\n       \u003c\u003c\"\u003cb\u003econtent inside \u003ctitle\u003e must be treated as plaintext\u003c/b\u003e\"\u003e\u003e},\n {close,{{6,73},undefined,undefined},\u003c\u003c\"title\"\u003e\u003e},\n {open,{{7,8},undefined,undefined},\n       {\u003c\u003c\"script\"\u003e\u003e,[{\u003c\u003c\"src\"\u003e\u003e,{\u003c\u003c\"assets/foo.js\"\u003e\u003e,{7,8}}}]}},\n {close,{{7,36},undefined,undefined},\u003c\u003c\"script\"\u003e\u003e},\n {open,{{8,8},undefined,undefined},{\u003c\u003c\"style\"\u003e\u003e,[]}},\n {text,{{8,15},undefined,undefined},\n       \u003c\u003c\":root {\\n               --foo: 0;\\n           }\"\u003e\u003e},\n {close,{{12,8},undefined,undefined},\u003c\u003c\"style\"\u003e\u003e},\n {close,{{13,4},undefined,undefined},\u003c\u003c\"head\"\u003e\u003e},\n {open,{{14,4},undefined,undefined},{\u003c\u003c\"body\"\u003e\u003e,[]}},\n {open,{{15,8},undefined,undefined},{\u003c\u003c\"h1\"\u003e\u003e,[]}},\n {text,{{15,12},undefined,undefined},\u003c\u003c\"Form\"\u003e\u003e},\n {close,{{15,16},undefined,undefined},\u003c\u003c\"h1\"\u003e\u003e},\n {void,{{16,8},undefined,undefined},{\u003c\u003c\"br\"\u003e\u003e,[]}},\n {void,{{17,8},undefined,undefined},{\u003c\u003c\"br\"\u003e\u003e,[]}},\n {open,{{18,8},undefined,undefined},{\u003c\u003c\"form\"\u003e\u003e,[]}},\n {open,{{19,12},undefined,undefined},{\u003c\u003c\"div\"\u003e\u003e,[]}},\n {text,{{19,17},undefined,undefined},\u003c\u003c\"Foo Form\"\u003e\u003e},\n {close,{{19,25},undefined,undefined},\u003c\u003c\"div\"\u003e\u003e},\n {void,{{20,12},undefined,undefined},\n       {\u003c\u003c\"input\"\u003e\u003e,\n        [{\u003c\u003c\"id\"\u003e\u003e,{\u003c\u003c\"foo\"\u003e\u003e,{20,12}}},\n         {\u003c\u003c\"class\"\u003e\u003e,{[\u003c\u003c\"foo\"\u003e\u003e,\u003c\u003c\"bar\"\u003e\u003e],{20,21}}},\n         {\u003c\u003c\"name\"\u003e\u003e,{\u003c\u003c\"foo\"\u003e\u003e,{20,43}}},\n         {\u003c\u003c\"value\"\u003e\u003e,{\u003c\u003c\"\\\"bar\\\"\"\u003e\u003e,{20,54}}}]}},\n {void,{{21,12},undefined,undefined},\n       {\u003c\u003c\"input\"\u003e\u003e,\n        [{\u003c\u003c\"type\"\u003e\u003e,{\u003c\u003c\"number\"\u003e\u003e,{21,12}}},\n         {\u003c\u003c\"value\"\u003e\u003e,{\u003c\u003c\"10\"\u003e\u003e,{21,26}}}]}},\n {close,{{22,8},undefined,undefined},\u003c\u003c\"form\"\u003e\u003e},\n {close,{{23,4},undefined,undefined},\u003c\u003c\"body\"\u003e\u003e},\n {close,{{24,4},undefined,undefined},\u003c\u003c\"html\"\u003e\u003e}]\n\n3\u003e bel_dom:parse_document(Tokens).\n[{\u003c\u003c\"!DOCTYPE\"\u003e\u003e,\n  #{\u003c\u003c\"html\"\u003e\u003e =\u003e true},\n  [{\u003c\u003c\"html\"\u003e\u003e,\n    #{\u003c\u003c\"lang\"\u003e\u003e =\u003e \u003c\u003c\"en\"\u003e\u003e},\n    [{\u003c\u003c\"head\"\u003e\u003e,#{},\n      [{\u003c\u003c\"title\"\u003e\u003e,#{},\n        [\u003c\u003c\"\u003cb\u003econtent inside \u003ctitle\u003e must be treated as plaintext\u003c/b\u003e\"\u003e\u003e]},\n       {\u003c\u003c\"script\"\u003e\u003e,#{\u003c\u003c\"src\"\u003e\u003e =\u003e \u003c\u003c\"assets/foo.js\"\u003e\u003e},[]},\n       {\u003c\u003c\"style\"\u003e\u003e,#{},\n        [\u003c\u003c\":root {\\n               --foo: 0;\\n           }\"\u003e\u003e]}]},\n     {\u003c\u003c\"body\"\u003e\u003e,#{},\n      [{\u003c\u003c\"h1\"\u003e\u003e,#{},[\u003c\u003c\"Form\"\u003e\u003e]},\n       {\u003c\u003c\"br\"\u003e\u003e,#{},[]},\n       {\u003c\u003c\"br\"\u003e\u003e,#{},[]},\n       {\u003c\u003c\"form\"\u003e\u003e,#{},\n        [{\u003c\u003c\"div\"\u003e\u003e,#{},[\u003c\u003c\"Foo Form\"\u003e\u003e]},\n         {\u003c\u003c\"input\"\u003e\u003e,\n          #{\u003c\u003c\"class\"\u003e\u003e =\u003e [\u003c\u003c\"foo\"\u003e\u003e,\u003c\u003c\"bar\"\u003e\u003e],\n            \u003c\u003c\"id\"\u003e\u003e =\u003e \u003c\u003c\"foo\"\u003e\u003e,\u003c\u003c\"name\"\u003e\u003e =\u003e \u003c\u003c\"foo\"\u003e\u003e,\n            \u003c\u003c\"value\"\u003e\u003e =\u003e \u003c\u003c\"\\\"bar\\\"\"\u003e\u003e},\n          []},\n         {\u003c\u003c\"input\"\u003e\u003e,\n          #{\u003c\u003c\"type\"\u003e\u003e =\u003e \u003c\u003c\"number\"\u003e\u003e,\u003c\u003c\"value\"\u003e\u003e =\u003e \u003c\u003c\"10\"\u003e\u003e},\n          []}]}]}]}]}]\n```\n\n## CSS\n\n### Scanner and Parser\n\n#### Example\n\n```erlang\n1\u003e Query = \u003c\u003c\"#foo \u003e .bar + div.k1.k2 [id='baz']:hello(2):not(:where(div))::before, #bar + .baz.fizz div.buzz\"\u003e\u003e.\n\n2\u003e {ok, Tokens, _} = bel_dom:scan_query(Query).\n{ok,[{hash,{1,1},\u003c\u003c\"foo\"\u003e\u003e},\n     {greater,{1,5}},\n     {space,{1,7}},\n     {'.',{1,8}},\n     {ident,{1,9},\u003c\u003c\"bar\"\u003e\u003e},\n     {plus,{1,12}},\n     {space,{1,14}},\n     {ident,{1,15},\u003c\u003c\"div\"\u003e\u003e},\n     {'.',{1,18}},\n     {ident,{1,19},\u003c\u003c\"k1\"\u003e\u003e},\n     {'.',{1,21}},\n     {ident,{1,22},\u003c\u003c\"k2\"\u003e\u003e},\n     {space,{1,24}},\n     {'[',{1,25}},\n     {ident,{1,26},\u003c\u003c\"id\"\u003e\u003e},\n     {'=',{1,28}},\n     {string,{1,29},\u003c\u003c\"baz\"\u003e\u003e},\n     {']',{1,34}},\n     {':',{1,35}},\n     {function,{1,36},\u003c\u003c\"hello\"\u003e\u003e},\n     {number,{1,42},\u003c\u003c\"2\"\u003e\u003e},\n     {')',{1,43}},\n     {'not',{1,44}},\n     {':',{1,49}},\n     {function,{1,50},\u003c\u003c\"where\"\u003e\u003e},\n     {ident,{1,56},\u003c\u003c\"div\"\u003e\u003e},\n     {')',{1,59}},\n     {')',{1,60}},\n     {':',{1,61}},\n     {':',{1,62}},\n     {ident,{1,63},\u003c\u003c\"before\"\u003e\u003e},\n     {comma,{1,69}},\n     {space,{1,70}},\n     {hash,{1,71},\u003c\u003c\"bar\"\u003e\u003e},\n     {plus,{1,75}},\n     {space,{1,77}},\n     {'.',{1,78}},\n     {ident,{1,79},\u003c\u003c\"baz\"\u003e\u003e},\n     {'.',{1,82}},\n     {ident,{1,83},\u003c\u003c\"fizz\"\u003e\u003e},\n     {space,{1,87}},\n     {ident,{1,88},\u003c\u003c\"div\"\u003e\u003e},\n     {'.',{1,91}},\n     {ident,{1,92},\u003c\u003c\"buzz\"\u003e\u003e}],\n    1}\n\n3\u003e bel_dom:parse_query(Tokens).\n{ok,[{greater,\n         {[{id,\u003c\u003c\"foo\"\u003e\u003e}],\n          {plus,\n              {[{class,\u003c\u003c\"bar\"\u003e\u003e}],\n               {space,\n                   {[{type,{undefined,\u003c\u003c\"div\"\u003e\u003e}},\n                     {class,\u003c\u003c\"k1\"\u003e\u003e},\n                     {class,\u003c\u003c\"k2\"\u003e\u003e}],\n                    [{attrib,{undefined,\u003c\u003c\"id\"\u003e\u003e,{'=',{string,\u003c\u003c\"baz\"\u003e\u003e}}}},\n                     {pseudo_class,{function,{\u003c\u003c\"hello\"\u003e\u003e,[{number,\u003c\u003c\"2\"\u003e\u003e}]}}},\n                     {negation,\n                         {pseudo_class,\n                             {function,{\u003c\u003c\"where\"\u003e\u003e,[{ident,\u003c\u003c\"div\"\u003e\u003e}]}}}},\n                     {pseudo_element,{ident,\u003c\u003c\"before\"\u003e\u003e}}]}}}}}},\n     {plus,\n         {[{id,\u003c\u003c\"bar\"\u003e\u003e}],\n          {space,\n              {[{class,\u003c\u003c\"baz\"\u003e\u003e},{class,\u003c\u003c\"fizz\"\u003e\u003e}],\n               [{type,{undefined,\u003c\u003c\"div\"\u003e\u003e}},{class,\u003c\u003c\"buzz\"\u003e\u003e}]}}}}]}\n```\n\n## DOM\n\n### Query\n\n#### Example\n\n```erlang\n1\u003e bel_dom:query_selector(\u003c\u003c\"#foo.bar\"\u003e\u003e, \u003c\u003c\"\u003cdiv\u003e\u003cp id='foo' class='bar'\u003ebel-framework\u003c/p\u003e\u003c/div\u003e\"\u003e\u003e).\n{\u003c\u003c\"p\"\u003e\u003e,\n #{\u003c\u003c\"class\"\u003e\u003e =\u003e [\u003c\u003c\"bar\"\u003e\u003e],\u003c\u003c\"id\"\u003e\u003e =\u003e \u003c\u003c\"foo\"\u003e\u003e},\n [\u003c\u003c\"bel-framework\"\u003e\u003e]}\n```\n\n## TODO\n\n- [ ] Specs\n- [ ] Doc\n- [ ] Improve tests\n- [ ] Fix query issues and implement all missing patterns:\n  - [ ] {attrib, {NamespacePrefix, Ident, Match}}\n  - [ ] {pseudo_class, {ident, Ident} | {'function, {Name, Exprs}}}\n  - [ ] {pseudo_element, {ident, Ident} | {'function, {Name, Exprs}}}\n  - [ ] {negation, Arg}\n  - [ ] {universal, NamespacePrefix}\n\n## Build\n\n```shell\n$ rebar3 compile\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbel-framework%2Fbel-dom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbel-framework%2Fbel-dom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbel-framework%2Fbel-dom/lists"}