Recursive directory parsing with Pandoc on Mac

前端 未结 2 2061
失恋的感觉
失恋的感觉 2020-12-30 15:41

I found this question which had an answer to the question of performing batch conversions with Pandoc, but it doesn\'t answer the question of how to make it recursive. I sti

相关标签:
2条回答
  • 2020-12-30 16:19

    Create the following Makefile:

    TXTDIR=sources
    HTMLS=$(wildcard *.html)
    MDS=$(patsubst %.html,$(TXTDIR)/%.markdown, $(HTMLS))
    
    .PHONY : all
    
    all : $(MDS)
    
    $(TXTDIR) :
        mkdir $(TXTDIR)
    
    $(TXTDIR)/%.markdown : %.html $(TXTDIR)
        pandoc -f html -t markdown -s $< -o $@
    

    (Note: The indented lines must begin with a TAB -- this may not come through in the above, since markdown usually strips out tabs.)

    Then you just need to type 'make', and it will run pandoc on every file with a .html extension in the working directory, producing a markdown version in 'sources'. An advantage of this method over using 'find' is that it will only run pandoc on a file that has changed since it was last run.

    0 讨论(0)
  • 2020-12-30 16:33

    Just for the record: here is how I achieved the conversion of a bunch of HTML files to their Markdown equivalents:

    for file in $(ls *.html); do pandoc -f html -t markdown "${file}" -o "${file%html}md"; done
    

    When you have a look at the script code from the -o argument, you'll see it uses string manipulation to remove the existing html with the md file ending.

    0 讨论(0)
提交回复
热议问题