Code Monkey home page Code Monkey logo

md-to-pdf's People

Contributors

astery avatar ccarcaci avatar dependabot[bot] avatar dyllan-to-you avatar gjdonkers avatar jaknas avatar joemccann avatar lachlannewman avatar ltvolks avatar simonhaenisch avatar tomsvogel 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

md-to-pdf's Issues

SyntaxError in index.js

I'm having trouble trying to convert any document.

Everytime I get this exception:

error

This happens even if my cloned repo is clean.

CSS content urls are evaluated relative to the markdown file instead of the CSS file

One thing that I have noticed though is that there seems to be some inconsistency with the evaluation of the content url in the CSS file. If the below structure is used then these are the outcomes:

  • file.md
  • img/logo.svg
  • style/style.css
  • subFolder/otherFile.md

style/style.css includes:

.class::before {
  content: url("img/logo.svg");
}

This will evaluate fine for file.md but fail for otherFile.md. It seems that the content url is being evaluated relative to the .md file and not the .css file as it should be.

The css should be:

.class::before {
  content: url("../img/logo.svg");
}

This is because the content include should be relative to the location of the style.css file, meaning that the css could be applied to any file in any sub directory consistently.

Blank lines not keeped

Hi Simon!

Why blank lines (ie those only with carriage return & Lien Feed) are deleted during conversion ?

# Title One 
## Subtitle 

One sentence after blank line.


An another one sentence after 2 blank lines.

image
image

How to generate IDs without accentuated and special characters ?

Hi Simon !
How are you ?

Once again I ask for your help !

As you know, I'm using markdown-toc.
Links doesn't work for titles with accentuated characters (in html and pdf).
It's a well-known issue (jonschlinkert/markdown-toc#145).

Would it be possible for md-to-pdf to generate IDs without accentuated and special characters (in order to be homogenous with the slugify function used) ?

For instance, today we have this title in one markdown file :

Un titre de niveau H2 avec 2 caractères accentués
------------

Today, with md-to-pdf, the result in Html is :
<h2 id="un-titre-de-niveau-h2-avec-2-caractères-accentués">Un titre de niveau H2 avec 2 caractères accentués</h2>

I would like please :
<h2 id="un-titre-de-niveau-h2-avec-2-caracteres-accentues">Un titre de niveau H2 avec 2 caractères accentués</h2>
(or
<h2 id="un-titre-de-niveau-h2-avec-2-caract-res-accentu-s">Un titre de niveau H2 avec 2 caractères accentués</h2>
)

image

Thanks in advance!

Jean

Automatically Expand <details> Blocks

Wonderful project, thank you.

I'd like to request automatically expanding

blocks in markdown files. These are frequently used to expand/hide sections such as Tables of Contents.

Encoding error

Hi,
I'm having problems using "windows1252" as default markdown files encoding.

Whenever I use accented chars they became unknown chars when I try to convert the markdown file to pdf.

  • here's the screenshot of the editor and the preview:

test_1

  • and here a screen of the converted pdf:

test_3

Is there a way (maybe some css style file to edit) to change the output encoding so they match?

Border colours and fonts are applied inconsistently

So I've run into a bit of an issue I'm scratching my head over. Seems like it could be another race condition type thing.

Sometimes when I compile only some of the CSS rules are applied.

This is the expected output:
css-applied

This is what sometimes happens:
css-not-applied

There doesn't seem to be a consistent way of making this happen, though it does happen quite often.

Add TOC (Table Of Contents) feature

Add a --toc cli argument to Use a .toc class or <!-- TOC --> comment to enable a TOC generator and inject an auto-generated TOC into the html.

Programmatic API

To make the package easier to use as a dependency of other packages, a programmatic API would probably be helpful for some people. Should be a pretty straight-forward refactoring task.

Path to highlight.js css files is wrong

When installing md-to-pdf as a dev dependency in another project the path to the highlight.js css files will no longer be relative to /md-to-pdf/.

(node:52783) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/path/to/other-project/node_modules/md-to-pdf/node_modules/highlight.js/styles/monokai.css'
  -- ASYNC --
