Render README Snippet from Relative Link

45 Views Asked by At

Background

I am creating the README.md for my GitHub repo ("MyRepo"), which provides certain VBA functionality. Here I wish to display a code snippet, which the user should paste into their own code.

Since this snippet enables the functionality, it is a crucial element of the project. As such, I maintain it modularly in src/Snippet.bas.

Goal

I am wish to combine the following features for the snippet in my README:

  1. The button 1 to copy the snippet with a single click.
  2. The scrollable pane, which keeps the README visually uncluttered by the large snippet. 2
  3. The injection of code from an upstream source file.
  4. The dynamic injection of the latest code from that file.
  5. The relative reference (src/Snippet.bas) to that file, rather than the unwieldy absolute (https://github.com/Greg/MyRepo/tree/HEAD/src/Snippet.bas).
  6. The inclusion of the entire file, rather than a fixed section of it (#L14-L22).

Issue

Unfortunately, (1) appears only for code samples written manually within ``` fences; and not for permalinks to the code. As for (2), it appears only for the permalinks; and not for the manually written samples.

While permalinks do achieve (3), they seem anchored to a specific commit, and thus fail at (4). Furthermore, it seems they require the absolute URL, and do not render the relative for (5). Finally, they are anchored rigidly lines (#L14-L22) within the file, and thus do not accommodate (6).

Question

Is there a way to achieve all (or more) of these features in GitHub Flavored Markdown, or in the HTML it permits? Or would this task require sophisticated GitHub Actions?

Alternatively, is there a URL parameter like copy, which automatically copies the linked file to the clipboard?

src/Snippet.bas?copy=1
0

There are 0 best solutions below