jgrassler / mkdocs-pandoc Goto Github PK
View Code? Open in Web Editor NEW[unmaintained] mkdocs -> pandoc converter: use this fork https://github.com/twardoch/mkdocs-combine
License: Apache License 2.0
[unmaintained] mkdocs -> pandoc converter: use this fork https://github.com/twardoch/mkdocs-combine
License: Apache License 2.0
First off, great tool! Thanks a lot!
I'm using some custom Markdown extensions, e.g. https://github.com/gisce/markdown-blockdiag. Unfortunately, blockdiag blocks don't get processed.
Do you thing there is a way to apply extensions before feeding the source to mkdocs2pandoc?
Windows 10
Python 2.7.13
mkdocs 0.16.3
mkdocs-material 1.5.4
pandoc installed from chocolatey 0.10.5
Site being created: https://github.com/adrianhall/develop-mobile-apps-with-csharp-and-azure
D:\GitHub\develop-mobile-apps-with-csharp-and-azure [master +1 ~0 -0 !]> mkdocs2pandoc > editions/editions1.pd
Traceback (most recent call last):
File "C:\Python27\Scripts\mkdocs2pandoc-script.py", line 11, in <module>
load_entry_point('mkdocs-pandoc==0.2.6', 'console_scripts', 'mkdocs2pandoc')()
File "c:\python27\lib\site-packages\mkdocs_pandoc\cli\mkdocs2pandoc.py", line 80, in main
for line in pconv.convert():
File "c:\python27\lib\site-packages\mkdocs_pandoc\pandoc_converter.py", line 165, in convert
lines = mkdocs_pandoc.filters.tables.TableFilter().run(lines)
File "c:\python27\lib\site-packages\mkdocs_pandoc\filters\tables.py", line 177, in run
ret.extend(self.convert_table(block))
File "c:\python27\lib\site-packages\mkdocs_pandoc\filters\tables.py", line 91, in convert_table
for i in range(0, len(self._split_row(lines_orig[0], has_border))):
TypeError: _split_row() takes exactly 2 arguments (3 given)
mkdocs2pandoc gives no output an no error message.
Would be great, if you could add some logging, possibly a '-v' switch
sudo aptitude install fonts-lmodern lmodern pandoc texlive-base texlive-latex-extra texlive-fonts-recommended texlive-latex-recommended texlive-xetex
cd /home/xxxx/temp
virtualenv .
pip install mkdocs-pandoc
cd <dir-containing-mkdocs.yml>
/home/xxxx/temp/py/bin/mkdocs2pandoc
/home/xxxx/temp/py/bin/mkdocs2pandoc -f mkdocs.yml > file
No output...
Hi, i got an error when start to using mkdocs2pandoc:
➤ git remote -v
origin https://github.com/hugoruscitti/pilas-manual (fetch)
origin https://github.com/hugoruscitti/pilas-manual (push)
~/p/pilas-manual (master=)
➤ mkdocs2pandoc > example.pd
Traceback (most recent call last):
File "/usr/local/bin/mkdocs2pandoc", line 9, in <module>
load_entry_point('mkdocs-pandoc==0.2.5', 'console_scripts', 'mkdocs2pandoc')()
File "/usr/local/lib/python2.7/site-packages/mkdocs_pandoc/cli/mkdocs2pandoc.py", line 80, in main
for line in pconv.convert():
File "/usr/local/lib/python2.7/site-packages/mkdocs_pandoc/pandoc_converter.py", line 95, in convert
pages = self.flatten_pages(self.config['pages'])
File "/usr/local/lib/python2.7/site-packages/mkdocs_pandoc/pandoc_converter.py", line 73, in flatten_pages
if type(list(page.values())[0]) is str:
AttributeError: 'list' object has no attribute 'values'
and an empty output file:
➤ du -s example.pd
0 example.pd
Hey there, just tried your tool and got the following error:
mkdocs2pandoc > mydocs.pd
Traceback (most recent call last):
File "/home/markus/anaconda3/bin/mkdocs2pandoc", line 11, in <module>
sys.exit(main())
File "/home/markus/anaconda3/lib/python3.6/site-packages/mkdocs_pandoc/cli/mkdocs2pandoc.py", line 80, in main
for line in pconv.convert():
File "/home/markus/anaconda3/lib/python3.6/site-packages/mkdocs_pandoc/pandoc_converter.py", line 165, in convert
lines = mkdocs_pandoc.filters.tables.TableFilter().run(lines)
File "/home/markus/anaconda3/lib/python3.6/site-packages/mkdocs_pandoc/filters/tables.py", line 177, in run
ret.extend(self.convert_table(block))
File "/home/markus/anaconda3/lib/python3.6/site-packages/mkdocs_pandoc/filters/tables.py", line 91, in convert_table
for i in range(0, len(self._split_row(lines_orig[0], has_border))):
TypeError: _split_row() takes 2 positional arguments but 3 were given
```
anyone else had this error before?
Best - Markus
Hi:
Thanks for your interesting tool.
However I get all the time the same error: "failed to create process". Just writing the command mkdocs2pandoc
.
Any clues on what could be happening?
TIA!
I'm on Ubuntu 15.04 with Python 2.7.10, mkdocs 0.15.3 and using a slightly modified mkdocs-material theme.
When I run the tool, it exits with this error:
Traceback (most recent call last):
File "/usr/local/bin/mkdocs2pandoc", line 9, in <module>
load_entry_point('mkdocs-pandoc==0.2.6', 'console_scripts', 'mkdocs2pandoc')()
File "/home/maggus/.local/lib/python2.7/site-packages/mkdocs_pandoc/cli/mkdocs2pandoc.py", line 80, in main
for line in pconv.convert():
File "/home/maggus/.local/lib/python2.7/site-packages/mkdocs_pandoc/pandoc_converter.py", line 165, in convert
lines = mkdocs_pandoc.filters.tables.TableFilter().run(lines)
File "/home/maggus/.local/lib/python2.7/site-packages/mkdocs_pandoc/filters/tables.py", line 177, in run
ret.extend(self.convert_table(block))
File "/home/maggus/.local/lib/python2.7/site-packages/mkdocs_pandoc/filters/tables.py", line 163, in convert_table
lines.extend(self.wrap_row(widths, row))
File "/home/maggus/.local/lib/python2.7/site-packages/mkdocs_pandoc/filters/tables.py", line 208, in wrap_row
row[i] = tw.wrap(textwrap.dedent(row[i]))
File "/usr/lib/python2.7/textwrap.py", line 329, in wrap
return self._wrap_chunks(chunks)
File "/usr/lib/python2.7/textwrap.py", line 258, in _wrap_chunks
raise ValueError("invalid width %r (must be > 0)" % self.width)
ValueError: invalid width 0 (must be > 0)
Any ideas?
This is very useful.
In pandoc_converter.py
, change this
# Add an empty line between pages to prevent text from a previous
# file from butting up against headers in a subsequent file.
lines.append('')
to this
# Add an empty line between pages to prevent text from a previous
# file from butting up against headers in a subsequent file.
lines.append('')
lines.append('\\newpage')
lines.append('')
Can this be an option for the cli?
I got an install error on my windows 10 machine - can someone please help me ?
C:\Windows\system32>choco install pandocpdf
Chocolatey v0.10.5
Installing the following packages:
pandocpdf
By installing you accept licenses for the packages.
pandocpdf not installed. The package was not found with the source(s) listed.
If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.
Version: ""
Source(s): "https://chocolatey.org/api/v2/"
Hi there,
I just tried to convert my mydocs docu but I am getting these errors:
Traceback (most recent call last):
File "/usr/local/bin/mkdocs2pandoc", line 11, in
sys.exit(main())
File "/usr/local/lib/python2.7/site-packages/mkdocs_pandoc/cli/mkdocs2pandoc.py", line 80, in main
for line in pconv.convert():
File "/usr/local/lib/python2.7/site-packages/mkdocs_pandoc/pandoc_converter.py", line 103, in convert
pages = self.flatten_pages(self.config['pages'])
KeyError: 'pages'
Appreciate any help!
thanks
When I try to generate a .pd with mkdocs2pandoc -f mkdocs.yml -o output.pd
in my docker image (schizopriest/mkdocs) on gitlab-ci, I get the following error:
Traceback (most recent call last):
File "/usr/bin/mkdocs2pandoc", line 11, in <module>
load_entry_point('mkdocs-pandoc==0.2.6', 'console_scripts', 'mkdocs2pandoc')()
File "/usr/lib/python2.7/site-packages/mkdocs_pandoc/cli/mkdocs2pandoc.py", line 80, in main
for line in pconv.convert():
File "/usr/lib/python2.7/site-packages/mkdocs_pandoc/pandoc_converter.py", line 165, in convert
lines = mkdocs_pandoc.filters.tables.TableFilter().run(lines)
File "/usr/lib/python2.7/site-packages/mkdocs_pandoc/filters/tables.py", line 177, in run
ret.extend(self.convert_table(block))
File "/usr/lib/python2.7/site-packages/mkdocs_pandoc/filters/tables.py", line 91, in convert_table
for i in range(0, len(self._split_row(lines_orig[0], has_border))):
TypeError: _split_row() takes exactly 2 arguments (3 given)
Followed usage to install the stable version of mkdocs-pandocs
. When calling mkdocs2pandoc
i get an error relating to markdown-extensions
Traceback (most recent call last):
File "C:\python\Scripts\mkdocs2pandoc-script.py", line 9, in <module>
load_entry_point('mkdocs-pandoc==0.2.3', 'console_scripts', 'mkdocs2pandoc')
()
File "C:\python\lib\site-packages\mkdocs_pandoc\cli\mkdocs2pandoc.py", line 69
, in main
encoding=args.encoding,
File "C:\python\lib\site-packages\mkdocs_pandoc\pandoc_converter.py", line 52,
in __init__
for ext in self.config['markdown_extensions']:
KeyError: 'markdown_extensions'
I am not quite sure what this means. Did i do something stupid which can be fixed easily?
When trying to convert the documentation of mkdocs .-) (https://github.com/mkdocs/mkdocs.git),
I get the following exception:
» mkdocs2pandoc >! mkdocs.pd
Traceback (most recent call last):
File "/home/ag/.local/bin/mkdocs2pandoc", line 9, in <module>
load_entry_point('mkdocs-pandoc==0.2.5', 'console_scripts', 'mkdocs2pandoc')()
File "/home/ag/.local/venvs/mkdocs-pandoc/lib/python2.7/site-packages/mkdocs_pandoc/cli/mkdocs2pandoc.py", line 80, in main
for line in pconv.convert():
File "/home/ag/.local/venvs/mkdocs-pandoc/lib/python2.7/site-packages/mkdocs_pandoc/pandoc_converter.py", line 157, in convert
lines = mkdocs_pandoc.filters.tables.TableFilter().run(lines)
File "/home/ag/.local/venvs/mkdocs-pandoc/lib/python2.7/site-packages/mkdocs_pandoc/filters/tables.py", line 172, in run
ret.extend(self.convert_table(block))
File "/home/ag/.local/venvs/mkdocs-pandoc/lib/python2.7/site-packages/mkdocs_pandoc/filters/tables.py", line 102, in convert_table
if len(row[i]) > widest_cell[i]:
IndexError: list index out of range
I'm using the devel version @ 671174f
The windows instructions suggest running choco install pandocpdf
:
Chocolatey v0.10.5
Installing the following packages:
pandocpdf
By installing you accept licenses for the packages.
pandocpdf not installed. The package was not found with the source(s) listed.
If you specified a particular version and are receiving this message, it is possible that the package name exists but t
he version does not.
Version: ""
Source(s): "https://chocolatey.org/api/v2/"
Chocolatey installed 0/1 packages. 1 packages failed.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Failures
- pandocpdf - pandocpdf not installed. The package was not found with the source(s) listed.
If you specified a particular version and are receiving this message, it is possible that the package name exists but t
he version does not.
Version: ""
Source(s): "https://chocolatey.org/api/v2/"
hi there!
I'm having a very annoying issue, images seem to brake when I convert my mkdocs 2 pandoc...
some links are relative, others are absolute even though they are all defined in the same way on the individual markdowns...
Problem:
MkDocs only shows resized pictures if they are written in html tags. The pandoc conversion from markdown to pdf will simply cut out all html inliners since the extension raw_html would be ignored. The conversion from markdown to html and finally to pdf will drop any alignment information in tables which would be available in conversion from markdown to pdf.
Idea:
The conversion triggered by mkdocs2pandoc > docs.pd could already check for html tags and change them to markdown inliners. /mkdocs_pandoc/filters/ contains filters like the images.py. A suggestion for a new filter would be html_images.py.
Suggested solution:
In /mkdocs_pandoc/pandoc_converter.py add
import mkdocs_pandoc.filters.html_images
and below def init(self, **kwargs):
self.filter_html_img = True
Above lines_tmp = f_headlevel.run(lines_tmp) add
if self.filter_html_img:
lines_tmp = f_html_image.run(lines_tmp)
html_images.py:
import re
class ImageFilter(object):
def run(self, lines):
ret = []
for line in lines:
done = {}
while True:
src = ''
alt = ''
title = ''
width_height = ''
matchImg = re.search(r'<img ([^>]*)>([^<]*</img>)?', line)
# image in html style?
if matchImg:
if matchImg.group(0) in done:
break
allInfoElems = matchImg.group(1)
srcMatch = re.search(r'src=\"([^>\"]*)\"', allInfoElems)
src=srcMatch.group(1)
altMatch = re.search(r'alt=\"([^>\"]*)\"', allInfoElems)
if altMatch:
alt=altMatch.group(1)
titleMatch = re.search(r'title=\"([^>\"]*)\"', allInfoElems)
if titleMatch:
title=" \""+titleMatch.group(1)+"\""
widthMatch = re.search(r'width=\"([^>\"]*)\"', allInfoElems)
if widthMatch:
width="width="+widthMatch.group(1)+"px "
heightMatch = re.search(r'height=\"([^>\"]*)\"', allInfoElems)
if heightMatch:
height="height="+heightMatch.group(1)+"px "
if width != "" or height != "":
width_height="{ "+width+height+"}"
else:
break
line = re.sub(r'<img [^>]*>([^<]*</img>)?',
'![%s](%s%s)%s' % (alt, src, title, width_height), line)
done[matchImg.group(0)] = True
ret.append(line)
return ret
Running the current mkdocs2pandoc 0.2.4
gives me this error:
Traceback (most recent call last):
File "C:\python\Scripts\mkdocs2pandoc-script.py", line 9, in <module>
load_entry_point('mkdocs-pandoc==0.2.4', 'console_scripts', 'mkdocs2pandoc')
()
File "C:\python\lib\site-packages\mkdocs_pandoc\cli\mkdocs2pandoc.py", line 80
, in main
for line in pconv.convert():
File "C:\python\lib\site-packages\mkdocs_pandoc\pandoc_converter.py", line 139
, in convert
lines_tmp = f_image.run(lines_tmp)
File "C:\python\lib\site-packages\mkdocs_pandoc\filters\images.py", line 75, i
n run
'![%s](%s)' % (alt, img_name), line)
File "C:\python\lib\re.py", line 179, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "C:\python\lib\re.py", line 326, in _subx
template = _compile_repl(template, pattern)
File "C:\python\lib\re.py", line 313, in _compile_repl
p = sre_parse.parse_template(repl, pattern)
File "C:\python\lib\sre_parse.py", line 812, in parse_template
raise error("missing group name")
sre_constants.error: missing group name
which refers to images.py#L75.
According to this SO answer the problem might be related with either the image name or the alternative caption containing special characters that might need escaping before feeding into regex.
I am not so much into python but would be willing to work on this issue. Please let me know.
Hi,
I get this error when trying to generate the PDF:
pandoc: Error producing PDF from TeX source.
! Font T1/cmr/m/n/10=ecrm1000 at 10.0pt not loadable: Metric (TFM) file not found.
<to be read again>
relax
l.100 \fontencoding\encodingdefault\selectfont
any suggestions?
Hello,
Your tool is great help and almost perfect. My only issue is with mkdocs option when yaml file is written following way
pages:
- Home: 'index.md'
- User Guide:
- 'Writing your docs': 'user-guide/writing-your-docs.md'
- 'Styling your docs': 'user-guide/styling-your-docs.md'
- About:
- 'License': 'about/license.md'
- 'Release Notes': 'about/release-notes.md'
in such case generated pd file is without header level 1 for User Guide and About causing result PDF to not be structured as I want.
Home is correct as there is index.md file but if there is not mardown file it will not be placed to generated file.
From #30 (comment):
I'm not using it anymore, so I no longer have much of an inclination to maintain it.
Any of you folks want to take over maintaining it?
I've mentioned I can help out over in #30 (comment).
Anyone else motivated to help this thing keep up with the mkdocs ecosystem?
In mkdocs.yml
, the pages:
directive is being deprecated in favor of the nav:
directive. This means that eventually mkdocs-pandoc
will not work with functional mkdocs.yml
files.
Here's the error you will see if you use nav:
(as per mkdocs spec) instead of pages:
:
$ mkdocs2pandoc > mydocs.pd
Traceback (most recent call last):
File "/Users/charles/davis/dahak/dahak-comparison/vp/bin/mkdocs2pandoc", line 11, in <module>
sys.exit(main())
File "/Users/charles/davis/dahak/dahak-comparison/vp/lib/python3.6/site-packages/mkdocs_pandoc/cli/mkdocs2pandoc.py", line 80, in main
for line in pconv.convert():
File "/Users/charles/davis/dahak/dahak-comparison/vp/lib/python3.6/site-packages/mkdocs_pandoc/pandoc_converter.py", line 103, in convert
pages = self.flatten_pages(self.config['pages'])
KeyError: 'pages'
As mentioned in #5 (comment) the generated output might need unexpected extra line breaks.
To reproduce this have a look at mkoertgen/mkdocs-pandoc-samples. The ./headings
directory contains a sample project that reproduces this issue - at least on Windows.
I used
mkdocs2pandoc -o mydocs.pd
pandoc --toc -f markdown+grid_tables+table_captions -o mydocs.pdf mydocs.pd
Here is the relevant section in the generated .pd
#### Another Heading 2
Lorem ipsum...
## Say B
### Say B (Heading 1)
For me the generated mydocs.pd
looks ok but maybe the pd-syntax requires empty lines between headings. So maybe it's pandoc
that requires an extra line here.
Finally, the generated mydocs.pdf
includes some lines ending with the extra headings generated by mkdocs2pandoc (cf. attachments)
As a workaround i started adding html page breaks (at the end of overview/a.md
)
<div style="page-break-after: always;"></div>
After that i realized that adding an extra line break at the end of the files also works around this issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.