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

Add embed functionality .. #17

Closed
skx opened this issue Jun 29, 2020 · 2 comments · Fixed by #18
Closed

Add embed functionality .. #17

skx opened this issue Jun 29, 2020 · 2 comments · Fixed by #18
Assignees

Comments

@skx
Copy link
Owner

skx commented Jun 29, 2020

I recently came across this tool:

It allows you to embed code-samples in markdown files, though it must be said it is very flexible and basically you give it an input-file which contains:

MARKER  file|URL start-regexp end-regexp

The line will be replaced by content from the file-path, or the remote URL, between the start/end regexps. Pretty trivial to write this in perl, via the flip-flop operator:

That said it would be a nice addition here.

Something like:

sysbox embed file1.md > file1.out

The biggest, obvious, issue is that if you were to replace in-place, you'd lose the marker(s). So this example:

Hello I am header.

#marker: /etc/passwd /root/ /\n/

Could become:

Hello I am header

root:x:0:0:root:/root:/bin/bash

But then you're stuck! You can't replace the content again, because the edited-in-place file no longer has the marker. You probably don't want that marker inline anyway. Though you could have something like:

<div class="include" start="^root" end="\n" />

Which could remain. But that's getting a bit markdown-specific. I guess the real solution is that your repository would have README.in (master-source) and README.md (generated/expanded output).

@skx skx self-assigned this Jun 29, 2020
@skx
Copy link
Owner Author

skx commented Jun 29, 2020

Upon reflection this is overkill. It seems that what I really want is:

  • Expand "template" with some magic behaviours.
    • Include a file (complete file)
    • Include lines matching a pattern (grep).
    • Include lines between two regexps.

We already have env-template. How about this:

Hello {{env "USER"}}!

Grep match:

{{grep "/etc/hosts" "\\.vpn"}}

File inline:

{{include "/etc/issue"}}

Between:
{{between "main.go" "func main" "^}"}}

Just an import?

{{between "main.go" "^import" "^\\)"}}

Your $PATH variable has {{len (split (env "PATH") ":")}} entries.

Implement those primitives and it'll work as-is...

@skx
Copy link
Owner Author

skx commented Jun 29, 2020

(Only obvious issue here is what if we want the lines between two regexps - but not including them. Duplication?)

skx added a commit that referenced this issue Jun 29, 2020
This allows three forms of file-inclusion:

* Literal/Complete file inclusion.
* Include lines from a file that match a regexp.
* Include lines between two regular expressions.

This closes #17
@skx skx mentioned this issue Jun 29, 2020
@skx skx closed this as completed in #18 Jun 29, 2020
skx added a commit that referenced this issue Jun 29, 2020
* Added support for file-inclusion.

This allows three forms of file-inclusion (where "file" means either reading a file from the local filesystem, or reading the output of executing a command):

* Literal/Complete file inclusion.
* Include lines from a file that match a regexp.
* Include lines between two regular expressions.

This closes #17
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

Successfully merging a pull request may close this issue.

1 participant