As a follow-up to How to get a regex search-replace yield markup rather than plain text, while the macro is now working when I call it directly with a string (thanks to help from @EricShulman, @Brian_Radspinner and – offline – @telumire) , when I transclude the parameter, the macro seems to have no effect. A demo of the problem is at https://crosseye.github.io/TW5-demos/2023-04-12a/. I’m guessing it’s something easily overcome, but whatever brain rot was affecting me yesterday seems to still be at work.
The macro is simply a way to allow the tiddler to have data like "H2O"
for Water, but display it as H2O
. One of my attempted fixes was to replace the macro name “formula” with “chemical-formula” just in case there was some conflict with the field name. As I expected, this made no difference. But that got left in when I made the demo.
Used directly
This demonstrates that the macro is working fine when I hard-code the chemical formula.
Markup
<ul>
<li><$link to="Water">Water (<<chemical-formula "C9H8O4" >>)</$link></li>
<li><$link to="Aspirin">Aspirin (<<chemical-formula "H2O" >>)</$link></li>
</ul>
Result
Used by transclusion
But when I transclude that formula, it’s not showing correctly. Wrapping it in quotes does not matter:
Markup
<ul>
<$set name="currentTiddler" value="Aspirin">
<li><$link>{{!!title}} (<<chemical-formula {{!!formula}} >>)</$link></li>
</$set>
<$set name="currentTiddler" value="Water">
<li><$link>{{!!title}} (<<chemical-formula "{{!!formula}}" >>)</$link></li>
</$set>
</ul>
Result
(Simplified) intended usage
The actual usage will have this running inside a <$list>
Widget. The filter is much more complex, but that part is working fine. It’s only a matter of getting the formula to display correctly.
Markup
<ul>
<$list filter=[tag[Compound]]>
<li><$link>{{!!title}} (<<chemical-formula {{!!formula}} >>)</$link></li>
</$list>
</ul>
Result
- Aspirin ( C9H8O4)
- Carbon Dioxyde ( CO2)
- Carbon Monoxide ( CO)
- Chlorine (gas) ( Cl2)
- Dihydrogen ( H2)
- Dioxygen ( O2)
- Hydrochloric acid ( HCl)
- Nitrogen dioxide ( NO2)
- Potassium hydroxide ( KOH)
- Sodium chloride ( NaCl)
- Water ( H2O)
Any suggestions?