...

In other words the path:

/path/to/other-project/node_modules/md-to-pdf/node_modules/highlight.js/styles/monokai.css

should in this case be:

/path/to/other-project/node_modules/highlight.js/styles/monokai.css

Flaky image loading when using css content

I have a series of documents that we're using for our markdown documentation. Each of them has a title page with a header and footer, which I'm injecting in using the css content property to avoid duplication.

The header contains an image of our company logo, but I've been finding that when I compile the file, sometimes it doesn't load in, leaving just a blank space at the top.

&::before {
  content: url("img/logo.svg");
  display: block;
  height: 80px;
}

I can only assume that, as it works perfectly fine around half of the time, that there is some sort of race condition between loading the page in chromium headless and printing out to the pdf.

Stylesheet paths are not relative to the file they are in

Hi

The relative path changed... it used to consider the relative path from the execution path, now, it considers relative path from the MD file.

It used to work with:

  "stylesheet": [
    ".\\mystyle.css"
  ],

when executed from c:\RepoFolderRoot\

Error is:

 md2pdf --config-file .\generate_pdf\config.json ./doc1/doc1.md
  × generating PDF from ./doc1/doc1.md
    → ENOENT: no such file or directory, open 'c:\RepoFolderRoot\doc1\mystyle.css'

and now works with...

  "stylesheet": [
    "C:\\RepoFolderRoot\\generate_pdf\\mystyle.css"
  ],

It is not very convenient for me, as my stylesheet lifecyle is different from doc lifecycle, and I'm not the only one to use this repo (and of course, all of us do not have the same folder organisation....)

Originally posted by @nekloth in #19 (comment)

License?

I think you should choose a license for this repo/package!

bug: Anchor links doesn't work when it written by multibytes chars

Context:

  • version (md-to-pdf -v): 2.8.2
  • platform (Unix, macOS, Windows): Windows
  • node version: 8.11.3

Describe the bug:

Anchor links doesn't work.

I wrote following basic markdown and convert it to pdf.

