Skip to content

Commit a260d83

Browse files
committed
v1.1.3 Variable Substitution Rules Relaxed
1 parent 0963abb commit a260d83

9 files changed

Lines changed: 150 additions & 104 deletions

File tree

changelog.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,10 @@
10781078
.highlight .gc{color:#999;background-color:#EAF2F5}
10791079
</style><title>changelog</title></head><body><article class="markdown-body"><h1 id="this-is-the-change-log-for-mdpre-markdown-preprocessor">This Is The Change Log For mdpre Markdown Preprocessor<a class="headerlink" href="#this-is-the-change-log-for-mdpre-markdown-preprocessor" title="Permanent link"></a></h1>
10801080
<h3 id="releases">Releases<a class="headerlink" href="#releases" title="Permanent link"></a></h3>
1081+
<h3 id="v113-28-september-2025">v1.1.3 - 28 September, 2025<a class="headerlink" href="#v113-28-september-2025" title="Permanent link"></a></h3>
1082+
<ul>
1083+
<li><strong>ENHANCED</strong> <a href="https://github.com/MartinPacker/mdpre/issues/45">Issue 45</a>: Variable Substitution Rules Relaxed</li>
1084+
</ul>
10811085
<h3 id="v112-19-august-2025">v1.1.2 - 19 August, 2025<a class="headerlink" href="#v112-19-august-2025" title="Permanent link"></a></h3>
10821086
<ul>
10831087
<li><strong>FIXED</strong> <a href="https://github.com/MartinPacker/mdpre/issues/42">Issue 42</a>: Crash With Dependency Extraction In A Code Block</li>
@@ -1102,13 +1106,13 @@ <h3 id="v10-25-may-2025">v1.0 - 25 May, 2025<a class="headerlink" href="#v10-25-
11021106
<h3 id="v09-17-may-2025">v0.9 - 17 May, 2025<a class="headerlink" href="#v09-17-may-2025" title="Permanent link"></a></h3>
11031107
<ul>
11041108
<li><strong>ENHANCED</strong> <a href="https://github.com/MartinPacker/mdpre/issues/33">Issue 33</a>: Add environment variables</li>
1105-
<li><strong>ENHANCED</strong> <a href="https://github.com/MartinPacker/mdpre/issues/34">Issue 34</a>: Support <code>=ifmatch</code> &amp; <code>=ifnonmatch</code></li>
1109+
<li><strong>ENHANCED</strong> <a href="https://github.com/MartinPacker/mdpre/issues/34">Issue 34</a>: Support <code>=ifmatch</code> &amp;; <code>=ifnonmatch</code></li>
11061110
</ul>
11071111
<h3 id="v081-9-may-2025">v0.8.1 - 9 May, 2025<a class="headerlink" href="#v081-9-may-2025" title="Permanent link"></a></h3>
11081112
<ul>
11091113
<li><strong>FIXED</strong> <a href="https://github.com/MartinPacker/mdpre/issues/32">Issue 32</a>: Verbose output for <code>=def</code> doesn&rsquo;t cope with colons</li>
11101114
<li><strong>ENHANCED</strong> <a href="https://github.com/MartinPacker/mdpre/issues/30">Issue 30</a>: Allow Variable To Be Set To stderr Value For a Command</li>
1111-
<li><strong>ENHANCED</strong> <a href="https://github.com/MartinPacker/mdpre/issues/31">Issue 31</a>: Support <code>=ifempty</code> &amp; <code>=ifnotempty</code></li>
1115+
<li><strong>ENHANCED</strong> <a href="https://github.com/MartinPacker/mdpre/issues/31">Issue 31</a>: Support <code>=ifempty</code> &amp;; <code>=ifnotempty</code></li>
11121116
</ul>
11131117
<h3 id="v08-3-may-2025">v0.8 - 3 May, 2025<a class="headerlink" href="#v08-3-may-2025" title="Permanent link"></a></h3>
11141118
<ul>

changelog.log

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
mdpre Markdown Preprocessor v1.1.2 (19 August, 2025)
3-
====================================================
2+
mdpre Markdown Preprocessor v1.1.3 (28 September, 2025)
3+
=======================================================
44

55
- opened <stdout> for writing
66
Def makefile = file-3
@@ -13,43 +13,45 @@ Def input = stdin
1313

1414
Def node = Mac.domain_not_set.invalid
1515

16-
Def version = Darwin Kernel Version 25.0.0: Tue Aug 5 22:46:55 PDT 2025; root:xnu-12377.1.6~5/RELEASE_ARM64_T6000
16+
Def version = Darwin Kernel Version 25.1.0: Fri Sep 19 19:14:26 PDT 2025; root:xnu-12377.40.77.505.1~4/RELEASE_ARM64_T6000
1717

1818
Def architecture = 64bit Mach-O
1919

2020
Def machine = arm64
2121

2222
Def system = Darwin
2323

24-
Def release = 25.0.0
24+
Def release = 25.1.0
2525

2626
Def python_version = 3.13.1
2727

2828
Def python_implementation = CPython
2929

3030
Def processor = arm
3131

32-
Def mdpre_date = 19 August, 2025
32+
Def mdpre_date = 28 September, 2025
3333

34-
Def mdpre_level = 1.1.2
34+
Def mdpre_level = 1.1.3
3535

3636
Def userid = martinpacker
3737

38-
Def day = 19
38+
Def day = 28
3939

40-
Def month = August
40+
Def month = September
4141

4242
Def year = 2025
4343

44-
Def time = 16&colon;05
44+
Def time = 13&colon;47
4545

46-
Def date = 19 August&comma; 2025
46+
Def date = 28 September&comma; 2025
4747

4848
This Is The Change Log For mdpre Markdown Preprocessor
4949

5050
Table Of Contents - spec '2 2 Releases'
5151

5252
2 2 Releases
53+
..... ..... v1.1.3 - 28 September, 2025
54+
5355
..... ..... v1.1.2 - 19 August, 2025
5456

5557
..... ..... v1.1.1 - 9 June, 2025
@@ -114,7 +116,7 @@ Table Of Contents - spec '2 2 Releases'
114116

115117
..... ..... v0.0 - 12 March, 2018
116118

117-
----------------------------------------------------
119+
-------------------------------------------------------
118120
- Processing completed.
119-
----------------------------------------------------
121+
-------------------------------------------------------
120122

changelog.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
### Releases
44

55

6+
### v1.1.3 - 28 September, 2025
7+
8+
* **ENHANCED** [Issue 45](https://github.com/MartinPacker/mdpre/issues/45): Variable Substitution Rules Relaxed
9+
610
### v1.1.2 - 19 August, 2025
711

812
* **FIXED** [Issue 42](https://github.com/MartinPacker/mdpre/issues/42): Crash With Dependency Extraction In A Code Block
@@ -28,13 +32,13 @@
2832
### v0.9 - 17 May, 2025
2933

3034
* **ENHANCED** [Issue 33](https://github.com/MartinPacker/mdpre/issues/33): Add environment variables
31-
* **ENHANCED** [Issue 34](https://github.com/MartinPacker/mdpre/issues/34): Support `=ifmatch` & `=ifnonmatch`
35+
* **ENHANCED** [Issue 34](https://github.com/MartinPacker/mdpre/issues/34): Support `=ifmatch` &; `=ifnonmatch`
3236

3337
### v0.8.1 - 9 May, 2025
3438

3539
* **FIXED** [Issue 32](https://github.com/MartinPacker/mdpre/issues/32): Verbose output for `=def` doesn't cope with colons
3640
* **ENHANCED** [Issue 30](https://github.com/MartinPacker/mdpre/issues/30): Allow Variable To Be Set To stderr Value For a Command
37-
* **ENHANCED** [Issue 31](https://github.com/MartinPacker/mdpre/issues/31): Support `=ifempty` & `=ifnotempty`
41+
* **ENHANCED** [Issue 31](https://github.com/MartinPacker/mdpre/issues/31): Support `=ifempty` &; `=ifnotempty`
3842

3943
### v0.8 - 3 May, 2025
4044

changelog.mdp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
=toc 2 2 Releases
44

5+
### v1.1.3 - 28 September, 2025
6+
7+
* **ENHANCED** [Issue 45](https://github.com/MartinPacker/mdpre/issues/45): Variable Substitution Rules Relaxed
8+
59
### v1.1.2 - 19 August, 2025
610

711
* **FIXED** [Issue 42](https://github.com/MartinPacker/mdpre/issues/42): Crash With Dependency Extraction In A Code Block

mdpre

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ from enum import Enum
2323
import calendar
2424
import tempfile
2525

26-
mdpre_level = "1.1.2"
27-
mdpre_date = "19 August, 2025"
26+
mdpre_level = "1.1.3"
27+
mdpre_date = "28 September, 2025"
2828
banner = "mdpre Markdown Preprocessor v" + mdpre_level + " (" + mdpre_date + ")"
2929

3030

@@ -1368,15 +1368,32 @@ def substitute_variables(input_line):
13681368
# Go through the remaining fragments, extracting their data
13691369
for f in range(ampersands):
13701370
fragment = fragments[f + 1]
1371-
semicolonPos = fragment.find(";")
1372-
if semicolonPos == -1:
1373-
# No terminating semicolon
1374-
output_line += "&" + fragment
1375-
else:
1371+
1372+
if (semicolonPos := fragment.find(";")) > -1:
13761373
# Terminating semicolon so extract variable name
13771374
varName = fragment[:semicolonPos]
1375+
13781376
tail = fragment[semicolonPos + 1 :]
1377+
13791378
output_line += replace_varname(varName) + tail
1379+
1380+
elif (spacePos := fragment.find(" ")) > -1:
1381+
# Terminating space so extract variable name
1382+
varName = fragment[:spacePos]
1383+
1384+
tail = fragment[spacePos:]
1385+
1386+
output_line += replace_varname(varName) + tail
1387+
1388+
else:
1389+
if f == ampersands - 1:
1390+
# Last fragment on the line
1391+
output_line += replace_varname(fragment[: -1])
1392+
1393+
else:
1394+
# No terminating semicolon
1395+
output_line += "&" + fragment
1396+
13801397
return output_line
13811398

13821399

user-guide.html

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@
11891189
<h1 id="markdown-preprocessor-user-guide">Markdown Preprocessor User Guide<a class="headerlink" href="#markdown-preprocessor-user-guide" title="Permanent link"></a></h1>
11901190
<p>This document describes the mdpre Markdown preprocessor.</p>
11911191
<p>In this document we&rsquo;ll refer to it as &ldquo;mdpre&rdquo;, pronounced &ldquo;em dee pree&rdquo;.</p>
1192-
<p>This document was converted to HTML at 12&colon;21 on 8 June&comma; 2025.</p>
1192+
<p>This document was converted to HTML at 13&colon;44 on 28 September&comma; 2025.</p>
11931193
<h3 id="table-of-contents">Table Of Contents<a class="headerlink" href="#table-of-contents" title="Permanent link"></a></h3>
11941194
<ul>
11951195
<li><a href="#why-a-preprocessor">Why A Preprocessor?</a></li>
@@ -1206,7 +1206,10 @@ <h3 id="table-of-contents">Table Of Contents<a class="headerlink" href="#table-o
12061206
</li>
12071207
<li><a href="#language-elements">Language Elements</a><ul>
12081208
<li><a href="#including-files-with-include">Including files with <code>=include</code></a></li>
1209-
<li><a href="#defining-variables-with-def">Defining Variables With <code>=def</code></a></li>
1209+
<li><a href="#defining-variables-with-def">Defining Variables With <code>=def</code></a><ul>
1210+
<li><a href="#substituting-variables-in-text">Substituting Variables In Text</a></li>
1211+
</ul>
1212+
</li>
12101213
<li><a href="#undefining-variables-with-undef">Undefining Variables With <code>=undef</code></a></li>
12111214
<li><a href="#incrementing-integer-variables-wth-inc">Incrementing Integer Variables Wth <code>=inc</code></a></li>
12121215
<li><a href="#decrementing-integer-variables-wth-dec">Decrementing Integer Variables Wth <code>=dec</code></a></li>
@@ -1341,11 +1344,10 @@ <h3 id="creating-a-make-file-fragment">Creating A Make File Fragment<a class="he
13411344
mdpre -v &lt; $(target).mdp &gt; $(target).md 2&gt;$(target).log $(makefragment)
13421345
</code></pre>
13431346
<p>You could, for example, include the following lines in your main make file (possibly called &ldquo;makefile&rdquo;):</p>
1344-
<div class="highlight"><pre>target=user-guide
1345-
1346-
include fragment.mak
1347-
</pre></div>
1348-
1347+
<p>```
1348+
target=user-guide</p>
1349+
<p>include fragment.mak
1350+
```</p>
13491351
<p>This would set the make variable <code>target</code> to the value &ldquo;user-guide&rdquo;.
13501352
The result of this is that running make invokes mdpre against user-guide.mdp, creating as output user-guide.md and sending messages to user-guide.log.
13511353
Verbose Mode is turned on - which is probably what you want with a log file as a destination for messages.</p>
@@ -1427,16 +1429,6 @@ <h3 id="defining-variables-with-def">Defining Variables With <code>=def</code><a
14271429
<p>The variable name cannot contain spaces. If you try the parser will interpret anything after the first space as a value. Other than that there are no restrictions on variable names.</p>
14281430
<p>Defining variables is useful with the <code>=ifdef</code> and <code>=ifndef</code> statements, and their analogues.
14291431
See <a href="#conditional-inclusion">Conditional Inclusion</a>.</p>
1430-
<p>To use a variable you&rsquo;ve defined with a value code the variable name preceded by an ampersand and terminated by a semicolon.
1431-
For example:</p>
1432-
<pre><code>=def greeting Hello
1433-
1434-
&amp;greeting; World!
1435-
</code></pre>
1436-
<p>will produce:</p>
1437-
<pre><code>Hello World!
1438-
</code></pre>
1439-
<p>If you don&rsquo;t terminate the use of the variable with a semicolon it won&rsquo;t be substituted. If the variable isn&rsquo;t defined at the point of usage it won&rsquo;t be substituted.</p>
14401432
<p>You can also define variables and, optionally, set their value with the <code>-d</code> command line parameter. See <a href="#defining-variables">Defining Variables</a> for more.</p>
14411433
<p>For the third and fourth forms, the command string needs to be enclosed in backticks.
14421434
The command is platform dependent.
@@ -1459,6 +1451,22 @@ <h3 id="defining-variables-with-def">Defining Variables With <code>=def</code><a
14591451
=def command ls &amp;lsFlags;
14601452
=def listing,myErr `&amp;command;`
14611453
</code></pre>
1454+
<h4 id="substituting-variables-in-text">Substituting Variables In Text<a class="headerlink" href="#substituting-variables-in-text" title="Permanent link"></a></h4>
1455+
<p>To substitute a variable in text you&rsquo;ve defined with its value code the variable name preceded by an ampersand and terminated by a semicolon.</p>
1456+
<p>For example:</p>
1457+
<pre><code>=def greeting Hello
1458+
1459+
&amp;greeting; World!
1460+
</code></pre>
1461+
<p>will produce:</p>
1462+
<pre><code>Hello World!
1463+
</code></pre>
1464+
<p>If you don&rsquo;t terminate the use of the variable with a semicolon it won&rsquo;t be substituted unless one of the following is true:</p>
1465+
<ul>
1466+
<li>The variable name is terminated by a space. (The space will be preserved.)</li>
1467+
<li>The variable name is at the end of the line. (The newline will be preserved.)</li>
1468+
</ul>
1469+
<p>If the variable isn&rsquo;t defined at the point of usage it won&rsquo;t be substituted.</p>
14621470
<h3 id="undefining-variables-with-undef">Undefining Variables With <code>=undef</code><a class="headerlink" href="#undefining-variables-with-undef" title="Permanent link"></a></h3>
14631471
<p>Just as you can use <code>=def</code> to define a variable you can remove it from the variable table using <code>=undef</code>. For example,</p>
14641472
<pre><code>=undef xyzzy
@@ -1915,32 +1923,24 @@ <h3 id="creating-a-calendar-month-table-with-cal">Creating A Calendar Month Tabl
19151923
<p>although in md2pptx the bullets would be coloured appropriately - and mdpre actually centres the month.</p>
19161924
<h4 id="controlling-how-day-numbers-are-displayed-with-caldays">Controlling How Day Numbers Are Displayed With <code>=caldays</code><a class="headerlink" href="#controlling-how-day-numbers-are-displayed-with-caldays" title="Permanent link"></a></h4>
19171925
<p>You can style days in the calendar with CSS using the <code>class</code> attribute. For example:</p>
1918-
<div class="highlight"><pre>=caldays blue 14 15 16 17
1919-
=caldays orange 18
1920-
</pre></div>
1921-
1926+
<p><code>=caldays blue 14 15 16 17
1927+
=caldays orange 18</code></p>
19221928
<p>In this case days 14, 15, 16, and 17 are styled with CSS class <code>blue</code>, whereas day 18 is styled with CSS class <code>orange</code>. You need to code the CSS for classes <code>blue</code> and <code>orange</code> for these specifications to be effective.</p>
19231929
<p><code>=caldays</code> must be specified on its own line between the <code>=cal</code> and <code>=endcal</code> lines. You can specify as many <code>=caldays</code> lines as you like within this bracket.</p>
19241930
<p>You can specify a range of days in the following manner:</p>
1925-
<div class="highlight"><pre>=caldays blue 14-17 22-24 27
1926-
</pre></div>
1927-
1931+
<p><code>=caldays blue 14-17 22-24 27</code></p>
19281932
<p><strong>Notes:</strong></p>
19291933
<ol>
19301934
<li>In a range specification there mustn&rsquo;t be spaces between the <code>-</code> and the numbers either side.</li>
19311935
<li>A later <code>=caldays</code> line overrides a prior one in the sequence - within a <code>=cal</code> / <code>=endcal</code> bracket.</li>
19321936
</ol>
19331937
<h4 id="adding-a-key-to-the-day-numbers-styling-with-calkey">Adding A Key To The Day Numbers&rsquo; Styling With <code>=calkey</code><a class="headerlink" href="#adding-a-key-to-the-day-numbers-styling-with-calkey" title="Permanent link"></a></h4>
19341938
<p>You can add bullets below the table to explain what each style means. For example:</p>
1935-
<div class="highlight"><pre>=calkey blue We have data for **somehow**
1936-
=calkey orange Is focus day
1937-
</pre></div>
1938-
1939+
<p><code>=calkey blue We have data for **somehow**
1940+
=calkey orange Is focus day</code></p>
19391941
<p>causes the following Markdown / HTML to be generated:</p>
1940-
<div class="highlight"><pre>* &lt;span class=&#39;blue&#39;&gt;&amp;nbsp;&lt;/span&gt;We have data for **somehow**
1941-
* &lt;span class=&#39;orange&#39;&gt;&amp;nbsp;&lt;/span&gt;Is focus day
1942-
</pre></div>
1943-
1942+
<p><code>* &lt;span class='blue'&gt;&amp;nbsp;&lt;/span&gt;We have data for **somehow**
1943+
* &lt;span class='orange'&gt;&amp;nbsp;&lt;/span&gt;Is focus day</code></p>
19441944
<p>As with <code>=caldays</code>, you need to code the CSS for classes <code>blue</code> and <code>orange</code> for these specifications to be effective.</p>
19451945
<p><code>=calkey</code> must be specified on its own line between the <code>=cal</code> and <code>=endcal</code> lines. You can specify as many <code>=calkey</code> lines as you like within this bracket.</p>
19461946
<p><strong>Notes:</strong> </p>
@@ -1952,19 +1952,15 @@ <h4 id="adding-a-key-to-the-day-numbers-styling-with-calkey">Adding A Key To The
19521952
</ol>
19531953
<h4 id="adding-information-to-a-cell-with-calnote">Adding Information To A Cell With <code>=calnote</code><a class="headerlink" href="#adding-information-to-a-cell-with-calnote" title="Permanent link"></a></h4>
19541954
<p>You can add annotations to individual calendar dates with <code>=calnote</code>. For example:</p>
1955-
<div class="highlight"><pre>=calnote 17 A
1956-
=calnote 18 &lt;span class=&quot;green&quot;&gt;B&lt;/span&gt;
1957-
</pre></div>
1958-
1955+
<p><code>=calnote 17 A
1956+
=calnote 18 &lt;span class="green"&gt;B&lt;/span&gt;</code></p>
19591957
<ol>
19601958
<li><code>=calnote 17 A</code> adds the text &ldquo;A&rdquo; to the cell for 17th of the month.</li>
19611959
<li><code>=calnote 18 &lt;span class="green"&gt;B&lt;/span&gt;</code> adds the text &ldquo;B&rdquo; in (presumably) green to the cell for the 18th of the month.</li>
19621960
</ol>
19631961
<p><code>=calnote</code> must be specified on its own line between the <code>=cal</code> and <code>=endcal</code> lines. You can specify as many <code>=calnote</code> lines as you like within this bracket.</p>
19641962
<p>You can specify a range of days in the following manner:</p>
1965-
<div class="highlight"><pre>=calnote 14-17 RMF
1966-
</pre></div>
1967-
1963+
<p><code>=calnote 14-17 RMF</code></p>
19681964
<p><strong>Notes:</strong></p>
19691965
<ol>
19701966
<li>In the examples given the text is short. It probably looks worse if the text is long.</li>

0 commit comments

Comments
 (0)