Hello,
is there a plugin in Grav, that can display a label (for example file name) above the code on the page?
Like this:
Thanks.
Z.
Hello,
is there a plugin in Grav, that can display a label (for example file name) above the code on the page?
Like this:
Thanks.
Z.
Really no one knows how to do it? It does not have to be exactly what I placed here, would be enough if it looks like this:
Iām not sure to understand what youāre looking for.
Could you maybe be more specific and explain with more details ?
Thank you, Iām looking for a way to display the code in āGravā with description.
I can insert the code, as follows:
#!/usr/bin/env python
#some code
but this show only code, I would like find a way for showing code with description for it. Just as in the picture.
I finally did it by changing the css:
.codehead {
font-family: Consolas;
text-indent: 6px;
color:#000000;
background:#888888;
border-top-left-radius:4px;
border-top-right-radius:4px;
padding: 2px 0px;
}
.codehead pre {
text-indent: 0px;
margin: 0 ;
}
and with html:
<div class="codehead">raw.py
<pre><code>#!/usr/bin/env python
print()
</code></pre></div>
How it looks like now:
But my question still remains, how to do it better with less work? I just imagine something like:
<code | raw.py>
#!/usr/bin/env python
print()
</code>
or something similar:
<code description="raw.py">
#!/usr/bin/env python
print()
</code>
Well, as it says, help yourself. I solve it by installing shortcode plugin with settings:
<?php
namespace Grav\Plugin\Shortcodes;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
class StrikeShortcode extends Shortcode
{
public function init()
{
$this->shortcode->getHandlers()->add('codehead', function(ShortcodeInterface $sc) {
$codehead = $sc->getParameter('codehead', $this->getBbCode($sc));
$buffer = $sc->getContent();
$buffer = preg_replace( "/(^\n|\n$)/", "", $buffer);
$str_before = array("<", ">", "<p>", "</p>");
$str_after = array("<", ">", "", "");
$buffer = str_replace($str_before, $str_after, $buffer);
return '<pre class="codehead">'.$codehead.'<code>'.$buffer.'</code></pre>';
});
}
}
And in default.md:
[codehead="/usr/local/bin/script.py"]
Heloo world!
[/codehead]
Itās not probably the purest solution, but works fine to me. Please, If anyone know about better way, let me know.
Thanks.
To paraphrase a proverb:
give a man a fish and you feed him for a day; let him find out himself how to fish and you feed him for a lifetime
You might want to pick your preferred solution and mark it as āsolutionā.