Skip to content
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

Subclass of MardownExtra added with Geshi support (syntax highlighting) #199

Closed
wants to merge 1 commit into from

Conversation

mariokonrad
Copy link
Contributor

Hello there!

I have implemented a class MarkdownExtraGeshi (subclass of MarkdownExtra) with basic Geshi support (code syntax highlighing).

It is able to do syntax highlighting for code snippets like this:

int main(int, char **)
{
  // some code
}

with a twist: you can select the starting line number of the code, example:

std::string s = "Hello World!";
std::cout << s << "\n";

Of course, Geshi is needed for this to work, so an additional external dependency. But only for the new class.

Are you interested in a patch like this?

Best regards
Mario

@michelf
Copy link
Owner

michelf commented Apr 14, 2015

It's hard to understand what you mean since Github parsed your code block markers. You should probably indent them with four spaces so the markers appear on Github.

One question, regarding the cpp:44 syntax for line numbers, where does it come from?

@mariokonrad
Copy link
Contributor Author

Sorry, didn't think about GitHub eating my examples. New try, normal code block (the same way GitHub parses and highlights code as it seems):

~~~ cpp
int main(int, char **)
{
    // some code
}
~~~

and with a starting line number:

~~~ cpp:44
std::string s = "Hello World!";
std::cout << s << "\n";
~~~

The notation "cpp:44" is not derived from GitHubs or Geshis behaviour, it seemed familiar, like error messages from gcc, breakpoint commands from gdb...

@michelf
Copy link
Owner

michelf commented Apr 16, 2015

I don't like that dependency, and I don't like that it has to be a separate class. I would propose this instead: what if there was a configuration variable in the parser letting you specify a filter function for code blocks? Something similar to url_filter_func or header_id_func. Then you could use Geshi this way:

$parser = new \Michelf\MarkdownExtra();
$parser->code_block_content_func = function($code, $lang) {
    $geshi = new \Geshi($code, $lang);
    $codeblock = $geshi->parse_code();
};
$html = $parser->transform($text);

As for the line number, I'm not sure I want to have this in MarkdownExtra. But if you want to add : to the characters allowed in the language name, I think that would be fine. You could then split and handle it in your custom function.

What do you think?

@mariokonrad
Copy link
Contributor Author

I agree, the additional dependency is not handy, especially because Geshi could be installed anywhere and tinkering with include paths is a mess. Actually (after a second check) the ':' is already allowed in the classname, which makes it even easier.
I have already a working version with your proposal in my forked repo, branch: code_block_content_func. Probably it is easier to just close this pull request and I open another one.

Thanks!

@mariokonrad
Copy link
Contributor Author

Replaced with pull request #200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants