Skip to content

Analyze a Markdown file for Image URLs, download these files and generate a new markdown with the downloaded files.

License

Notifications You must be signed in to change notification settings

ludos1978/Markdown_MakeLocal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Markdown_MakeLocal

Analyze a Markdown file for Image URLs, download these files and generate a new markdown with the downloaded files.

Has only been tested on OSX!

Usage

call the script with markdown file as parameter and optionally a folder (-m) where to save the Media will keep only images that are downloaded and generates a new markdown file with replaced links

python3 mdMakelocal.py file.md [file2.md ..] [-m Folder]

Requirements

  • python3

with the libraries

  • requests
  • glob
  • uuid
  • hashlib
  • markdown
  • mimetypes
  • threading
  • lxml
  • urllib

Things Considered in Development

  • If the filename already exists in the media folder, it will append the files md5 hash to the filename
  • The original markdown file will no be modified, only a new one generated with the appendix '-localMedia-X' where X is a number increased when a file already exists with that name.
  • Downloads are threaded
  • Image Filename and extension is generated from (in the following order)
    • html header 'content-disposition'
    • filename and html header 'content-type'
    • filename itself

Known Problems / Kwirks

  • All links are downloaded, only afterwards the mimetype is detected. Then the file will be deleted if it's not matching a image type.
  • the generated filename could be to long for the filesystem.
  • Markdown file is converted to html to check for links, maybe would be nicer with regex?

Example Links to Images

Image links from w3.org to test the script on this file

BMP

GIF

JPG

PNG

About

Analyze a Markdown file for Image URLs, download these files and generate a new markdown with the downloaded files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages