diff -r 9221e7c3bf36 -r 03413eb7301f make/common/ProcessMarkdown.gmk --- a/make/common/ProcessMarkdown.gmk Wed Oct 17 11:41:33 2018 +0200 +++ b/make/common/ProcessMarkdown.gmk Tue Oct 23 13:45:24 2018 +0200 @@ -26,6 +26,8 @@ $(error You must include MakeBase.gmk prior to including ProcessMarkdown.gmk) endif +include TextFileProcessing.gmk + # Helper function for SetupProcessMarkdown # $1: The $1 from SetupProcessMarkdown # $2: The name of the current source file, relative to $1_SRC @@ -35,8 +37,14 @@ $1_$2_INPUT_FILE := $$($1_SRC)/$2 $1_$2_MARKER := $$(subst /,_,$1_$2) - ifneq ($$($1_PRE_PROCESS), ) + ifneq ($$($1_REPLACEMENTS), ) $1_$2_PANDOC_INPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_pre.tmp + + $$(eval $$(call SetupTextFileProcessing, $1_$2_PREPROCESSED, \ + SOURCE_FILES := $$($1_$2_INPUT_FILE), \ + OUTPUT_FILE := $$($1_$2_PANDOC_INPUT), \ + REPLACEMENTS := $$($1_REPLACEMENTS), \ + )) else $1_$2_PANDOC_INPUT := $$($1_$2_INPUT_FILE) endif @@ -62,17 +70,14 @@ $1_$2_OPTIONS += --filter $$($1_FILTER) endif - $1_$2_VARDEPS := $$($1_OPTIONS) $$($1_$2_OPTIONS) $$($1_CSS) + $1_$2_VARDEPS := $$($1_OPTIONS) $$($1_$2_OPTIONS) $$($1_CSS) \ + $$($1_REPLACEMENTS) $$($1_POST_PROCESS) $1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \ $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps) -$$($1_$2_OUTPUT_FILE): $$($1_$2_INPUT_FILE) $$($1_$2_VARDEPS_FILE) $$($1_EXTRA_DEPS) +$$($1_$2_OUTPUT_FILE): $$($1_$2_PANDOC_INPUT) $$($1_$2_VARDEPS_FILE) $$($1_EXTRA_DEPS) $$(call LogInfo, Converting $2 to $$($1_FORMAT)) $$(call MakeDir, $$($1_$2_TARGET_DIR) $$(SUPPORT_OUTPUTDIR)/markdown) - ifneq ($$($1_PRE_PROCESS), ) - $$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_pre, \ - $$($1_PRE_PROCESS) < $$($1_$2_INPUT_FILE) > $$($1_$2_PANDOC_INPUT)) - endif $$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \ $$(PANDOC) $$($1_OPTIONS) -f markdown -t $$($1_FORMAT) --standalone \ $$($1_$2_CSS_OPTION) $$($1_$2_OPTIONS) '$$($1_$2_PANDOC_INPUT)' \ @@ -109,6 +114,8 @@ # OPTIONS : Additional options to pandoc # EXTRA_DEPS : Additional dependencies to add to each pandoc call # FILTER : Optional pandoc filter command +# POST_PROCESS : Optional command-line to post-process generated markdown +# REPLACEMENTS : Text replacements to perform on input file before processing # SetupProcessMarkdown = $(NamedParamsMacroTemplate) define SetupProcessMarkdownBody @@ -131,23 +138,6 @@ endif ifeq ($$($1_FORMAT), man) - # Use preprocessing to inject the current version. - $1_PRE_PROCESS := $(SED) -e 's/@@VERSION_SHORT@@/$(VERSION_SHORT)/g' - - # Pandoc's default behavior is to convert `code` to \f[C], which do not - # show up in normal man page rendering (but shows correctly when generating - # html). The norm for man pages is to show code as bold, so this should be - # transformed. However, even if we fix this in our pandoc filter, pandoc prior - # to version 2.0 cannot properly produced nested formatting in man pages - # (see https://github.com/jgm/pandoc/issues/3568). - # As a workaround, use post-processing with sed instead. - # - # As of pandoc 2.3, the termination of formatting is still broken - # (see https://github.com/jgm/pandoc/issues/4973). We need to replace - # \f[] with \f[R]. - $1_POST_PROCESS := $(SED) -e 's/\\f\[C\]/\\f\[CB\]/g' \ - -e 's/\\f\[\]/\\f\[R\]/g' - # If no file extension is specified, default to '.1'. ifeq ($$($1_FILE_EXT), ) $1_FILE_EXT := .1