Skip to content

Commit

Permalink
[TASK] Add compatibility with typo3/cms-composer-installers v4
Browse files Browse the repository at this point in the history
Resolves: #33
  • Loading branch information
brotkrueml committed Feb 24, 2022
1 parent 2ffe880 commit b7561a6
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 45 deletions.
38 changes: 8 additions & 30 deletions Build/patches/prismjs+1.27.0.patch
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
diff --git a/node_modules/prismjs/plugins/autoloader/prism-autoloader.js b/node_modules/prismjs/plugins/autoloader/prism-autoloader.js
index ae93dc1..8dc4590 100644
index 69bfa53..c21134a 100644
--- a/node_modules/prismjs/plugins/autoloader/prism-autoloader.js
+++ b/node_modules/prismjs/plugins/autoloader/prism-autoloader.js
@@ -271,28 +271,10 @@
var lang_data = {};

var ignored_language = 'none';
- var languages_path = 'components/';

@@ -275,7 +275,7 @@

var script = Prism.util.currentScript();
- if (script) {
if (script) {
- var autoloaderFile = /\bplugins\/autoloader\/prism-autoloader\.(?:min\.)?js(?:\?[^\r\n/]*)?$/i;
- var prismFile = /(^|\/)[\w-]+\.(?:min\.)?js(?:\?[^\r\n/]*)?$/i;
-
- var autoloaderPath = script.getAttribute('data-autoloader-path');
- if (autoloaderPath != null) {
- // data-autoloader-path is set, so just use it
- languages_path = autoloaderPath.trim().replace(/\/?$/, '/');
- } else {
- var src = script.src;
- if (autoloaderFile.test(src)) {
- // the script is the original autoloader script in the usual Prism project structure
- languages_path = src.replace(autoloaderFile, 'components/');
- } else if (prismFile.test(src)) {
- // the script is part of a bundle like a custom prism.js from the download page
- languages_path = src.replace(prismFile, '$1components/');
- }
- }
- }
+
+ var languages_path = '/typo3conf/ext/codehighlight/Resources/Public/Prism/components/';

var config = Prism.plugins.autoloader = {
languages_path: languages_path,
+ var autoloaderFile = /\bplugins\/autoloader\/prism-autoloader\.(?:min\.)?(?:[0-9]+\.)?js(?:\?[^\r\n/]*)?$/i;
var prismFile = /(^|\/)[\w-]+\.(?:min\.)?js(?:\?[^\r\n/]*)?$/i;

var autoloaderPath = script.getAttribute('data-autoloader-path');
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Compatibility with typo3/cms-composer-installers v4 (#33)

### Changed
- The Prism autoloader JavaScript can't be concatenated anymore with other JavaScript files (#33)

## [2.10.0] - 2022-02-19

### Updated
Expand Down
18 changes: 15 additions & 3 deletions Classes/ViewHelpers/PrismViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static function handleMainAssets(): void
}

static::addJsFile('components/prism-core.min.js');
static::addJsFile('plugins/autoloader/prism-autoloader.min.js');
static::addJsFile('plugins/autoloader/prism-autoloader.min.js', false);
}

private static function handleLineNumbers(): void
Expand Down Expand Up @@ -263,9 +263,21 @@ private static function addCssFile(string $file, bool $prependPrismPath = true):
}
}

private static function addJsFile(string $file): void
private static function addJsFile(string $file, bool $allowConcatenation = true): void
{
static::$pageRenderer->addJsFooterFile(Extension::PRISM_BASE_PATH . $file);
if ($allowConcatenation) {
static::$pageRenderer->addJsFooterFile(Extension::PRISM_BASE_PATH . $file);
return;
}

static::$pageRenderer->addJsFooterFile(
Extension::PRISM_BASE_PATH . $file,
'',
false,
false,
'',
true
);
}

private static function addToPreAttributes(string $dataName, string $dataValue): void
Expand Down
12 changes: 12 additions & 0 deletions Documentation/Changelog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
`Unreleased <https://github.com/brotkrueml/codehighlight/compare/v2.10.0...HEAD>`_
--------------------------------------------------------------------------------------

Added
^^^^^


* Compatibility with typo3/cms-composer-installers v4 (#33)

Changed
^^^^^^^


* The Prism autoloader JavaScript can't be concatenated anymore with other JavaScript files (#33)

`2.10.0 <https://github.com/brotkrueml/codehighlight/compare/v2.9.0...v2.10.0>`_ - 2022-02-19
-------------------------------------------------------------------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion Documentation/Configuration/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,6 @@ and :php:`addJsFooterFile()`. This means, that they adhere to the configuration
setting :php:`$GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename']`
and the TypoScript settings
:ref:`config.concatenateJs <t3tsref:setup-config-concatenatejs>` and
:ref:`config.concatenateCss <t3tsref:setup-config-concatenatecss>`.
:ref:`config.concatenateCss <t3tsref:setup-config-concatenatecss>`. One
exception from concatenation is the Prism autoloader JavaScript which is used to
load the necessary language files.
5 changes: 0 additions & 5 deletions Documentation/Includes.rst.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
.. ==================================================
.. FOR YOUR INFORMATION
.. --------------------------------------------------
.. -*- coding: utf-8 -*- with BOM.
.. ==================================================
.. DEFINE SOME TEXT ROLES
.. --------------------------------------------------
Expand Down
9 changes: 4 additions & 5 deletions Documentation/Maintenance/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ these to the translation file

.. note::

Due to the variants JavaScript files can be integrated into the page (as
configured, last modification timestamp is embedded into the filename,
:ref:`concatenated <t3tsref:setup-config-concatenatejs>`) the script
Due to the variants JavaScript files can be integrated into the page (like
last modification timestamp is embedded into the filename), the script
:file:`Build/node_modules/prismjs/plugins/autoloader/prism-autoloader.js`
was patched: The variable :js:`language_path` has to be set to
:js:`/typo3conf/ext/codehighlight/Resources/Public/Prism/components/`.
was patched: The variable :js:`autoloaderFile` regex has to be set to
adjusted to consider a possibly available timestamp in the filename.
When updating the Prism library, the patch under
:file:`Build/patches/prismjs+1.xx.x.patch` has to be adjusted eventually.
The package `patch-package <https://github.com/ds300/patch-package#readme>`__
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b7561a6

Please sign in to comment.