Hello again,
I tried this out today, because I want to try to auto-evaluate LaTex equasions using JavaScript, but it just seems to return
$1:: parent
or
macro-argument:: parent
I’ve tried all three versions of the code, I have it in my config.edn, I have the page you gave me, but somehow it just always returns parent no matter what I giveconfig.edn:
:macros {
:pp "<span class='kit' data-kit='parentprop' data-prop='$1'>$1:: parent</span>"
}
ParentProp.md:
logseq.kits.setStatic(function parentprop(span){
if (span.closest('.ls-block:has(a[data-ref=template])')) return
const blockId = span.closest(".ls-block").getAttribute("blockId")
const block = logseq.api.get_block(blockId)
const content = block.content
const macroName = span.closest(".macro").dataset.macroName
const macroStart = content.indexOf("{{" + macroName)
const macroEnd = content.indexOf("}}", macroStart) + 2
const prop = span.dataset.prop
const text = logseq.api.get_block(block.parent.id).content
const replace = (prop === '$1' ? text : '')
const newContent = content.slice(0, macroStart) + replace + content.slice(macroEnd)
logseq.api.update_block(blockId, newContent.replace('{{' + macroName + '}}', ''))
if (!replace) logseq.api.upsert_block_property(blockId, prop, text)
})
Test JavaScript.md
-
$$3*3$$
-```runjs
// Load Evaluatex.js dynamically
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/evaluatex@latest/dist/evaluatex.min.js';
document.head.appendChild(script);
script.onload = async () => {
try {
const latex = "3*3"
// Evaluate the LaTeX expression
const fn = evaluatex(latex);
const result = fn();
// Display the result in this block
setOutput(result);
} catch (err) {
setOutput('Error: ' + err.message);
}
};
```
- Test
- {{pp}}
-
Does the format of the macro section in config.edn matter? Does the formatting of the JavaScript matter? Does it not actually have a parent and I’m stupid?
Thanks in advance, all answers are welcome