From: Lady Date: Mon, 1 Apr 2024 21:05:41 +0000 (-0400) Subject: Allow ⛩️📰 书社 to produce plain text X-Git-Tag: 0.7.0~3 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/c29056b55b54897e5eae3d0a4e407406d4c593c6?ds=sidebyside;hp=2024d501192c7399c0791dec5ba0d3004613aefc Allow ⛩️📰 书社 to produce plain text This requires adding _another_ build stage; the result of the transformation step is output to `build/results`, which is then processed again to create the `build/public` final result. In most cases, this additional processing just produces a symlink. However, when the root element is a special value, a derived file will be produced. The only special elements supported right now are `<书社:raw-text>`, which outputs the raw text contents of the text nodes in the result tree, and `<书社:base64-binary>`, which produces a binary file from the base64 text contents determined using the same method. --- diff --git a/GNUmakefile b/GNUmakefile index 75045a9..98a08cb 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -39,6 +39,7 @@ override define makefileinfo ║│ • touch │║ ║│ • tr (requires support for `-d´) │║ ║│ • uuencode (requires support for `-m´ and `-r´) │║ +║│ • uudecode (requires support for `-m´ and `-r´) │║ ║│ • xargs (requires support for `-0´) │║ ║│ • xmlcatalog (provided by libxml2) │║ ║│ • xmllint (provided by libxml2) │║ @@ -112,6 +113,7 @@ STAT := stat TEST := test TOUCH := touch TR := tr +UUDECODE := uudecode UUENCODE := uuencode XARGS := xargs XMLCATALOG := xmlcatalog @@ -366,7 +368,7 @@ override sourcedestinationpair := $(foreach destination,$(destinations),$(call s override destination = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcedestinationpair)))) # Pair each source file with its compiled location. -override sourcecompiledpair := $(foreach file,$(sourcefiles),$(file)|$(BUILDDIR)/public/$(call destination,$(file))) +override sourcecompiledpair := $(foreach file,$(sourcefiles),$(file)|$(BUILDDIR)/results/$(call destination,$(file))) # (callable) Get the location of the transformed X·M·L files for the given source files. override compiled = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%,$(sourcecompiledpair)))) @@ -374,6 +376,9 @@ override compiled = $(foreach file,$1,$(patsubst $(file)|%,%,$(filter $(file)|%, # (callable) Get the source files for the given compiled file. override uncompiled = $(foreach file,$1,$(patsubst %|$(file),%,$(filter %|$(file),$(sourcecompiledpair)))) +# (callable) Get the location of the final built file for the given source files. +override built = $(foreach file,$1,$(patsubst $(BUILDDIR)/results/%,$(BUILDDIR)/public/%,$(call compiled,$(file)))) + # (callable) Get the installed locations for the given source files. override installed = $(foreach file,$1,$(DESTDIR)/$(call destination,$(file))) endif @@ -396,10 +401,16 @@ override wrapplaintext = $(TR) '\000\013\014' '\032\011\012' < $(call quote,$1) # This isn’t a perfect substitution (it makes some assumptions about the format of the underlying X·M·L), but it should be workable for most sensible, welformed files. override serializexml = $(SED) "$$($(PRINTF) '%b' '/]*?>//\n s/&\0043x0*[1-8BCEFbcef];/\0302\0221/g\n s/&\0043x0*1[0-9A-Fa-f];/\0302\0221/g\n s/&\00430*[1-8];/\0302\0221/g\n s/&\00430*1[124-9];/\0302\0221/g\n s/&\00430*2[0-9];/\0302\0221/g\n s/&\00430*3[01];/\0302\0221/g\n}')" < $(call quote,$1) | $(SED) "$$(PRINTF '%b' ':a\n/^\\n*$$/{ $$d\n N\n ba\n}')" +# (callable) Test if the provided xpath expression matches the provided document. +override xpath = $(XMLLINT) --xpath $(call quote,$1) $(call quote,$2) > /dev/null 2> /dev/null + +# (callable) Extract the value of the text nodes in the provided X·M·L document and print them to `stdout´. +override extracttext = $(PRINTF) '%s' '' | $(XSLTPROC) - $(call quote,$1) + # ─ ¶ Phony Targets ─────────────────────────────────────────────────── # Compile all files, or error if any are recursive. -all : $(call compiled,$(recursivefiles) $(compilablefiles)) ; +all : $(call built,$(recursivefiles) $(compilablefiles)) ; # Destroy buildfiles. clean : @@ -539,16 +550,26 @@ $(BUILDDIR)/transform.xslt : $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalo @$(ECHO) "Generating main transform…" $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<) -# Generate the output files using the dependencies as necessary. -$(call compiled,$(compilablefiles)) : $(BUILDDIR)/public/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@))) - $(silent)$(call ensuredirectory,$(dir $@)) +# Compile the result files using the dependencies as necessary. +$(call compiled,$(compilablefiles)) : $(BUILDDIR)/results/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@))) @$(PRINTF) '%s\n' $(call quote,Compiling …) + $(silent)$(call ensuredirectory,$(dir $@)) $(silent)$(XSLTPROC) -o $(call quote,$@) --stringparam CATALOG 'catalog' --stringparam BUILDTIME $$(TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ') --stringparam SRCTIME $$(TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call uncompiled,$@))) --stringparam IDENTIFIER $(call quote,$(call localuri,$(call uncompiled,$@))) --stringparam PATH $(call quote,/$*) --stringparam CKSUM $$($(CKSUM) $(call quote,$(call uncompiled,$@)) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<) -$(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/public/% : $$(call uncompiled,$$@) +$(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/results/% : $$(call uncompiled,$$@) @$(PRINTF) '%s\n' $(call quote,Compiling …) $(silent)$(call ensuredirectory,$(dir $@)) $(silent)$(CP) $(call quote,$<) $(call quote,$@) +# Create the final files from the compiled results (or error in the case of recursive ones). +$(call built,$(compilablefiles)) : $(BUILDDIR)/public/% : $(BUILDDIR)/results/% + @$(PRINTF) '%s\n' $(call quote,Building …) + $(silent)$(call ensuredirectory,$(dir $@)) + $(silent)if $(call xpath,/*[local-name()="raw-text" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$<); then $(RM) -f $(call quote,$@); $(call extracttext,$<) > $(call quote,$@); elif $(call xpath,/*[local-name()="base64-binary" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"],$<); then $(RM) -f $(call quote,$@); $(call extracttext,$<) | $(TR) -d '\t\n\f\r ' | $(UUDECODE) -m -r > $(call quote,$@); else $(LN) -s -f $(call quote,$(subst $(space),,$(foreach component,$(subst /, ,$*),../))results/$*) $(call quote,$@); fi +$(call built,$(filter $(assetfiles),$(sourcefiles)) $(recursivefiles)) : $(BUILDDIR)/public/% : $(BUILDDIR)/results/% + @$(PRINTF) '%s\n' $(call quote,Building …) + $(silent)$(call ensuredirectory,$(dir $@)) + $(silent)$(LN) -s -f $(call quote,../results/$*) $(call quote,$@) + # Install compiled files (or error in the case of recursive ones). $(call installed,$(filter $(assetfiles),$(sourcefiles)) $(recursivefiles) $(compilablefiles)) : $(DESTDIR)/% : $(BUILDDIR)/public/% @$(PRINTF) '%s\n' $(call quote,Installing …) diff --git a/README.markdown b/README.markdown index 1973e02..7c663be 100644 --- a/README.markdown +++ b/README.markdown @@ -73,9 +73,13 @@ Compilation involves the following steps :⁠— 5. ⛩️📰 书社 uses the dependency tree to establish prerequisites for each output file. -6. ⛩️📰 书社 compiles each output file to `build/public`. +6. ⛩️📰 书社 compiles each output file to `build/result`. -7. ⛩️📰 书社 copies the output files to `public`. +7. ⛩️📰 书社 symlinks most output files from `build/result` to + `build/public`, but it does some additional processing instead on + those which indicate a non‐X·M·L desired final output form. + +8. ⛩️📰 书社 copies the final resulting files to `public`. You can use `make list` to list each identified source file or include alongside its computed type and dependencies. @@ -126,6 +130,7 @@ In every case, you may supply your own implementation by overriding the - `touch` - `tr` (requires support for `-d`) - `uuencode` (requires support for `-m` and `-r`) +- `uudecode` (requires support for `-m` and `-r`) - `xargs` (requires support for `-0`) - `xmlcatalog` (provided by `libxml2`) - `xmllint` (provided by `libxml2`) @@ -522,8 +527,8 @@ This mechanism can be used to allow transforms to insert content Output wrapping can be entirely disabled by adding a `@书社:disable-output-wrapping` attribute to the top‐level element in the result tree. -This attribute will also prevent wrapping non‐H·T·M·L embeds with an - ``. +It will not be performed on outputs whose root elements are + `<书社:raw-text>` or `<书社:base64-binary>` (described below). ## Applying Attributes @@ -546,6 +551,22 @@ Both elements ignore attributes in the `xml:` namespace, except for On H·T·M·L and S·V·G elements, `@lang` has the same behaviour as `@xml:lang`. +## Other Kinds of Output + +There are a few special elements in the `书社:` namespace which, if + they appear as the toplevel element in a transformation result, cause + ⛩️📰 书社 to produce something other than an X·M·L file. +They are :⁠— + +- **`<书社:raw-text>`:** + A plaintext (U·T·F‐8) file will be produced from the text nodes in + the transformation result. + +- **`<书社:base64-binary>`:** + The text nodes in the transformation result will, after removing all + Ascii whitespace, be treated as a Base·64 string, which is then + decoded. + ## License This repository conforms to [REUSE][]. diff --git a/lib/catalog2transform.xslt b/lib/catalog2transform.xslt index 35f9c2b..85d043c 100644 --- a/lib/catalog2transform.xslt +++ b/lib/catalog2transform.xslt @@ -232,7 +232,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one - +