Code Monkey home page Code Monkey logo

md-imglocalize's Introduction

Markdown-ImageLocalize

中文README

This code is adapted from Img_link_to_local_markdown

This is a python script that scans all the markdown files of a folder looking for images links, and substitutes the urls of the markdown files for local file names, and download the images.

Why?🛠️

Offline markdown files are a reliable way to store and organize information. When copying from the web the text is copied directly, but images are copied as links. If the link expires in the future, or you are offline, you lose the information. It would be great to have every picture added as a link downloaded to local storage.

Features⭐

  • Support both <img> and ![]() labels.

  • Add more options to custom the behaviors(e.g. whether to modify source markdown files).

  • Download images in Async mode, which performs well to decrease exec time:

    vanilla code async code
    28.420s 5.236s
  • Support loop traversal of markdown files.

  • Save the link between the images and the urls, which enables user and this program to re-download failed images.

  • Convert all absolute paths to relative paths.

  • Support for custom addition of test cases to verify if markdown files can be correctly converted.

Usage🚀

  1. Install Python on your computer.
  2. Clone this Repo git clone https://github.com/YellowAndGreen/Md-ImgLocalize.git.
  3. Install aiohttp pip install -r requirements.txt .
  4. Change to the Repo's directory
  5. Run python main.py --md_path=[md_path] in command line:
    • specify --md_path as your markdown files directory
    • use --log to save the complete log file, NOTE: using --log leads to no output on the screen
    • use --modify_source to modify source markdown files directly, this option create image folders under markdown file directory
    • use --coroutine_num to specify the number of coroutines, set to 1 if async feature is not needed.
    • use --del_dict to delete saved all_img_dict.json file.
    • use --relative to convert all absolute paths to relative paths, this option will not download images.
  6. To use the Test feature, you need to run python main.py --test. All test cases are saved in the test_case folder. To add a single image test case, please directly modify the test_single/test_single.md file. To add an entire test folder, please add it to the test_folder.

TODO📃

  • Async function
  • Loop traverse
  • Re-download
  • Delete the auto-generated dict file
  • Convert absolute path to relative path
  • Test cases
  • Add github actions
  • Add web support

Feel free to submit a Pull Request or Issues😃!

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.