- [Anchor1](#anchor1)
- [Anchor 2](#anchor-2)
- [アンカー3](#%E3%82%A2%E3%83%B3%E3%82%AB%E3%83%BC3)
- [アンカー 4](#%E3%82%A2%E3%83%B3%E3%82%AB%E3%83%BC-4)

# Anchor1
ASCII chars and no blank.

# Anchor 2
ASCII chars and blank.

# アンカー3
Japanese chars and no blank.

# アンカー 4
Japanese chars and blank.

Anchor1 and Anchor 2 works well as I expected, but アンカー3 and アンカー 4 doesn't convert as link.

When I hover the cursor on アンカー3 and アンカー 4 in the output PDF, the cursor doesn't change as finger pointer.
But when I output html with --as-html option, the links works fine. <a>tag is perfectly works in Chrome browser.

Please give me any advise for this problem.

Thanks.

example for js config file

Can you please add an example of a js config file in the readme. I tried to export a default object and had no luck.

Add front-matter parser

Add a front-matter parser to allow configuration from within the markdown file.

Benefits:

  • overwrite some settings only for a certain document
  • settings can be saved together with the source document, so it's easy to re-create the PDF from source without needing to remember cli arguments or having to add a config file

throw new errors.AssertionError

Hi guys, Im getting this error when trying to convert my .md to .pdf with md-to-pdf README.md command. How can I fix this

assert.js:42
throw new errors.AssertionError({

AssertionError [ERR_ASSERTION]: html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath'
at new PDF (/Users/ymushet/md-to-pdf/node_modules/html-pdf/lib/pdf.js:38:3)
at Object.createPdf [as create] (/Users/ymushet/md-to-pdf/node_modules/html-pdf/lib/index.js:10:14)
at Object. (/Users/ymushet/md-to-pdf/index.js:80:10)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)

Installation and usage issue

Hello

I'm must be idiot or cursed, but either standard installation and usage does not work... :-/

I'm truing to use md-to-pdf on a Windows 7 and the Ubuntu subsystem of Windows

Installation issue

Following the procedure, on both Windows and subsys Ubuntu, I used the command line npm i -g in the github-cloned folder.

Everything went well.

Then, typed md-to-pdf readme.md and got a:
md-to-pdf: command not found for both systems.

Usage issue

So, I used node c:\temp\md-to-pdf\index.js readme.md (Windows 7) or node /mnt/c/temp/md-to-pdf/index.js readme.md (Ubuntu subsytem) and then, I got (for both):
{ AssertionError [ERR_ASSERTION]: html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath'

PhantomJs issue

THEN, I tried to install PhantomJS on both system using npm install -g [email protected] ... and got the same error for both:

Phantom installation failed { Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1526975751906/phantomjs-2.1.1-linux-x86_64' -> '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom'
  errno: -13,
  code: 'EACCES',
  syscall: 'link',
  path: '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1526975751906/phantomjs-2.1.1-linux-x86_64',
  dest: '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom' } Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1526975751906/phantomjs-2.1.1-linux-x86_64' -> '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

May you have an suggestion?

feature request: watch with devtools (aka "hot reload")

Context:

  • version (md-to-pdf -v): 2.8.2
  • platform (Unix, macOS, Windows): Windows
  • node version: 10.15.3

Describe the bug:

I'd like to run watch mode with devtools to be able to see the render in Chrome in live but it does not work --> Changes are not displayed

Add tests

There should be some tests for the stuff in the util folder.

Text copied from generated PDF is reversed

Original text from the markdown file:

This token must be used as the password portion of the HTTP basic authentication header.

Pasted text after copying it from the generated PDF:

.redaeh noitacitnehtua cisab PTTH eht fo noitrop drowssap eht sa desu eb tsum nekot sihT

md2pdf: 2.6.2
Platform: macOS 10.14.4
node: 10.15.0

How to set a repeating background without margins

Problem:

Hey, I apologize if this is a dumb question, but I just can't seem to figure out how to create a repeating background on the pdfs generated using md-to-pdf. I'm wanting to create a parchment effect, instead of a white background on my pdf output. I've been playing around with something like this in my css for testing:

* {
  background: url(http://api.thumbr.it/whitenoise-361x370.png?background=ffffffff&noise=5c5c5c&density=13&opacity=62);
  background-repeat: repeat;
  background-position: center center;
}

I also have printBackground: true in my pdf options. The background will show up behind everything except the margin-ed areas:

Screen Shot 2019-08-16 at 4 06 59 PM

Any tips/ideas on how to get the background to cover all whitespace on the page?

generating PDF is failing with little clues

Context:

  • version (md-to-pdf -v): 2.8.2
  • platform (Unix, macOS, Windows): Debian 8.10
  • node version: v8.12.0

Describe the bug:

I'm just doing a basic test. I have installed the package:

npm i -g md-to-pdf

Next, I try to build the PDF for the basic test that comes with the github repository:

git clone https://github.com/simonhaenisch/md-to-pdf
md-to-pdf md-to-pdf/test/basic/test.md 

but I get the following error:

  ✖ generating PDF from md-to-pdf/test/basic/test.md
    → TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md

However, it's a bit cryptic... I'm not sure which particular error md-to-pdf has found with regards to puppeter or how to debug it. In addition, the cited reference is pretty long, describing diferent kind of problems and not sure which one is the one I could have.

Any help or insight on this would be appreciated. Thanks!

bug: spawn EPERM

Context:

  • version (md-to-pdf -v): 2.8.2
  • platform (Unix, macOS, Windows): Windows
  • node version: 10.15.3

Describe the bug:

After executing the command md-to-pdf docs/README.md docs/output.pdf, I get the output:

× generating PDF from docs/README.md
→ spawn EPERM

Thanks for your help,

bug: not all css applied (background-color)

I'm trying to generate a pdf using the config file, with a css file, but not all CSS is applied. It does not generate an error on the config.

  • version (md-to-pdf -v): 2.7.1
  • platform (Unix, macOS, Windows): windows
  • node version: v8.12.0

When I generate a pdf using config, which contains header and footer content and a css file, the generated pdf does not have all css applied. Below I have applied 2 screenshots; one containing how it should look (this does not use a config file, using a css file), and one how it looks with the config file, using a css file.

My config file looks like this:

{
"pdf_options": {
"format": "A4",
"margin": "20mm",
"displayHeaderFooter": false
},
"stylesheet": "style.css"
}

Any idea why the css is not applied as I want it to?

case1
case2

Failed to generated PDF

Hi!
When doign md2pdf HowToMarkdown.md
I get and error when generating the PDF, I read the Troubleshooting link but I couldn't find what is cause
x generating PDF from HowToMarkdown.md → TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
I also get the same error when running md2pdf HowToMarkdown.md --config-file ./config.json
And the config looks like this

 {
  "stylesheet": [
    "https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css"
  ],
  "css": " .page-break { page-break-after: always; } .markdown-body { font-size: 11px; }",
  "body_class": "markdown-body",
  "highlight_style": "monokai",
  "marked_options": {
    "headerIds": false,
    "smartypants": true
  },
  "pdf_options": {
    "format": "A5",
    "margin": "20mm"
  },
  "stylesheet_encoding": "utf-8"
}

--config option does not accept relative path

Hello

I have a doc repo structure like:

RepoFolderRoot
├───doc1
│       doc1.md
│       doc1.pdf
│
├───doc2
│   │   doc2.md
│   │   doc2.pdf
│
├───generate_pdf
│   │   config.json
│   │   mystyle.css

I tried to launch the md2pdf command from the root folder (for scripting) by trying:
md2pdf --config-file .\generate-pdf\config.json .\doc1\doc1.md
or
md2pdf --config-file generate-pdf\config.json .\doc1\doc1.md
or
md2pdf --config-file \generate-pdf\config.json .\doc1\doc1.md

And I always got aWarning: couldn't read config file: \generate-pdf\config.json

Question : How to add TOC, Header and Footer ?

Hi Simon, Hi Jakub,

How are you ?
Thanks to your help last Week, now I am able to generate one pdf from one markdownfile! :-)

How to manage TOC, Header and Footer automatically for several markdown files please?
Each markdown file is a chapter of a help guide. I need to convert each md file in html and pdf.
I would like to keep the already specified style levels in order to automatically generate a table of contents and apply formatting with a CSS.

For instance, how is it possible to take in account the yaml file for pdf_options displayed in your main readme?
I have already looked at some issues in your website. Nevertheless, maybe do you have other examples which can help me?

Thanks in advance for your help.

Regards,

Jean

Watch mode

Could add a watch mode to watch the given markdown file and regenerate the PDF every time it changes. Might be useful when the preview is open next to the editor, like in the screenshot (not sure whether PDF viewers on system other than macOS refresh the preview though).

feature: Render Markdown with inline PlantUML

Problem:

It'd be very powerful if md-to-pdf can also render inline PlantUML diagrams when converting .md to .pdf

Solution:

Use a PlantUML parser to convert text within uml or plantuml code block to SVG image and render them along with the PDF:

```plantuml
@startuml
:Hello world;
:This is defined on
several **lines**;
@enduml

Table conversion problem from '.md' to '.pdf' formats

Hello @simonhaenisch ,
I am facing an issue.

The sample in markdown file is as follows: -

    ---
stylesheet: https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css
body_class: markdown-body
css: >-
  .markdown-body { font-size: 11px; }
  .markdown-body pre>code { white-space: pre-wrap; }
---

BJT | MOSFET
----|-------
Bipolar junction transitor | Metal Oxide Semiconductor <br/> Field effect transistor
3 terminal - C, B, E | 4 terminal - S, G, D, B(body/substrate)
for low current applicaions | high power applications
less commonly used in A & D circuits | most commonly used 
depends on current at base | depends on voltage at insulated oxide gate electrode
replaced the old vacuum tubes | voltage controlled device
cheap | costlier
conduction is due to majority & minority carriers | only due to majority carriers

Markdown preview

markdown preview

PDF preview

pdf preview

Problem statement

  • the table in pdf format doesn't look identical to the one of markdown img.
  • Is there any way to remove the css stylesheet entire statement (appearing along with the table) ?

Thanks,

Have a nice day :)

Footer/Header and images

I'm trying to include images in my header, using the option file. My config.json file looks like:

{
	"highlight_style": "monokai",
	"html_pdf_options": {
		"format": "A4",
		"border": "15mm",
		"header": {
			"height": "15mm",
			"contents": "<div style='width:100%;text-align: right; border-bottom: 1pt solid #eeeeee;'><font size='-1'>A <b>Team</b><em>A</em> document</font> <img style=\"vertical-align:middle;margin-right:10px;margin-left:10px;\" width=\"60px\" src=\"https://goo.gl/HkfCvS\"/> </div>"
		},
		"footer": {
			"height": "15mm",
			"contents": {
        "default": "<hr width='110%'><div style='float:right;'>Page {{page}}/{{pages}}</div>"
			}
		}
	}
}

As a result, I can see the picture location, but only white space instead of of picture...

Even if I remove any style option, the picture never displays.

Can we have conversion log (PhantomJS ?) ? That could help to understand the situation...

Thanks
Nekloth

Allow to pass multiple input files via globbing

Following some discussion on issue #14, I would like to change the API to allow to pass multiple input files via shell globbing. This will be a breaking change because currently the second input argument is treated as the pdf output filename.

$ md-to-pdf **/*.md

The shell would expand the glob into an array of files that will be passed as input arguments (leaving the glob expansion to the shell rather than dealing with it using some npm package).

Stdio mode

Might be helpful for scripting to add a --stdio flag or similar name (might actually not need a flag, can just detect whether there is anything coming in on process.stdin) to read the markdown from stdin and output the PDF to stdout, which would allow to redirect it into a file the UNIX way, i. e.

$ cat file.md | md-to-pdf --stdio >> output.pdf

If anyone would be interested in this, please leave a +1 or comment (:

bug: config.json conflict when both highlight_style and pdf_options

Context:

  • version (md-to-pdf -v): 2.8.1
  • platform (Unix, macOS, Windows): Windows 10
  • node version: 13.1.0

Describe the bug:

If you have both the highlight_style and pdf_options in a config.json file, the highlighting doesn't quite work. With styles like "monokai" and "darcula" the background should be black, but this is completely lost. Sample config.json that won't work:

{
  "highlight_style": "darcula",
  "pdf_options": {
    "format": "Letter",
    "margin": "10mm"
  }
}

But the following will work:

{
  "highlight_style": "darcula"
}

Follow Links to Combine Documents

I'd like to request the ability to instruct the parser to follow file links to other markdown files, to combine multiple documents into one.

bug: SyntaxError Unexpected token function

Context:

  • version (md-to-pdf -v): 2.7.1
  • platform (Unix, macOS, Windows): Debian 8.11 64-bit
  • node version: 6.17.1

Describe the bug:
(A clear and concise description of what the bug is. Feel free to include screenshots.)

Dear Support Team,

After installed successfully "md-to-pdf" on Debian 8.11, I’ve tried to convert my first markdown file in pdf.
Unfortunately, I encountered this error message :

md-top-pdf - SyntaxError Unexpected token function

Thanks for your help.

Regards,

Jean Salmon

feature: include another md file

Problem:

Currently, to have a complete PDF documentation, the whole of chapter have to be written just in one md file.

Solution:

That will great if it is possible to inclide another md file like that for example :
[include](chapter1.md)

Funding for md-to-pdf

Hey @simonhaenisch! 👋

Just wanted to reach out about funding your work on md-to-pdf.

@transitive-bullshit and I are both open source maintainers, and we're currently exploring new ways to make OSS funding a viable source of income.

We're currently looking at building SaaS APIs on top of existing OSS libraries, reserving the majority of profits for the original authors. We've built a few at this point, but want to keep adding more.

I think md-to-pdf could make a really handy SaaS API, and I'd love to build one out. We'd handle dev, auth, billing and support so you wouldn't have to do anything.

Looking forward to hearing your thoughts! 🙏

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.