Skip to content
Snippets Groups Projects
Commit a6611122 authored by João Eduardo Ramos Costa's avatar João Eduardo Ramos Costa Committed by Joshua Sedler
Browse files

Issue #3504552: Make "glossify-exclude" class detection more robust

parent f451b85b
Branches
Tags 3.0.5
1 merge request!37Issue #3504552: Make "glossify-exclude" class detection more robust
Pipeline #438865 passed with warnings
......@@ -89,9 +89,24 @@ function MODULE_query_glossify_taxonomy_tooltip_alter(Drupal\Core\Database\Query
1. Go to Administration » Configuration » Content authoring » Text formats
and editors
1. Edit a text format, for example "Basic HTML"
1. Enable a Glossify filter and configure it under "Filter settings"
2. Edit a text format, for example "Basic HTML"
3. Enable a Glossify filter and configure it under "Filter settings"
### Exclude terms from filter processing
1. Wrap the relevant text (Term name or Node title) in a element with
'glossify-exclude' class within the specified formatted text instance.
Example: "<span class="glossify-exclude">text</span>".
2. Tip: The CKEditor 5 / CKEditor Style plugin allows users to apply predefined styles
to their text, so glossary-exclude can be added as needed to exclude certain
terms from being glossified in specific instances:
- Go to /admin/config/content/formats
- Configure concerning text format where the class should be applied.
- Ensure that CKEditor 5 / CKEditor is selected as the editor.
- In the Editor Plugins section, confirm that the Style plugin is enabled.
- Add your custom style definition under the Styles plugin configuration.
Example: `p.glossary-exclude|Exclude from glossary`
## Maintainers
......
......@@ -130,7 +130,7 @@ abstract class GlossifyBase extends FilterBase implements ContainerFactoryPlugin
ksort($pattern_parts);
// Process HTML.
$text_nodes = $xpath->query('//text()[not(ancestor::a) and not(ancestor::span[@class="glossify-exclude"])]');
$text_nodes = $xpath->query('//text()[not(ancestor::a) and not(ancestor::*[contains(concat(" ",normalize-space(@class)," ")," glossify-exclude ")])]');
foreach ($text_nodes as $original_node) {
$text = $original_node->nodeValue;
if (empty(trim($text))) {
......
......@@ -269,6 +269,47 @@ class GlossifyBaseTest extends UnitTestCase {
'urlpattern' => '/random/testpattern',
'output' => '<p>Simple HTML with<b> <a href="/random/testpattern" title="' . $term->tip . '">RT</a></b> and rt as replacement term</p>',
],
// Glossify-exclude class prevents term to be "glossified"
'set18' => [
'text' => 'Simple plain text with <span class="glossify-exclude">RT</span> as replacement term that is excluded from glossify',
'terms' => [$term->name_norm => $term],
'case_sensitivity' => TRUE,
'first_only' => FALSE,
'displaytype' => 'tooltips',
'tooltip_truncate' => FALSE,
'urlpattern' => '',
'output' => 'Simple plain text with <span class="glossify-exclude">RT</span> as replacement term that is excluded from glossify',
],
'set19' => [
'text' => '<p class="glossify-exclude">Simple plain text with RT as replacement term that is excluded from glossify.</p>',
'terms' => [$term->name_norm => $term],
'case_sensitivity' => TRUE,
'first_only' => FALSE,
'displaytype' => 'tooltips',
'tooltip_truncate' => FALSE,
'urlpattern' => '',
'output' => '<p class="glossify-exclude">Simple plain text with RT as replacement term that is excluded from glossify.</p>',
],
'set20' => [
'text' => 'Simple plain text with wrapped by an element containing not only glossify-exclude class <span class="foo glossify-exclude bar">RT</span> as replacement term that is excluded from glossify.',
'terms' => [$term->name_norm => $term],
'case_sensitivity' => TRUE,
'first_only' => FALSE,
'displaytype' => 'tooltips',
'tooltip_truncate' => FALSE,
'urlpattern' => '',
'output' => 'Simple plain text with wrapped by an element containing not only glossify-exclude class <span class="foo glossify-exclude bar">RT</span> as replacement term that is excluded from glossify.',
],
'set21' => [
'text' => '<div class="glossify-exclude"><p>Nested HTML block with text with <span>RT</span> as replacement term that is excluded from glossify.</p></div>',
'terms' => [$term->name_norm => $term],
'case_sensitivity' => TRUE,
'first_only' => FALSE,
'displaytype' => 'tooltips',
'tooltip_truncate' => FALSE,
'urlpattern' => '',
'output' => '<div class="glossify-exclude"><p>Nested HTML block with text with <span>RT</span> as replacement term that is excluded from glossify.</p></div>',
],
];
// cSpell:enable.
return $data;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment