{"id":20206023,"url":"https://github.com/jaredrummler/htmldsl","last_synced_at":"2025-04-05T02:10:18.839Z","repository":{"id":44488901,"uuid":"77140259","full_name":"jaredrummler/HtmlDsl","owner":"jaredrummler","description":"Build valid HTML for Android TextView","archived":false,"fork":false,"pushed_at":"2023-02-03T07:35:44.000Z","size":769,"stargazers_count":538,"open_issues_count":3,"forks_count":94,"subscribers_count":21,"default_branch":"main","last_synced_at":"2024-05-22T06:12:29.807Z","etag":null,"topics":["android","android-textview","dsl","html","html-builder","html-dsl","html-tags","kotlin","spannable","textview"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/jaredrummler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-22T11:47:52.000Z","updated_at":"2024-01-01T11:23:20.000Z","dependencies_parsed_at":"2023-02-18T04:31:26.400Z","dependency_job_id":null,"html_url":"https://github.com/jaredrummler/HtmlDsl","commit_stats":null,"previous_names":["jaredrummler/htmlbuilder","jrummyapps/html-builder"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredrummler%2FHtmlDsl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredrummler%2FHtmlDsl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredrummler%2FHtmlDsl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredrummler%2FHtmlDsl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredrummler","download_url":"https://codeload.github.com/jaredrummler/HtmlDsl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276189,"owners_count":20912288,"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":["android","android-textview","dsl","html","html-builder","html-dsl","html-tags","kotlin","spannable","textview"],"created_at":"2024-11-14T05:20:47.597Z","updated_at":"2025-04-05T02:10:18.823Z","avatar_url":"https://github.com/jaredrummler.png","language":"Kotlin","readme":"\u003cimg src=\".github/demo-med.png\" align=\"left\" hspace=\"10\" vspace=\"10\"\u003e\n\n# HTML DSL\n\n**Provides a DSL to build HTML for Android TextView**\n\n\u003ca target=\"_blank\" href=\"LICENSE\"\u003e\u003cimg src=\"http://img.shields.io/:license-apache-blue.svg\" alt=\"License\" /\u003e\u003c/a\u003e\n\u003ca target=\"_blank\" href=\"https://maven-badges.herokuapp.com/maven-central/com.jaredrummler/htmldsl\"\u003e\u003cimg src=\"https://maven-badges.herokuapp.com/maven-central/com.jaredrummler/ktsh/badge.svg\" alt=\"Maven Central\" /\u003e\u003c/a\u003e\n\u003ca target=\"_blank\" href=\"https://twitter.com/jaredrummler\"\u003e\u003cimg src=\"https://img.shields.io/twitter/follow/jaredrummler.svg?style=social\" /\u003e\u003c/a\u003e\n\n### Description\n\nThere is a lovely method on the `android.text.Html` class, `fromHtml`, that converts HTML into a `Spannable` for use with a `TextView`.\n\nHowever, the documentation does not stipulate what HTML tags are supported, which makes this method a bit hit-or-miss. This small library provides a DSL for building valid HTML for `android.widget.TextView`.\n\n## Download\n\nDownload [the latest AAR](https://repo1.maven.org/maven2/com/jaredrummler/html-dsl/1.0.0/html-dsl-1.0.0.aar) or grab via Gradle:\n\n```kotlin\nimplementation(\"com.jaredrummler:html-dsl:1.0.0\")\n```\n\n## Structure\n\n* `buildSrc` — Gradle dependencies, plugins, versions\n* `library` - The HTML DSL library\n* `library/src/test` - Unit tests for the library\n* `demo` - Android demo project using HTML DSL\n* `scripts` - Scripts to publish library to Maven\n\n----------\n\n## Usage\n\n### Create HTML:\n\n```kotlin\nHTML.create {\n        h1(\"HTML DSL\")\n        strong(\"Provides a DSL to build HTML for Android TextView\")\n}\n```\n\n### Set HTML on a `TextView`:\n\n```kotlin\ntextView.setHtml {\n    h1(\"HTML DSL\").br()\n    strong(\"Build valid HTML for Android TextView.\").br().br()\n    h3(\"Android Versions:\")\n    ul {\n        li {\n            a(href = \"https://developer.android.com/about/versions/12/get\") {\n                +\"Android 12 Beta\"\n            }\n        }\n        li(\"Android 11\")\n        li(\"Android 10\")\n        li(\"Pie\")\n        li(\"Oreo\")\n        li(\"Nougat\")\n        li(\"Marshmallow\")\n        li(\"Lollipop\")\n        // ...\n    }\n\n    small {\n        sub {\n            +\"by \"\n            a {\n                href = \"https://github.com/jaredrummler\"\n                text = \"Jared Rummler\"\n            }\n        }\n    }\n}\n```\n\n### Render HTML to a string\n\n```kotlin\nval htmlString = HTML.create {\n    p {\n        font(face = \"monospace\", color = \"#3ddc84\") {\n            unsafe {\n                +\"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\"\n            }\n        }\n    }\n}.render(prettyPrint = true)\n```\n\n### Write HTML to a file:\n\n```kotlin\nHtmlRenderer\u003cFileWriter\u003e(HTML.create {\n    small {\n        sub {\n            +\"by \"\n            a {\n                href = \"https://github.com/jaredrummler\"\n                text = \"Jared Rummler\"\n            }\n        }\n    }\n}, FileWriter(\"output.html\"), true)\n```\n\n## Supported HTML elements:\n\n\u003cul\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;a href=\u0026quot;...\u0026quot;\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;b\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;big\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;blockquote\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;br\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;cite\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;dfn\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;div align=\u0026quot;...\u0026quot;\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;em\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;font color=\u0026quot;...\u0026quot; face=\u0026quot;...\u0026quot;\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;h1\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;h2\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;h3\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;h4\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;h5\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;h6\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;i\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;img src=\u0026quot;...\u0026quot;\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;p\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;small\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;strike\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;strong\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;sub\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;sup\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;tt\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;u\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;ul\u0026gt;\u003c/code\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ccode\u003e\u0026lt;li\u0026gt;\u003c/code\u003e\u003c/li\u003e\n \u003c/ul\u003e\n \n \n## License\n\n    Copyright 2021 Jared Rummler\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredrummler%2Fhtmldsl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredrummler%2Fhtmldsl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredrummler%2Fhtmldsl/lists"}