Closed danielgafni closed 2 months ago
Hi!
Thanks for using tabi and for requesting this cool feature. I like the idea.
I've got a prototype shortcode which does exactly as you request.
Will update soon!
Amazing!
Thank you for writing Tabi :) I am really enjoying it.
Thank you! I'm glad to hear :)
The feature is added in #305.
It's almost exactly what you requested; to place the code in a code block, you need to add the backticks and language manually. This is necessary so that Zola can handle the syntax highlighting.
The docs should clarify the usage.
Let me know whether this works for your or if you encounter any issues!
Cheers
EDIT: Just realised I didn't add the "Show source" part. I'll think about how to implement this.
Thanks!
Yep, I was able to make something similar, but without the source reference, too.
I think it's an important part of this feature, it would be great if you could figure it out :)
Adding the source to the codeblock is easy enough with CSS. The challenge is making the URL clickable without JavaScript—I don't think it's possible.
Do you think this feature is important enough to warrant loading an extra (small) JS file?
Would it be enough to show the path/URL, even if it's not clickable?
I think we can start with just displaying it (can it have a copy button?) and add the other part later.
Honestly, my CSS/HTML/JS knowledge is close to zero, so I don't know what exactly has to be done to enable it.
Adding a "copy" option to the source would require JS too.
The thing is I'm not a big fan of JavaScript. The feature you are requesting is impossible to do without it, though, as we can't modify the HTML of codeblocks; Zola auto-renders them.
That's why I was asking how important the feature was. It's a simple enough change, so I'll add it soon.
Turns out it's not as easy.
The only solution I see right now is to create another shortcode like add_src_to_codeblock
. This will take a single argument, the src
. Then a JavaScript file would match each src
added by the shortcode to the next codeblock it finds.
This means adding two shortcodes per codeblock with visible source, in the right order, with the same data. Plus, loading the JS file to handle the "joining" of data.
It works, though.
(The URL is clickable.)
I just need to write the docs.
Alright, great!
Do you think we should also have an option to override the displayed source path with something else?
For example, the desired file location could be displayed instead of the original source path, indicating that this code block contents should be placed in the desired path.
Do you think we should also have an option to override the displayed source path with something else?
The src
for the codeblock and the src
for the text (what's shown in the code block) are independent. So you would do:
{{ add_src_to_codeblock(src="https://example.com/whateverURL") }}
```.gitignore
{{ remote_text(src="https://example.com/the_actual_url.py") }}
It's done in #307.
Not a fan of the JavaScript + shortcode + shortcode setup, but it's the best we can do given the constraints.
Check out the documentation and give it a go! Let me know whether it works for you or if you encounter any issues.
Cheers
Thanks, looking great!
The only small issue I found is with formatting with a long url and a small screen.
Thanks for letting me know! Should be fixed with f081a92f5939e141b6dbd7afe8ad1a9519d47f30
Feature Request
Summary
I am writing a blog post which includes a lot of code blocks.
I would like to:
I tried searching for solutions, but was not able to find anything working.
Motivation
Such feature will allow to:
I believe this should be a very common problem for blog posts with heavy use of code.
Detailed Description
Perhaps, a
code_block_source
shortcode could be implemented, which could be used like this:This shortcode would fetch the
source
contents, render it with syntax highlighting, and add a clickablesource
reference to the code block (I believe it can be shown before thecopy
button, or after the language title).The
source
argument should accept both local paths and external URLs.