Can Pandoc output syntax-highlighted codeblocks from a vimwiki source? - pandoc

For markdown Pandoc's syntax highlighting works great, for example for a file
test.md that looks like this
some text...
```sh
for i in {1,2,3}; do echo ${i}; done
```
the command
pandoc -f markdown -t html -s --highlight-style=zenburn -o out.html test.md
generates html-output out.html that basically has the syntax highlighting
specified in zenburn "baked in" and a browser renders it as you'd want:
However for the vimwiki-format (which pandoc supports) this doesn't seem to
work even though I haven't found anything saying the syntax highlighting was
limited only to some source formats.
Basically: Can I get pandoc to do the same style of syntax highlighting in the
html output if my source format is vimwiki and my source looks like this:
some text...
{{{sh
for i in {1,2,3}; do echo ${i}; done
}}}
because doing
pandoc -f vimwiki -t html -s --highlight-style=zenburn -o out.html test.wiki
yields (what you can also tell from the generated html) this:

Related

Makefile provides blank tex files

I am currently in the process of writing quite a large document, that I divided into multiple chapters. What I chose to do is to put each chapter in a different file, and then compile them with a makefile into one big document. When I type make get in the terminal, the .tex docs appear with the right name in my folder but completely blank.
Here is my makefile :
pdf:
pdflatex --shell-escape file.tex
clean:
rm -f chapter1.tex
rm -f chapter2.tex
get:
sed -e '/BEGIN_BOOK/,/END_BOOK/!d' ../01-chapter1/chapter1.tex> chapter1.tex
sed -e '/BEGIN_BOOK/,/END_BOOK/!d' ../02-chapter2/chapter2.tex> chapter2.tex
diff:
git latexdiff HEAD -- --main file.tex --latexopt "--shell-escape"
But if I replace these blank ones with the correct files, the make command works properly and I get what I want.
Thank you in advance

pandoc error: divide by zero

I am writing a book. The orginal format is reST, and sphinx is used to generate HTML/epub format. However it has to be converted into docx, since the editor think it is a good raw format for Indesign in their daily process.
A shell script is used:
#!/bin/bash
cd ./source
echo foreword
pandoc -o foreword.docx foreword.rst
echo ch001
pandoc -o ch001.docx ch001.rst
echo ch002
pandoc -o ch002.docx ch002.rst
echo ch002b
pandoc -o ch002b.docx ch002b.rst
echo ch003
pandoc -o ch003.docx ch003.rst
echo ch004
pandoc -o ch004.docx ch004.rst
echo ch005
pandoc -o ch005.docx ch005.rst
echo ch006
pandoc -o ch006.docx ch006.rst
echo ch007
pandoc -o ch007.docx ch007.rst
echo ch008
pandoc -o ch008.docx ch008.rst
echo ch009
pandoc -o ch009.docx ch009.rst
echo futureplan
pandoc -o futureplan.docx futureplan.rst
mv *.docx ../release/
cd ../
I got the following result from console:
foreword
ch001
ch002
ch002b
ch003
pandoc: divide by zero
ch004
ch005
pandoc: divide by zero
ch006
pandoc: divide by zero
ch007
pandoc: divide by zero
ch008
pandoc: divide by zero
ch009
pandoc: divide by zero
futureplan
Any document which was complainted for divide by zero has only 30B in file size.
Please tell me know to locate and fix that error. I can not find any clue from documentation and group.
Maybe it is a bug, but I have to avoid this issue since the scheduler is very tight.
Finally, I downloaded latest version pandoc for Windows.
Since rest to docx will drop some pictures, I use another work around method.
reST to HTML by sphinx, HTML to docx by pandoc.

In Bash, how can I use process substitution to create a template for Pandoc?

I'm trying to modify the default Pandoc LaTeX template (a small setting concerning tables) and I'm trying to do this and the Pandoc run all in one command. I'm getting the error pandoc: Could not find data file /dev/fd/63.latex when I try to execute the command and I'm not sure how to address it. The command is as follows:
pandoc --template <(pandoc --print-default-template=latex | sed 's/longtable,//') -f markdown -t latex report.md -o report.pdf
How should I be doing this process substitution?

