在Windows中批处理Pandoc转换

问题描述 投票:5回答:4

我正在尝试使用Windows中的Pandoc将大量HTML文件转换为Markdown,并在how to do this on a Mac上找到答案,但在尝试在Windows PowerShell中运行以下命令时会收到错误。

find . -name \*.md -type f -exec pandoc -o {}.txt {} \;

有人可以帮我翻译这个在Windows上工作吗?

batch-file markdown pandoc
4个回答
6
投票

以递归方式转换文件夹中的文件尝试此操作(Windows提示符命令行):

for /r "startfolder" %i in (*.htm *.html) do pandoc -f html -t markdown "%~fi" -o "%~dpni.txt"

在批处理文件中使用加倍%


0
投票

Endoro的答案很棒,不要对添加到%i的参数感到困惑。

为了帮助其他人,我需要从RST(重组文本)转换为dokuwiki语法,所以我创建了一个convert.bat

FOR /r "startfolder" %%i IN (*.rst) DO pandoc -f rst -t dokuwiki "%%~fi" -o "%%~dpni.txt"

适用于文件夹和子文件夹中的所有rst文件。


0
投票

如果你想递归通过一个目录及其子目录来编译所有类型的文件,比如*.md,那么你可以使用我写的批处理文件来回答另一个问题How can I use pandoc for all files in the folder in Windows?。我称之为pancompile.bat,用法如下。转到代码的其他答案。

Usage: pancompile DIRECTORY FILENAME [filemask] ["options"]
Uses pandoc to compile all documents in specified directory and subdirectories to a single output document

DIRECTORY         the directory/folder to parse recursively (passed to pandoc -s);
                  use quotation marks if there are spaces in the directory name
FILENAME          the output file (passed to pandoc -o); use quotation marks if spaces
filemask          an optional file mask/filter, e.g. *.md; leave blank for all files
"options"         optional list of pandoc commands (must be in quotation marks)

Minimal example: pancompile docs complete_book.docx
Typical example: pancompile "My Documents" "Complete Book.docx" *.md "-f markdown -t docx --standalone --toc"

0
投票

使用powershell内置的gci

gci -r -i *.md |foreach{$docx=$_.directoryname+"\"+$_.basename+".docx";pandoc $_.name -o $docx}

来自https://github.com/jgm/pandoc/issues/5429

© www.soinside.com 2019 - 2024. All rights reserved.