Skip to content

A treesitter based markdown synthesizer to yank code blocks from markdown

License

Notifications You must be signed in to change notification settings

rahlk/yank-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yank Code

A treesitter based markdown synthesizer to yank code blocks from markdown. It's designed to make it easy to pull out and use code snippets embedded in documentation and LLM generated markdown output.

Installation

You can install Yank-Code using pip:

pip install yank-code

Alternatively, you can install from source:

pip install git+https://github.com/rahlk/yank-code.git

Usage

Here's a simple example of how to use Yank-Code:

from yank_code import extract_code_blocks

markdown_content = """
    # Sample Markdown

    Here's a Python code block:

    ```python
    def hello_world():
        print("Hello, World!")
    ```

    And here's a JavaScript code block:


    ```javascript
    console.log("Hello, World!");
    ```
"""

code_blocks = extract_code_blocks(markdown_content)

for language, code in code_blocks:
    print(f"Language: {language}")
    print(code)
    print("---")

This will output:

Language: python
def hello_world():
    print("Hello, World!")
---
Language: javascript
console.log("Hello, World!")
---

Features

  • Extracts code blocks from Markdown text
  • Identifies the programming language of each code block (if specified)
  • Supports multiple code blocks in a single Markdown document

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A treesitter based markdown synthesizer to yank code blocks from markdown

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages