Recursive directory parsing with Pandoc on Mac

前端 未结 2 2062
失恋的感觉
失恋的感觉 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.

提交回复
热议问题