{"id":16526117,"url":"https://github.com/markusressel/kodehighlighter","last_synced_at":"2025-07-21T15:04:10.554Z","repository":{"id":42470686,"uuid":"167466321","full_name":"markusressel/KodeHighlighter","owner":"markusressel","description":"Simple, extendable code highlighting for Spannables on Android.","archived":false,"fork":false,"pushed_at":"2024-09-16T11:26:28.000Z","size":44234,"stargazers_count":21,"open_issues_count":13,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-07T06:41:17.049Z","etag":null,"topics":["android","android-library","code-highlighter","codehighlighting","hacktoberfest","regex","regular-expression","spannable"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markusressel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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":["markusressel"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-01-25T01:42:35.000Z","updated_at":"2025-05-20T21:43:02.000Z","dependencies_parsed_at":"2024-07-15T19:46:47.887Z","dependency_job_id":"567352c0-fcd2-4804-8949-cdf5dc3d6537","html_url":"https://github.com/markusressel/KodeHighlighter","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/markusressel/KodeHighlighter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusressel%2FKodeHighlighter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusressel%2FKodeHighlighter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusressel%2FKodeHighlighter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusressel%2FKodeHighlighter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markusressel","download_url":"https://codeload.github.com/markusressel/KodeHighlighter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusressel%2FKodeHighlighter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266324442,"owners_count":23911226,"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","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-library","code-highlighter","codehighlighting","hacktoberfest","regex","regular-expression","spannable"],"created_at":"2024-10-11T17:26:09.225Z","updated_at":"2025-07-21T15:04:10.516Z","avatar_url":"https://github.com/markusressel.png","language":"Kotlin","readme":"# KodeHighlighter  [![Master](https://travis-ci.org/markusressel/KodeHighlighter.svg?branch=master)](https://travis-ci.org/markusressel/KodeHighlighter/branches) [![codebeat badge](https://codebeat.co/badges/e533d507-9e49-4010-9c02-7fb3e638bb0d)](https://codebeat.co/projects/github-com-markusressel-kodehighlighter-master)\nSimple, extendable code highlighting for Spannables on Android.\n\n# Features\n\n* [x] Compose Support (`SpanStyle`)\n* [x] View (Legacy) Support (`CharacterStyle`)\n* [x] Custom Languages\n* [x] Language specific Themes\n\n# How to use\n\nHave a look at the demo app (`app`  module) for a complete sample.\n\n# Compose\n\n## KodeText\n\n```kotlin\nval text by remember(selectedLanguage) {\n    mutableStateOf(\"# Hello World!\")\n}\nval ruleBook by remember { derivedStateOf { MarkdownRuleBook() } }\nval colorScheme by remember { derivedStateOf { de.markusressel.kodehighlighter.language.markdown.colorscheme.DarkBackgroundColorSchemeWithSpanStyle() } }\n\nKodeText(\n    modifier = Modifier\n        .padding(4.dp)\n        .wrapContentSize()\n        .fillMaxWidth(),\n    text = text,\n    languageRuleBook = ruleBook,\n    colorScheme = colorScheme,\n    textColor = MaterialTheme.colors.onSurface,\n)\n```\n\n## KodeTextField\n\n```kotlin\nval initialText = \"# Hello World!\"\nvar textFieldValue by remember(initialText) {\n    mutableStateOf(\n        TextFieldValue(\n            annotatedString = AnnotatedString(initialText),\n        )\n    )\n}\n\nKodeTextField(\n    modifier = Modifier\n        .padding(4.dp)\n        .wrapContentSize()\n        .fillMaxWidth(),\n    value = textFieldValue,\n    languageRuleBook = ruleBook,\n    colorScheme = colorScheme,\n    textStyle = LocalTextStyle.current.copy(color = MaterialTheme.colors.onSurface),\n    onValueChange = {\n        if (it != textFieldValue) {\n            textFieldValue = it\n        }\n    }\n)\n```\n\n# XML\n\n## Simple example\n\n```kotlin\nval markdownText = readResourceFileAsText(R.raw.markdown_sample)\nval markdownRuleBook = MarkdownRuleBook()\nval markdownHighlighter = SpannableHighlighter(markdownRuleBook, DarkBackgroundColorScheme())\n\nCoroutineScope(Dispatchers.Main).launch {\n    val spannable = withContext(Dispatchers.Default) {\n        val spannable = createSpannable(text)\n        markdownHighlighter.highlight(spannable)\n        spannable\n    }\n    target.text = spannable\n}\n```\n\n## Working with `EditText`\nWhen using this library with an `EditText` view, previously applied styles need to be removed\nwhen the highlighting is updated due to a text change. To make it easy for you to deal with this\nthe `EditTextHighlighter` class can be used:\n\n```kotlin\nval editTextHighlighter = EditTextHighlighter(\n        target = editTextMarkdownDark,\n        languageRuleBook = MarkdownRuleBook())\neditTextHighlighter.start()\n\nCoroutineScope(Dispatchers.Main).launch {\n    val markdown = withContext(Dispatchers.IO) {\n        readResourceFileAsText(R.raw.markdown_sample)\n    }\n    editTextMarkdownDark.setText(markdown)\n}\n```\n\nYou can then set or edit any text you like and the highlighting will refresh automatically.\n\n## Gradle\nTo use this library just include it in your dependencies using\n\n```groovy\nrepositories {\n    ...\n    maven { url \"https://jitpack.io\" }\n}\n```\n\nin your project build.gradle file and\n\n```groovy\ndependencies {\n    ...\n\n    def codeHighlighterVersion = \"v4.0.3\"\n    implementation(\"com.github.markusressel.KodeHighlighter:core:${codeHighlighterVersion}\")\n}\n```\n\nin your desired module ```build.gradle``` file.\n\n\n## Syntax highlighting\n\n### Language Autodetection\n\nCurrently there is no auto detection for the language used in a text.\n\n### Integrated language rule books\n\nThis library includes rule books for a small set of languages for you to use right away, without\nspending time to think about finding the right tokens and color schemes:\n\n* java\n* json\n* kotlin\n* markdown\n* python\n\nTo include one of them in your project, just pick the ones you would like to use\nand - **in addition** to the `core` module - import them as a dependency:\n\n```groovy\ndependencies {\n    ...\n\n    implementation(\"com.github.markusressel.KodeHighlighter:java:${codeHighlighterVersion}\")\n    implementation(\"com.github.markusressel.KodeHighlighter:json:${codeHighlighterVersion}\")\n    implementation(\"com.github.markusressel.KodeHighlighter:kotlin:${codeHighlighterVersion}\")\n    implementation(\"com.github.markusressel.KodeHighlighter:markdown:${codeHighlighterVersion}\")\n    implementation(\"com.github.markusressel.KodeHighlighter:python:${codeHighlighterVersion}\")\n    [etc.]\n```\n\n### Writing a custom rule book\n\nA `LanguageRuleBook` consists of a **default color scheme** and a **set of rules** that provide\ninformation on how to style different parts of the `Spannable`. Have a look at how the\n[MarkdownRuleBook](markdown/src/main/java/de/markusressel/kodehighlighter/language/markdown/MarkdownRuleBook.kt)\nis implemented to get a feel for how to implement it yourself.\n\n### Styling\n\nDifferent highlighting styles for a given language can be achieved\nby implementing the `ColorScheme` interface and passing it to the highlighter\n(f.ex. a `SpannableHighlighter`). For more info on how to do this have a look at the\n[DarkBackgroundColorScheme from the Markdown rule book](markdown/src/main/java/de/markusressel/kodehighlighter/language/markdown/colorscheme/DarkBackgroundColorScheme.kt).\n\n# Contributing\n\nGitHub is for social coding: if you want to write code, I encourage contributions through pull requests from forks\nof this repository. Create GitHub tickets for bugs and new features and comment on the ones that you are interested in.\n\n# License\n\n```\nMIT License\n\nCopyright (c) 2018 Markus Ressel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","funding_links":["https://github.com/sponsors/markusressel"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusressel%2Fkodehighlighter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkusressel%2Fkodehighlighter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusressel%2Fkodehighlighter/lists"}