KevinBatdorf / code-block-pro

A Gutenberg code block with syntax highlighting powered by VS Code
https://code-block-pro.com
125 stars 9 forks source link

[Feature Request] Ability to link code from GitHub repositories & gists #246

Open iPwnPancakes opened 10 months ago

iPwnPancakes commented 10 months ago

Firstly, I'd like to thank the authors for making such an awesome plugin! This thing makes my code examples beautiful!

It would be really nice to be able to link the source from a public GitHub repo/gist!

Some examples of some links I would put in (ideally):

Raw code: https://raw.githubusercontent.com/iPwnPancakes/simple-byte-interpreter/main/tests/ByteInterpreterTest.php

Simple Repo: https://github.com/iPwnPancakes/simple-byte-interpreter/blob/main/tests/ByteInterpreterTest.php

Repo with line highlight: https://github.com/iPwnPancakes/simple-byte-interpreter/blob/main/tests/ByteInterpreterTest.php#L19-L27

Repo with line & column highlight: https://github.com/iPwnPancakes/simple-byte-interpreter/blob/main/tests/ByteInterpreterTest.php#L38C9-L38C22

iPwnPancakes commented 10 months ago

I've been exploring this idea and I see an issue around when exactly the code is fetched.

The options from what I can see:

I am a bit of a WordPress noob, so apologies if my ramblings are misguided

KevinBatdorf commented 10 months ago

Hey, I meant to reply earlier but I've been afk and playing catch up.

Do you mean syncing from within the editor? That I think I can do. You'd have to go edit the page though for it to stay in sync as I couldn't fetch and process it in the background.

But if from the frontend then it's not practical because I'd have to load a bunch of additional assets and it would be a bunch of work. Might be interesting as a new plugin though. I'll look into that.

iPwnPancakes commented 10 months ago

All good! And yes, I believe syncing from the editor is the most feasible way to go about it.

This might be a strange request, but may I take this one on? Been wanting to contribute to open source more and this would be an awesome opportunity :smile:

KevinBatdorf commented 10 months ago

yeah definitely. I can help out too if you get stuck with the WordPress stuff, and will review the code, etc too of course. Do you want to talk about the plan first before you start on it? Are you thinking just allowing the user to add a URL directly linking to the somewhere?

iPwnPancakes commented 10 months ago

Are you thinking just allowing the user to add a URL directly linking to the somewhere?

Yep! Exactly that. I set up a dev wordpress env using Local and found out how to add Gutenberg sections in the sidebar. Found out about how Gutenberg works a bit more.

I think the initial plan is to try and see if I do some initial validation on the frontend on typescript side. When it comes to actually fetching the content from the URL, I think my initial plan is to create a specific route on the CBPRouter that fetches the content, validates MIME types (probably enforcing text/plain), and returns the text after it's been validated on the backend.

What do you think? Is that on the right track? Or is it overkill?

KevinBatdorf commented 10 months ago

Came to check on this and saw my last reply didn't go through. Sorry for that.

Your plan sounds ok. Alternatively I guess it could connect to their gists via the github api. That might be overkill though...