|
| 1 | +# Copilot Instructions for Android Syntax Highlighter |
| 2 | + |
| 3 | +## Repository Summary |
| 4 | + |
| 5 | +This is an Android library project that demonstrates how to integrate web-based syntax highlighting (PrismJS and highlight.js) into Android applications using WebView. It supports Android Legacy Views, Fragments, and Jetpack Compose. The project is **not** a published library—it's a reference implementation for developers to copy and adapt. |
| 6 | + |
| 7 | +## Project Overview |
| 8 | + |
| 9 | +- **Language**: Kotlin (primary), Java (minimal) |
| 10 | +- **Build System**: Gradle 8.11.1 with Android Gradle Plugin 8.5.2 |
| 11 | +- **Min SDK**: 29 (Android 10), Target SDK: 35 (Android 15) |
| 12 | +- **Java Version**: 17 (required) |
| 13 | +- **Kotlin Version**: 2.0.21 |
| 14 | +- **Architecture**: Multi-module Gradle project with two modules |
| 15 | + |
| 16 | +## Build Commands |
| 17 | + |
| 18 | +**Always use the Gradle wrapper** (`./gradlew`) for builds. Do not use system Gradle. |
| 19 | + |
| 20 | +| Task | Command | Description | |
| 21 | +|------|---------|-------------| |
| 22 | +| Build All | `./gradlew build` | Compiles both modules, runs unit tests, generates APK | |
| 23 | +| Clean Build | `./gradlew clean build` | Clean and rebuild from scratch | |
| 24 | +| Unit Tests | `./gradlew test` | Run unit tests only | |
| 25 | +| Lint | `./gradlew lint` | Run Android Lint checks | |
| 26 | +| Assemble Debug | `./gradlew assembleDebug` | Build debug APK only | |
| 27 | +| Assemble Release | `./gradlew assembleRelease` | Build release APK only | |
| 28 | + |
| 29 | +**Build time**: First build takes 2-3 minutes (downloads Gradle and dependencies). Subsequent builds are faster with configuration cache enabled. |
| 30 | + |
| 31 | +## Project Structure |
| 32 | + |
| 33 | +``` |
| 34 | +android-syntax-highlighter/ |
| 35 | +├── highlighter/ # Library module (reusable syntax highlighting components) |
| 36 | +│ ├── build.gradle # Library build config |
| 37 | +│ └── src/main/ |
| 38 | +│ ├── assets/www/ # PrismJS & highlight.js files (prism.js, prism.css, etc.) |
| 39 | +│ └── java/dev/hossain/ynaash/ |
| 40 | +│ ├── compose/ # SyntaxHighlighterComposable.kt (Jetpack Compose) |
| 41 | +│ ├── prismjs/ # PrismJS implementation (Fragment, WebView, Template) |
| 42 | +│ ├── highlightjs/ # highlight.js implementation |
| 43 | +│ └── webclient/ # WebView client utilities |
| 44 | +├── example/ # Demo application module |
| 45 | +│ ├── build.gradle # App build config |
| 46 | +│ └── src/main/java/dev/hossain/ynaash/example/ |
| 47 | +│ ├── SampleApp.kt # Application class |
| 48 | +│ └── ui/ # Demo activities (MainActivity, PrismJsDemoActivity, etc.) |
| 49 | +├── build.gradle # Root project build file (defines shared versions) |
| 50 | +├── settings.gradle # Module includes |
| 51 | +├── gradle.properties # Build configuration |
| 52 | +└── gradle/wrapper/ # Gradle wrapper (8.11.1) |
| 53 | +``` |
| 54 | + |
| 55 | +## Key Source Files |
| 56 | + |
| 57 | +| File | Purpose | |
| 58 | +|------|---------| |
| 59 | +| `highlighter/src/main/java/dev/hossain/ynaash/prismjs/SyntaxHighlighterWebView.kt` | Main custom WebView for PrismJS | |
| 60 | +| `highlighter/src/main/java/dev/hossain/ynaash/prismjs/SyntaxHighlighterFragment.kt` | Fragment-based implementation | |
| 61 | +| `highlighter/src/main/java/dev/hossain/ynaash/prismjs/PrismJsHtmlTemplate.kt` | HTML template function | |
| 62 | +| `highlighter/src/main/java/dev/hossain/ynaash/compose/SyntaxHighlighterComposable.kt` | Jetpack Compose wrapper | |
| 63 | +| `example/src/main/java/dev/hossain/ynaash/example/ui/MainActivity.kt` | Demo app entry point | |
| 64 | + |
| 65 | +## Configuration Files |
| 66 | + |
| 67 | +| File | Purpose | |
| 68 | +|------|---------| |
| 69 | +| `build.gradle` (root) | Defines Kotlin version, Android Gradle Plugin, shared dependency versions | |
| 70 | +| `gradle.properties` | JVM args, AndroidX settings, configuration cache enabled | |
| 71 | +| `settings.gradle` | Defines modules: `:highlighter` and `:example` | |
| 72 | +| `.github/workflows/android.yml` | CI workflow (build on push/PR to main/develop) | |
| 73 | + |
| 74 | +## CI Workflow |
| 75 | + |
| 76 | +The GitHub Actions workflow (`.github/workflows/android.yml`) runs on: |
| 77 | +- Push to `main` branch |
| 78 | +- Pull requests to `main` or `develop` branches |
| 79 | + |
| 80 | +**CI Steps**: |
| 81 | +1. Checkout code |
| 82 | +2. Setup Java 17 (Zulu distribution) |
| 83 | +3. Setup Gradle |
| 84 | +4. Run `./gradlew build` |
| 85 | + |
| 86 | +**To validate changes locally before pushing**, run: `./gradlew build` |
| 87 | + |
| 88 | +## Dependencies (defined in root build.gradle `ext` block) |
| 89 | + |
| 90 | +All version numbers are centralized in the root `build.gradle` file under the `ext` block (not using version catalogs): |
| 91 | +- `appCompatVersion = '1.7.0'` |
| 92 | +- `coreKtxVersion = '1.15.0'` |
| 93 | +- `composeBomVersion = '2024.12.01'` |
| 94 | +- `junitVersion = '4.13.2'` |
| 95 | +- `espressoCoreVersion = '3.6.1'` |
| 96 | +- `timberLibraryVersion = '5.0.1'` |
| 97 | + |
| 98 | +## Testing |
| 99 | + |
| 100 | +- **Unit tests**: Located in `*/src/test/java/` directories |
| 101 | +- **Instrumented tests**: Located in `*/src/androidTest/java/` directories |
| 102 | +- Tests are minimal (example placeholder tests exist) |
| 103 | +- Run unit tests: `./gradlew test` |
| 104 | +- Run instrumented tests: `./gradlew connectedAndroidTest` (requires Android emulator/device) |
| 105 | + |
| 106 | +## Code Style |
| 107 | + |
| 108 | +- Kotlin code style: `official` (set in gradle.properties) |
| 109 | +- No custom linting rules configured |
| 110 | +- Standard Android/Kotlin conventions apply |
| 111 | + |
| 112 | +## Important Notes |
| 113 | + |
| 114 | +1. **JavaScript is enabled** in WebViews (`@SuppressLint("SetJavaScriptEnabled")`) - this is intentional for syntax highlighting functionality. |
| 115 | + |
| 116 | +2. **Web assets location**: All JS/CSS files for syntax highlighting are in `highlighter/src/main/assets/www/`. |
| 117 | + |
| 118 | +3. **No library publication**: This project is not published to Maven. It's reference code to copy. |
| 119 | + |
| 120 | +4. **Compose support**: Uses Compose BOM for version management. The `SyntaxHighlighter` composable wraps the WebView implementation. |
| 121 | + |
| 122 | +5. **Two syntax highlighters**: Both PrismJS (`prismjs/`) and highlight.js (`highlightjs/`) implementations exist. PrismJS is the primary/recommended one. |
| 123 | + |
| 124 | +## Trust These Instructions |
| 125 | + |
| 126 | +These instructions have been validated against the actual repository structure. Only search for additional information if: |
| 127 | +- The build commands fail with unexpected errors |
| 128 | +- Files mentioned do not exist |
| 129 | +- You need details about a specific implementation not covered here |
0 commit comments