How can I accomplish this `cat` usage more tersely?

Open ended question (be creative!) for a real use case. Essentially I want to cat (1) an existing file (2) the output of a program and (3) a specific bit of text. Between pipes, echo and redirects, I feel like I should be able to do better than this!
pandoc -t latex -o mydoc.tex mydoc.rst
echo \\end{document} > footer.tex
cat header.tex mydoc.tex footer.tex > fulldoc.tex
{
cat header.tex
pandoc -t latex mydoc.rst
echo \\end{document}
} > fulldoc.tex
If you're using bash, you can use process substitution and a here string:
cat header.tex <(pandoc -t latex mydoc.rst) <<<'\end{document}' > fulldoc.tex

Prepend header to file without changing the file

Background
The enscript command can apply syntax highlighting to various types of source files, including SQL statements, shell scripts, PHP code, HTML files, and more. I am using enscript to generate 300dpi images of source code for a technical manual to:
Generate content for the book based on actual source code.
Distribute the source code along with the book, without any modification.
Run and test the scripts while writing the book.
Problem
The following shell script performs the conversion almost as desired:
#!/bin/bash
DIRNAME=$(dirname $1)
FILENAME=$(basename $1)
# Remove the extension from the filename.
BASENAME=${FILENAME%%.*}
FILETYPE=${FILENAME##*.}
LIGHTGRAY="#f3f3f3"
enscript --escapes --color -f Courier10 -X ps -B -1 --highlight=$FILETYPE \
$2 -h -o - $1 | \
gs -dSAFER -sDEVICE=pngalpha -dGraphicsAlphaBits=4 -dNOPAUSE -r300 \
-sOutputFile=$BASENAME.png -dBackgroundColor=16$LIGHTGRAY > /dev/null && \
convert -trim $BASENAME.png $BASENAME-trimmed.png && \
mv $BASENAME-trimmed.png $BASENAME.png
The problem is that the background is not a light gray colour. According to the enscript man page, the --escapes (-e) option indicates that the file (i.e., $1) has enscript-specific control sequences embedded within it.
Adding the control sequences means having to duplicate code, which defeats the purpose of having a single source.
Solution
The enscript documentation implies that it should be possible to concatenate two files together (the target and a "header") before running the script, to create a third file:
^#shade{0.85} -- header line
#!/bin/bash -- start of source file
Then delete the third file once the command completes.
Questions
Q.1. What is a more efficient way to pipe the control sequences and the source file to the enscript program without using a third file?
Q.2. What other options are available to automate syntax highlighting for a book, while honouring the single source requirements I have described? (For example, write the book in LyX and use LaTeX commands for import and syntax highlighting.)
Q1 You can use braces '{}' to do I/O redirection:
{ echo "^#shade{0.85}"; cat $1; } |
enscript --color -f Courier10 -X ps -B -1 --highlight=$FILETYPE $2 -h -o - |
gs -dSAFER -sDEVICE=pngalpha -dGraphicsAlphaBits=4 -dNOPAUSE -r300 \
-sOutputFile=$BASENAME.png -dBackgroundColor=16$LIGHTGRAY > /dev/null &&
convert -trim $BASENAME.png $BASENAME-trimmed.png &&
mv $BASENAME-trimmed.png $BASENAME.png
This assumes that enscript reads its standard input when not given an explicit file name; if not, you may need to use an option (perhaps '-i -') or some more serious magic, possibly even 'process substitution' in bash.
You could also use parentheses to run a sub-shell:
(echo "^#shade{0.85}"; cat $1) | ...
Note that the semi-colon after cat is necessary with braces and not necessary with parentheses (and a space is necessary after the open brace) - such are the mysteries of shell scripting.
Q2 I don't have any alternatives to offer. When I produced a book (20 years ago now, using troff), I wrote a program to convert source into the the necessary markup, so that the book was produced from the source code, but by an automated process.
(Is 300 dpi sufficiently high resolution?)
Edit
To work-around the enscript program interpreting the escape sequence embedded in the conversion script itself:
{ cat ../../enscript-header.txt $1; } |
Q2: Use LaTeX with the listings package.

Resources