Skip to content

This is a single project where I will convert a markdown document into a PDF

Notifications You must be signed in to change notification settings

ramonmacias/markdown-to-pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Markdown to PDF

This is a single project that try to convert a markdown file into a PDF file using Go. To achieve this we have two different options:

The main differences between the two options, the second option you need to have internet acces due you need to send a request into a API, also this API is free to use but if you want to massive convert markdown files into pdf files you will need to pay for it. The first option is offline and use two packages based in Go, the main problem is that you need to code all the translation between both, is probably the best option to follow due that you will have the entire control of the each component of the translation flow, but you will need a lot more time to do it.

BE AWARE YOU CAN'T USE ANY OPTIONS FOR A PRODUCTION ENVIRONMENT

Code insights

The current Go status for packages that help to make this conversion is limited in Go, this is why I used a flexible structure using interfaces, on this way you can try to achieve a solution making combination between different markdown and pdf parsers, or even you can create you own parser. If you take a look inside the parser package you will see there the tests applied to both options, inside the testdata folder you have the markdowns files used for launch the tests and the results applying both options.

Also there is a main.go program that you can run, setup and environment and build your own pdf from you own markdow files

The first step is to download all the packages you will need to run

go get -u gopkg.in/russross/blackfriday.v2

go get -u github.com/gomarkdown/markdown

go get github.com/jung-kurt/gofpdf

After this you can run

go run main.go -h

And you will see a list of flags and their definitions

-input-file string
      Use this flag to setup an entry file name (default "README")
-output-file string
      Use this flag to setup an output file name (default "output")
-parser-provider string
      Define which markdown parser provider want to use (default "blackfriday")

So with this you can setup a input file name and a output file name (don't add the .md and .pdf the program will add it) and you can also select which option of parser provider want to use, the first option is named blackfriday and the second option is gomarkdown

So a sample of how you can run this program can be

go run main.go -input-file=README -output-file=output -parser-provider=gomarkdown  

TODO

This is a small project and part of a tech test, so there is still a lot of thinks to do

  • Add more unit testing
  • In both options there is a lot of things that don't work properly so need to be fixed
  • Explore new packages to use as a parsers
  • Use go modules as dependency system
  • Build my own markdown and pdf parser

About

This is a single project where I will convert a markdown document into a PDF

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages