New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for additional geshi options using an extendable options array (PR-2). #1985
Conversation
@LarsGit223, thanks for your PR! By analyzing the history of the files in this pull request, we identified @splitbrain, @andyboeh and @Chris--S to be potential reviewers. |
@splitbrain: maybe you also want to merge this. We've already worked on that some time ago (also see the changes/work done in #1625). |
@splitbrain: little reminder ping. It would be cool if this could become part of the next release if it's acceptable/planned to add it. Just want to make sure it's not forgotten maybe. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@micgro42 what do you think?
inc/parser/handler.php
Outdated
protected function parse_highlight_options ($options) { | ||
$result = array(); | ||
preg_match_all('/(\w+(?:="[^"]*"))|(\w+[^=,\]])(?:,*)/', $options, $matches, PREG_SET_ORDER); | ||
foreach ($matches as $match) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this parser needed? At first glance the syntax looks like json. What about using the json parser?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. It never occured to me that this is basically JSON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the consensus here? Do we keep the parser or do we swap to JSON (means a change is requested)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to replace this by json_decode()
it makes the code less complex and easier to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
For normal applications of code blocks, I guess that most users will experience this syntax as quite complex. Therefore I recommend to describe these options only at a separate wikipage (and not as addition on the syntax wikipage). Such that an unexperienced user is not overwhelmed by details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@micgro42: true, but it's OK if you use highlight and line numbers together: As this seems to be a Geshi issue what can we do about it? Which version of Geshi does DokuWiki run? |
It's still there in the latest version and has already been reported some time ago, see https://sourceforge.net/p/geshi/bugs/190/. |
we're using https://github.com/GeSHi/geshi-1.0 |
I submitted GeSHi/geshi-1.0#104 to address this. |
Below some examples with the new JSON encoding:
|
You're gonna hate me… but now that I actually see the syntax in JSON I do not really like it 😞 Sorry, I should have actually thought this through. My fault. I'll clean this up and merge. Thank you @LarsGit223 |
@splitbrain: never mind. |
Closed in favor of #2307. |
Also see the feature request in issue #1625.
I extended the syntax for the
code
andfile
tags in the following way:The actually implemented additional options are named after their corresponding Geshi functions:
Here are some syntax examples:
Example 1, normal code tag, unchanged behaviour:
Example 2, enable line numbers:
Example 3, highlight a specific line:
Example 4, start at specific line number (requires two options):
Example 5, highlight specific lines:
Implementation details:
In function
code
in filehandler.php
options get cut off the match and are parsed in functionparse_highlight_options
. The function searches forkey=value
pairs separated by commas. Each found pair is added to the options array like$options[$key] = $value;
.The options array is passed through as a additional parameter in functions
code
,file
and_highlight
in filexhtml.php
. And finally its passed top_xhtml_cached_geshi
which calls the corresponding functions.