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

Can I enable show line number for code? #471

Closed
sajjadintel opened this issue Jan 31, 2017 · 2 comments
Closed

Can I enable show line number for code? #471

sajjadintel opened this issue Jan 31, 2017 · 2 comments
Labels

Comments

@sajjadintel
Copy link

Dear,
Can I enable show line number for code?

@taufik-nurrohman
Copy link

taufik-nurrohman commented Jan 31, 2017

Not possible natively, but my extension has an option to capture the code block content from a function parameter, like this:

$parser->code_block_text = function($text) {
    return do_something($text);
};

Example:

function add_line_numbers($text) {
    $a = [];
    foreach (explode("\n", $text) as $k => $v) {
        $a[] = '<span data-i="' . ($k + 1) . '">' . $v . '</span>';
    }
    return implode("\n", $a);
}

$parser = new ParsedownExtraPlugin;
$parser->code_block_text = function($text) {
    return add_line_numbers($text);
};

echo '<style>pre [data-i]:before {content:attr(data-i) \' \'}</style>';
echo $parser->text('some content...');

@aidantwoods
Copy link
Collaborator

No plans currently to add this into Parsedown core, so using an extension as mentioned above is the way to go :)

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

No branches or pull requests

3 participants