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

Present doc files with text inclusions sensibly in GitHub code browser #460

Open
gwhitney opened this issue Oct 9, 2024 · 1 comment
Open

Comments

@gwhitney
Copy link
Collaborator

gwhitney commented Oct 9, 2024

Currently, if you visit a documentation file (that has MkDocs inclusion syntax) in the GitHub code browser, the ordinary markdown parts look fine but the inclusion syntax produces unintelligible hieroglyphics (see the attached screenshot for an example). It would be better if in the GitHub code browser, the rendered markdown showed a link to the included content rather than this gibberish (I don't think there's any way to get GitHub to run MkDocs on the fly!).

Screenshot_2024-10-08_20-43-39

@gwhitney
Copy link
Collaborator Author

gwhitney commented Oct 9, 2024

The proposed way to implement this is as follows, using the file that produced the above screenshot as a running example:

  1. Start from the current inclusion syntax:
{! ../package.json extract: {start: 'scripts', stop: '},', replace: [
    ['help:(.*\D)".*".*echo (.*)"', '### npm run \1\n\2'], # 1-liner help
    '"help:.*[-:]\d*".*echo \\?"?(.*?)\\?"?"', # a continuation line of help
    ['"help:(.*\D)":.*"', '### npm run \1\n'], # header of block of help lines
    '.' # ignore the actual scripts that don't start with help
]} !}
  1. Enclose it in special markdown comment delimiters so that it will not show up in the GitHub rendering:
<!-- md-inclusion
{! ../package.json extract: {start: 'scripts', stop: '},', replace: [
    ['help:(.*\D)".*".*echo (.*)"', '### npm run \1\n\2'], # 1-liner help
    '"help:.*[-:]\d*".*echo \\?"?(.*?)\\?"?"', # a continuation line of help
    ['"help:(.*\D)":.*"', '### npm run \1\n'], # header of block of help lines
    '.' # ignore the actual scripts that don't start with help
]} !}
-->
  1. Add a link to the extracted code before this, bracketed by special markdown comments:
<!-- for-github -->
You can see the available scripts in [package.json](https://github.com/numberscope/frontscope/blob/main/package.json#L8-L82).
<!-- end-github -->
<!-- md-inclusion
{! ../package.json extract: {start: 'scripts', stop: '},', replace: [
    ['help:(.*\D)".*".*echo (.*)"', '### npm run \1\n\2'], # 1-liner help
    '"help:.*[-:]\d*".*echo \\?"?(.*?)\\?"?"', # a continuation line of help
    ['"help:(.*\D)":.*"', '### npm run \1\n'], # header of block of help lines
    '.' # ignore the actual scripts that don't start with help
]} !}
md -->
  1. Modify the filtering parameters in mkdocs.yml to remove anything between <!-- for-github --> and <!-- end-github --> comments, and to remove comment starters that match <!-- md-inclusion and comment closers that match md -->. (Details left to the reader, but mkdocs semiliterate is definitely powerful enough to do this, with the correct stop and start patterns, I think in the extract_standard_markdown parameter block.)

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

No branches or pull requests

1 participant