Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
highlightjs_input_filter
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
highlightjs_input_filter
Commits
c7eda751
Commit
c7eda751
authored
9 months ago
by
Kent Richards
Committed by
Nicholas Mangold
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3453745
by kentr: Filter has false positives
parent
fa82268b
No related branches found
No related tags found
1 merge request
!14
Issue #3453745: Fix filter false positives
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/highlightjs_input_filter.js
+2
-1
2 additions, 1 deletion
js/highlightjs_input_filter.js
src/Plugin/Filter/HighlightJs.php
+14
-12
14 additions, 12 deletions
src/Plugin/Filter/HighlightJs.php
with
16 additions
and
13 deletions
js/highlightjs_input_filter.js
+
2
−
1
View file @
c7eda751
...
...
@@ -9,7 +9,8 @@ import hljs from 'https://unpkg.com/@highlightjs/cdn-assets@11.8.0/es/core.min.j
const
initEvent
=
new
Event
(
"
highlightjs:init
"
);
const
promises
=
Object
.
values
(
languages
).
map
(
language
=>
{
return
import
(
`https://unpkg.com/@highlightjs/cdn-assets@11.8.0/es/languages/
${
language
}
.min.js`
)
.
then
(
module
=>
hljs
.
registerLanguage
(
language
,
module
.
default
));
.
then
(
module
=>
hljs
.
registerLanguage
(
language
,
module
.
default
))
.
catch
(
e
=>
console
.
error
(
`
${
e
.
name
}
:
${
e
.
message
}
`
));
});
if
(
drupalSettings
.
enableCopyButton
==
true
)
{
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/Filter/HighlightJs.php
+
14
−
12
View file @
c7eda751
...
...
@@ -23,21 +23,23 @@ class HighlightJs extends FilterBase {
public
function
process
(
$text
,
$langcode
)
{
$enable_copy_button
=
\Drupal
::
config
(
'highlightjs_input_filter.settings'
)
->
get
(
'enable_copy_button'
);
$result
=
new
FilterProcessResult
(
$text
);
if
(
stristr
(
$text
,
'<code'
)
===
FALSE
||
stristr
(
$text
,
'language-'
)
===
FALSE
)
{
// Regex approximates the className regex in highlight.js itself,
// also matching the containing `<pre><code>` tags.
// Using a DOM parser as highlight.js does would probably be cleaner.
$pattern
=
'/<pre>\s*<code\s+class="\s*(?:[\w-]+\s+)?\b[\w-]*lang(?:uage)?-([\w-]+)\b/i'
;
// If no matches are found, return early.
if
(
!
preg_match_all
(
$pattern
,
$result
,
$matches
))
{
return
$result
;
}
$pattern
=
"/language-[^
\"
]+/i"
;
if
(
preg_match_all
(
$pattern
,
$result
,
$matches
))
{
foreach
(
$matches
as
$match
)
{
foreach
(
$match
as
$language_id
)
{
$language
=
str_replace
(
'language-'
,
''
,
$language_id
);
// Create a uniquely keyed array of languages so the
// BubbleableMetadata->mergeAttachments() method can properly
// merge the drupalSettings when adding attachments.
$languages
[
$language
]
=
$language
;
}
}
// If matches are found, process.
foreach
(
$matches
[
1
]
as
$language
)
{
// Create a uniquely keyed array of languages so the
// BubbleableMetadata->mergeAttachments() method can properly
// merge the drupalSettings when adding attachments.
$languages
[
$language
]
=
$language
;
}
$result
->
addCacheableDependency
(
$enable_copy_button
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment