Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 10, 2025

This PR adds comprehensive Jetpack Compose support to the Android Syntax Highlighter, enabling modern declarative UI development while maintaining compatibility with existing WebView-based functionality.

Changes Made

🚀 New Compose Component

  • SyntaxHighlighterComposable.kt: A new Compose component that wraps the existing SyntaxHighlighterWebView using AndroidView
  • Supports all existing parameters: sourceCode, language, showLineNumbers
  • Includes reactive updates and standard Compose Modifier support
  • Maintains full compatibility with PrismJS functionality

📱 Demo Implementation

  • PrismJsComposeDemoActivity.kt: Complete demo showcasing Compose usage
  • Multiple syntax highlighting examples in a scrollable Material3 UI
  • Navigation integration from main activity
  • Preview functions for Android Studio design tools

🔧 Build Configuration

  • Added Compose BOM (2024.12.01) to both highlighter and example modules
  • Configured Compose compiler and build features
  • Added necessary Compose dependencies: ui, material3, activity-compose

📚 Documentation

  • Comprehensive README updates with Compose section
  • Complete usage examples and setup instructions
  • Dependency configuration details
  • Updated project objective to highlight Compose support

Usage Example

@Composable
fun MyScreen() {
    SyntaxHighlighter(
        sourceCode = "data class Student(val name: String, val age: Int)",
        language = "kotlin",
        showLineNumbers = true,
        modifier = Modifier.fillMaxSize()
    )
}

Key Benefits

  • Minimal Impact: Reuses existing proven WebView-based logic
  • Full Compatibility: Maintains backward compatibility with existing implementations
  • Modern UI: Enables declarative Compose development
  • Comprehensive: Includes dependencies, examples, and documentation

The implementation follows Android best practices by wrapping the existing WebView component rather than reimplementing syntax highlighting logic, ensuring reliability and maintainability.

Fixes #85.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.11.1-bin/bpt9gzteqjrbo1mjrsomdt32c/gradle-8.11.1/lib/gradle-daemon-main-8.11.1.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.11.1-bin/bpt9gzteqjrbo1mjrsomdt32c/gradle-8.11.1/lib/agents/gradle-instrumentation-agent-8.11.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.11.1 (dns block)
  • google.com
    • Triggering command: ping -c 1 google.com (dns block)
    • Triggering command: curl -I REDACTED --connect-timeout 5 (dns block)
    • Triggering command: nslookup google.com (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 2 commits June 10, 2025 14:45
Co-authored-by: hossain-khan <99822+hossain-khan@users.noreply.github.com>
Co-authored-by: hossain-khan <99822+hossain-khan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add jetpack compose based solution to enable syntax highlighting Add Jetpack Compose support for syntax highlighting Jun 10, 2025
Copilot AI requested a review from hossain-khan June 10, 2025 14:53
Copilot finished work on behalf of hossain-khan June 10, 2025 14:53
@hossain-khan hossain-khan marked this pull request as ready for review June 10, 2025 20:45
Copy link
Owner

@hossain-khan hossain-khan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still compiles and works! So, let's go! 🚀

@hossain-khan hossain-khan merged commit 36cb5cf into main Jun 10, 2025
1 check passed
@hossain-khan hossain-khan deleted the copilot/fix-85 branch June 10, 2025 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add jetpack compose based solution to enable syntax highlighting

2 participants