]>
Lady’s Gitweb - LesML/blob - sh/lesml.sh
2 # @(#)💄📝 Les·M·L sh/lesml.sh 2026-03-31T01:28:11Z
3 # SPDX-FileCopyrightText: 2023, 2024, 2026 Lady <https://www.ladys.computer/about/#lady>
4 # SPDX-License-Identifier: MPL-2.0
6 ## ⁌ The 💄📝 Les·M·L shell script
8 ## ∎ Copyright © 2023–2024, 2026 Lady [@ Ladys Computer].
10 ## ⋮ This Source Code Form is subject to the terms of the Mozilla
11 ## Public License, version 2.0.
12 ## If a copy of the M·P·L was not distributed with this file, You can
13 ## obtain one at {🔗<https://mozilla.org/MPL/2.0/>}.
17 ## »|sh$sh ./sh/lesml.sh [--] [filename]
19 ## This script provides a simple solution for converting a Les·M·L file
24 ## `LANG´ and `LC_ALL´ are set to `C´ because this script assumes
25 ## working with U·T·F‐8 strings as opaque series of bytes.
32 ## All of the commands used by this script are overridable with your
33 ## own implementations by setting the corresponding `cmd_COMMAND´
36 : "${cmd_DIRNAME:=dirname}"
37 : "${cmd_PRINTF:=printf}"
38 : "${cmd_REALPATH:=realpath}"
42 : "${cmd_XSLTPROC:=xsltproc}"
44 ## In order to run, this program needs to know the location of the
45 ## 💄📝 Les·M·L transform, which is calculated below.
46 ## This location can be manually configured by setting the `path_LESML´
47 ## or `path_TRANSFORM´ environment variables.
50 "${cmd_REALPATH}" -- "${0}"
53 "${cmd_DIRNAME}" -- "${thisfile}"
57 "${cmd_REALPATH}" -- "${thisdir}"'/..'
59 : "${path_LESML:=${defaultlesml}}"
61 defaulttransform
="${path_LESML}"'/xslt/lesml.xslt'
62 : "${path_TRANSFORM:=${defaulttransform}}"
64 ## The (unregistered) media type for Les·M·L files is `text/lesml´.
65 ## By overriding both the media type and the transform, one can re·use
66 ## this script for processing other kinds of files with X·S·L·T.
68 : "${name_MEDIATYPE:=text/lesml}"
70 ## § Parameter processing
72 ## A leading `--´ is allowed (and ignored).
73 ## Otherwise, the first parameter is the source filename.
75 if "${cmd_TEST}" "${1}" = '--'
80 ## If no input file is provided, it defaults to `-´ (standard input).
82 if "${cmd_TEST}" -n "${1}" && "${cmd_TEST}" "${1}" != '-'
85 "${cmd_REALPATH}" -- "${1}"
93 ## ※ This implementation is derived from
94 ## {🔗⛩📰 书社<https://git.ladys.computer/Shushe/>} code written
97 ## The `sanitizeprog´ variable contains a Sed program for sanitizing
98 ## an arbitrary string into characters which are valid in X·M·L.
99 ## Ideally this would be written using dollar‐single‐quote literals,
100 ## but Mac·O·S Dash is outdated and does not support them.
103 "${cmd_PRINTF}" '%b' \
104 's/]]>/]]]]><!\\[CDATA\\[>/g\n' \
105 's/\0357\0277\0276/�/g\n' \
106 's/\0357\0277\0277/�/g\n' \
109 '$!s/\0302\0205$//g\n' \
110 's/\0302\0205/\\n/g\n' \
111 's/\0342\0200\0250/\\n/g\n' \
112 's/[\0001\0002\0003\0004\0005\0006\0007\0010]/�/g\n' \
113 's/[\0016\0017\0020\0021\0022\0023\0024\0025\0026\0027]/�/g\n' \
114 's/[\0031\0032\0033\0034\0035\0036\0037]/�/g'
117 ## A compound statement is used to group together the wrapping X·M·L
118 ## and the sanitized input into one output which can be piped to
122 "${cmd_PRINTF}" '%s\n%s%s%s' \
123 '<?xml version="1.0"?>' \
124 '<script xmlns="http://www.w3.org/1999/xhtml" type="' \
125 "${name_MEDIATYPE}" \
127 if "${cmd_TEST}" "${inputfile}" = '-'
129 "${cmd_TR}" '\000\013\014' '\032\011\012'
131 "${cmd_TR}" '\000\013\014' '\032\011\012' <"${inputfile}"
133 "${cmd_SED}" "${sanitizeprog}"
134 "${cmd_PRINTF}" '%s\n' ']]></script>'
136 "${cmd_XSLTPROC}" --nonet --nowrite --novalid \
137 "${path_TRANSFORM}" \
This page took 0.425785 seconds and 5 git commands to generate.