Giter VIP home page Giter VIP logo

markdown-embed-code's Introduction

markdown-embed-code

Embedding code into markdown from external file. Any language's code blocks are available.

See demo repo if you are interested in testing code within README.

How to use

In markdown, write code block as follows:

```python:tests/src/sample.py

```

And, you can refer specific lines as
```python:tests/src/sample.py [4-5]
 
```

Then, this action referes to tests/src/sample.py and modifies markdown as (if something code is written, they are overridden):

from math import sqrt


def sample(x):
    return sqrt(x)

And, specific lines is refered as

def sample(x):
    return sqrt(x)

NOTE: Read file by passed path, where the top directory in your repo is working directory. If the path is wrong, this action is failed.

How to use - workflow example

Override README.md and push by action if readme is changed:

name: Embed code in README

on:
  pull_request:
    branches:
      - main

jobs:
  embed-code:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
          fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
          ref: refs/heads/${{ github.head_ref }}

      - uses: tokusumi/markdown-embed-code@main
        with:
          markdown: "README.md"
          token: ${{ secrets.GITHUB_TOKEN }}
          message: "synchronizing Readme"
          silent: true

Configuration

input description
token Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}
markdown (Optional) Target markdown file path. (default: "README.md")
message (Optional) Commit message for action. (default: "Embedding code into Markdown")
no_change (Optional) Issue comment at no changed (default: "No changes on README!" )
output (Optional) Output markdown file path. If none, override target file. (default: "")
silent (Optional) No issue comment in silent mode (default: false)

markdown-embed-code's People

Contributors

actions-user avatar alexandroperez avatar tokusumi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

markdown-embed-code's Issues

support line number embed

a file

1 function a(){}
2 function a(){}
3 function a(){}
4 function a(){}
5 function a(){}

b.md

//```ts:a.ts 2:4
//```

render
b.md

2 function a(){}
3 function a(){}
4 function a(){}

Are non-README files supported?

I am trying (and failing!) to use this action to embed unit test code in some tutorials.

Here is my .github/workflows/github-pages.yml :

name: Build and deploy Jekyll site to GitHub Pages

on:
  push:
    branches:
      - develop # or main after October 2020
  schedule:
    - cron: "0 0 * * *" # build daily at midnight

jobs:
  github-pages:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        #persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
        #fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
        #ref: refs/heads/${{ github.head_ref }}

      - name: Download Quetzal-CoalTL
        run: git clone https://github.com/Becheler/quetzal-CoalTL.git

      - uses: tokusumi/markdown-embed-code@main
        with:
          markdown: "/my_collections/_quetzal-coaltl-tutorials/a-random-walker.md"
          token: ${{ secrets.GITHUB_TOKEN }}
          message: "synchronizing tutorial"

      - uses: helaili/jekyll-action@v2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

The file supposed to be embedded is:

\```cpp:quetzal-CoalTL/test/tutorials_test/tuto_1.cpp
// file main.cpp
\```

But I get this error message:

Run tokusumi/markdown-embed-code@main
  with:
    markdown: /my_collections/_quetzal-coaltl-tutorials/a-random-walker.md
    token: ***
    message: synchronizing tutorial
    no_change: No changes on README!
    silent: false
/usr/bin/docker run --name a68250bbc294923d9454dab0a79e91ec99669_ccf440 --label 6a6825 --workdir /github/workspace --rm -e INPUT_MARKDOWN -e INPUT_TOKEN -e INPUT_MESSAGE -e INPUT_NO_CHANGE -e INPUT_OUTPUT -e INPUT_SILENT -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/Becheler.github.io/Becheler.github.io":"/github/workspace" 6a6825:0bbc294923d9454dab0a79e91ec99669

Despite numerous try and fail, I could not get it working. Any suggestion?

publish to pypi

this seems like a useful standalong utility. maybe publish to pypi?

Dockerfile error? Docker build failed with exit code 1

I'm using your Github Action via the Marketplace and have configured the options for the step.
Copied the step definition directly from Marketplace search result & modified. ✔️
Github's UI validated that the yml indentation was correct. ✔️
c.f. https://github.com/aclairefication/oss-storytelling/blob/main/.github/workflows/update_story_archetype.yml#L16

I created a pull request & merged it to main, which kicked off the workflow.
The first run was not successful, ending with Docker build failed
c.f. https://github.com/aclairefication/oss-storytelling/runs/7051828039?check_suite_focus=true#step:2:595
Relevant lines:
1st try:

  Building wheels for collected packages: cffi
    Building wheel for cffi (setup.py): started
    Building wheel for cffi (setup.py): finished with status 'error'
    error: subprocess-exited-with-error
  
    × python setup.py bdist_wheel did not run successfully.
    │ exit code: 1
    ╰─> [48 lines of output]
        unable to execute 'gcc': No such file or directory
        unable to execute 'gcc': No such file or directory

    note: This error originates from a subprocess, and is likely not a problem with pip.
    ERROR: Failed building wheel for cffi

    Running setup.py install for cffi: finished with status 'error'
    error: subprocess-exited-with-error

    note: This error originates from a subprocess, and is likely not a problem with pip.
  error: legacy-install-failure
  
  × Encountered error while trying to install package.
  ╰─> cffi

  Warning: Docker build failed with exit code 1, back off 5.586 seconds before retry.

  Building wheels for collected packages: cffi
    Building wheel for cffi (setup.py): started
    Building wheel for cffi (setup.py): finished with status 'error'
    error: subprocess-exited-with-error

2nd try: same result and it gave up...

    Error: Docker build failed with exit code 1

Q: is there an issue in this repo's Dockerfile for v1.0.0 that builds the Gtihub-hosted runner?
Pinned this version, as suggested by the Marketplace step definition: https://github.com/tokusumi/markdown-embed-code/releases/tag/v1.0.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.