diff --git a/CHANGELOG.md b/CHANGELOG.md index e2e0bcd..7c51f12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.17.0] - 2026-10-01 + +- [#157](https://github.com/itk-dev/devops_itksites/pull/157) + Highlight detection result data with MicroLighter +- [#156](https://github.com/itk-dev/devops_itksites/pull/156) + Theme Swagger UI for dark mode + ## [1.16.0] - 2026-09-30 - [#154](https://github.com/itk-dev/devops_itksites/pull/154) @@ -416,7 +423,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.0.0] - 2022-09-15 -[Unreleased]: https://github.com/itk-dev/devops_itksites/compare/1.16.0...HEAD +[Unreleased]: https://github.com/itk-dev/devops_itksites/compare/1.17.0...HEAD +[1.17.0]: https://github.com/itk-dev/devops_itksites/compare/1.16.0...1.17.0 [1.16.0]: https://github.com/itk-dev/devops_itksites/compare/1.15.1...1.16.0 [1.15.1]: https://github.com/itk-dev/devops_itksites/compare/1.15.0...1.15.1 [1.15.0]: https://github.com/itk-dev/devops_itksites/compare/1.14.0...1.15.0 diff --git a/assets/admin.js b/assets/admin.js index ec0e849..7bd14d4 100644 --- a/assets/admin.js +++ b/assets/admin.js @@ -1,4 +1,6 @@ +import "microlighter/themes/github.css"; import "./styles/admin.css"; +import "microlighter/micro-lighter-element.js"; import TomSelect from "tom-select"; const tomSelectHandler = () => { diff --git a/assets/styles/admin.css b/assets/styles/admin.css index 475085c..fa08797 100644 --- a/assets/styles/admin.css +++ b/assets/styles/admin.css @@ -39,3 +39,13 @@ background: var(--button-invisible-danger-hover-hover-bg); } } + +/* Code highlighted with follows the EasyAdmin light/dark + switch rather than the OS setting its theme uses. */ +.ea-light-scheme [data-syntax-theme] { + color-scheme: light; +} + +.ea-dark-scheme [data-syntax-theme] { + color-scheme: dark; +} diff --git a/assets/styles/api-docs.css b/assets/styles/api-docs.css index a2e9ef5..9255553 100644 --- a/assets/styles/api-docs.css +++ b/assets/styles/api-docs.css @@ -111,6 +111,32 @@ header #logo img { outline-color: var(--itk-blue); } +/* Swagger UI dark mode (html.dark-mode, set from prefers-color-scheme): a dark + header and light title instead of the fixed light ones above, and cyan for + blue text, as in the Scalar dark theme below. */ +html.dark-mode header:before { + background-color: var(--apip-page-background); + border-bottom-color: var(--apip-block-border); +} + +html.dark-mode #swagger-ui.api-platform .info .title { + color: #fff; +} + +html.dark-mode .swagger-ui .info a, +html.dark-mode #formats a { + color: var(--itk-cyan); +} + +html.dark-mode .swagger-ui .scheme-container .btn.authorize { + color: var(--itk-cyan); + border-color: var(--itk-cyan); +} + +html.dark-mode .swagger-ui .scheme-container .btn.authorize svg { + fill: var(--itk-cyan); +} + /* Scalar (?ui=scalar). Its themes live in cascade layers, so these unlayered rules win without !important. */ .light-mode, diff --git a/package.json b/package.json index cee2ef2..6f243a3 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "type": "module", "devDependencies": { "@symfony/reprise": "^1.3.0", + "microlighter": "^2.2.0", "prettier": "^2.8.3", "tom-select": "^2.2.2", "vite": "^8.3.1" diff --git a/src/Controller/Admin/DetectionResultCrudController.php b/src/Controller/Admin/DetectionResultCrudController.php index ebf1c4f..8e47eff 100644 --- a/src/Controller/Admin/DetectionResultCrudController.php +++ b/src/Controller/Admin/DetectionResultCrudController.php @@ -16,8 +16,8 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Filters; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; -use EasyCorp\Bundle\EasyAdminBundle\Field\CodeEditorField; use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField; +use EasyCorp\Bundle\EasyAdminBundle\Field\Field; /** * @extends AbstractCrudController @@ -54,7 +54,9 @@ public function configureFields(string $pageName): iterable yield DateTimeField::new('createdAt')->hideOnIndex(); yield DateTimeField::new('modifiedAt')->hideOnIndex(); yield DateTimeField::new('lastContact'); - yield CodeEditorField::new('prettyData')->hideOnIndex()->setLabel('Data'); + yield Field::new('prettyData')->onlyOnDetail()->setLabel('Data') + ->setTemplatePath('EasyAdminBundle/Fields/code_highlight.html.twig') + ->setCustomOption('language', 'json'); } #[\Override] diff --git a/src/Entity/DetectionResult.php b/src/Entity/DetectionResult.php index 7bbf0da..1bcdc57 100644 --- a/src/Entity/DetectionResult.php +++ b/src/Entity/DetectionResult.php @@ -143,7 +143,7 @@ public function getPrettyData(): string return $this->data; } - return json_encode($json, JSON_PRETTY_PRINT); + return json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } public function setData(string $data): self diff --git a/templates/EasyAdminBundle/Fields/code_highlight.html.twig b/templates/EasyAdminBundle/Fields/code_highlight.html.twig new file mode 100644 index 0000000..e2c9153 --- /dev/null +++ b/templates/EasyAdminBundle/Fields/code_highlight.html.twig @@ -0,0 +1,8 @@ +{# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #} +{# Highlighted with from assets/admin.js; the language is the + field's "language" custom option. #} +
+ +
{{ field.value }}
+
+
diff --git a/tests/Entity/DetectionResultTest.php b/tests/Entity/DetectionResultTest.php new file mode 100644 index 0000000..683860a --- /dev/null +++ b/tests/Entity/DetectionResultTest.php @@ -0,0 +1,32 @@ +setData('{"remotes":["https:\/\/github.com\/itk-dev\/sites"],"name":"Ærø"}'); + + $this->assertSame(<<<'JSON' + { + "remotes": [ + "https://github.com/itk-dev/sites" + ], + "name": "Ærø" + } + JSON, $result->getPrettyData()); + } + + public function testPrettyDataReturnsDataThatIsNotJsonAsIs(): void + { + $result = new DetectionResult()->setData('not json'); + + $this->assertSame('not json', $result->getPrettyData()); + } +} diff --git a/vite.config.js b/vite.config.js index 718ed91..cb5d576 100644 --- a/vite.config.js +++ b/vite.config.js @@ -14,5 +14,19 @@ export default defineConfig({ }, }, }, - plugins: [Symfony()], + plugins: [ + Symfony({ + copy: [ + // loads grammars with import(`./grammars/${language}.js`) + // relative to the bundle, which Vite leaves as is, so ship them next to + // it under their own names. + { + from: "node_modules/microlighter/dist/grammars", + to: "grammars", + pattern: /\.js$/, + hash: false, + }, + ], + }), + ], }); diff --git a/yarn.lock b/yarn.lock index 32b4ce2..684d36b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -234,6 +234,11 @@ lightningcss@^1.33.0: lightningcss-win32-arm64-msvc "1.33.0" lightningcss-win32-x64-msvc "1.33.0" +microlighter@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/microlighter/-/microlighter-2.2.0.tgz#c40f99cd420c26bb39bb5797c2e4e90e2f3b73c2" + integrity sha512-XFUHmKclX4taKWVpYkqJ/GlfUS27FzQTCph1u3v9OwkmQJGXry3Pk1e7SivLz6xGOCxRVyi3DSrztF3e460jrg== + nanoid@^3.3.18: version "3.3.19" resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.19.tgz#336d4aa4bcd4fb24d2cddede7ffeae40bec03f0a"