Skip to content

Parity with SyntaxHighlight extension - #7

Open
kuenzign wants to merge 6 commits into
Nicolas01:masterfrom
kuenzign:line-numbers-and-highlights
Open

Parity with SyntaxHighlight extension#7
kuenzign wants to merge 6 commits into
Nicolas01:masterfrom
kuenzign:line-numbers-and-highlights

Conversation

@kuenzign

@kuenzign kuenzign commented Jun 15, 2022

Copy link
Copy Markdown

This enables support for all the same features as the SyntaxHighlight extension. This fixes #3, fixes #4, fixes #5, fixes #6, and fixes #8.

@kuenzign

Copy link
Copy Markdown
Author

@Nicolas01 Have you had a chance to take a look at this? Having support for all the same features as the SyntaxHighlight extension would allow more wikis to migrate to this extension instead.

@Nicolas01

Copy link
Copy Markdown
Owner

@kuenzign Thanks for the good work.
I'm sorry, I haven't had time to look at it in detail yet, but I will this week.
I'll let you know.

@Nicolas01 Nicolas01 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work !
I might integrate part of your contribution outside of this PR process, let me know what you think of it.

}

$code = htmlspecialchars(trim($in));
$out = htmlspecialchars($out);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the strip markers replacement and the rtrim here:

Suggested change
$out = htmlspecialchars($out);
// Replace strip markers (For e.g. {{#tag:syntaxhighlight|<nowiki>...}})
$out = $parser->mStripState->unstripNoWiki( $in );
$out = htmlspecialchars( rtrim( $out ) );

Comment on lines +32 to +39

// Convert deprecated attributes
if (isset($param['enclose'])) {
if ($param['enclose'] === 'none') {
$param['inline'] = true;
}
unset($param['enclose']);
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mentioned, enclose is a deprecated attribute.
So it may not be a good idea to handle it anymore.

Suggested change
// Convert deprecated attributes
if (isset($param['enclose'])) {
if ($param['enclose'] === 'none') {
$param['inline'] = true;
}
unset($param['enclose']);
}

Comment on lines +29 to +31

// Don't trim leading spaces away, just the linefeeds
$out = preg_replace('/^\n+/', '', rtrim($out));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I would only do a rtrim and leave the first empty lines.
I would also move the rtrim to the line 67.

Suggested change
// Don't trim leading spaces away, just the linefeeds
$out = preg_replace('/^\n+/', '', rtrim($out));

Comment on lines +27 to +28
// Replace strip markers (For e.g. {{#tag:syntaxhighlight|<nowiki>...}})
$out = $parser->mStripState->unstripNoWiki($in);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the strip markers replacement to the line 67.

Suggested change
// Replace strip markers (For e.g. {{#tag:syntaxhighlight|<nowiki>...}})
$out = $parser->mStripState->unstripNoWiki($in);

Comment on lines +50 to +55
// Allow certain HTML attributes
$htmlAttribs = Sanitizer::validateAttributes(
$param,
array_flip(['line', 'start', 'highlight', 'style', 'class', 'id', 'dir'])
);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use array_flip?

// id
if (isset($param['id'])) {
$htmlAttribs['id'] = $param['id'];
if (!(isset($htmlAttribs['dir']) && $htmlAttribs['dir'] === 'rtl')) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to force the dir attribute to ltr?

Comment thread init.js
// load the highlight.min.js script this way to avoid Uncaught SyntaxError: unterminated regular expression literal
$.cachedScript('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/highlight.min.js')
.done(function (script, textStatus) {
$.cachedScript('https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js')

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my main concern about your PR:
Highlight.js doesn't manage line numbers to keep simple, and I have the same wish for this extension.
But as your already made the work, I would suggest you to create 2 separate PRs for this concern:

  • one for the line numbers
  • another one for the highlight of specific lines

@Nicolas01 Nicolas01 Aug 21, 2022

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I think you should create a separate extension for this.
highlightjs-line-numbers is a different projet than highlightjs so it makes sense for me to have separate extensions.

@Nicolas01
Nicolas01 force-pushed the master branch 2 times, most recently from bbb82b1 to 2519aec Compare April 8, 2023 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants