New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macros and backticks #101
Comments
Hi, macros in LiaScript are a simple text substitution not strings as in programming languages. What you want is something like <!--
@mm
``` @0
@1
```
@end
-->
# Course Main Title
@mm(python,`print('Hallo Welt')`)
``` @mm(python)
# hallo Welt
print(12)
``` I think for some reason, a macro name must be longer than one character. And if you want to have new lines, it is better to use the definition type with I tried to explain the definition of macros here: I hope this helps ;-) |
Would it be possible to construct the same output using javascript? I tried
|
It should be ... what is problematic in this case, is that you have to add some styling. You have to display it as a block otherwise the code will not be visible ... For me, the following macro did the job ... @mm2
<script style="width:100%; display:block">
`LIASCRIPT:
\`\`\` @0
@1
\`\`\`
`
</script>
@end Scripts are inline elements, that is why they are rendered within a span. This works fine, if scripts are small members within a text, etc. But when larger elements are created, this styling has to be applied 🙈 |
I'm not sure I understand how composition of macros works when backticks are involved.
Then
And if I change
I get a box with |
Hi, this is a bit more complicated, the problem is that macros are not like in programming languages, it only deals with strings, it uses only the characters @example(_This is a longer param_,`@t1(some more stuff, with commas)`,``` some very long param
with some
new lines
...
```) in your case surrounding @mm3
``` @0
@1
```
@end
@tt
<script style="width:100%; display:block">
'LIASCRIPT: # ' + @0
</script>
@end
-->
# Course Main Title
@mm3(python,```@tt(1)```) The algorithm goes like this. When a macro is identified, its parameters are checked, if it contains some macros, then these are evaluated, in the same way (recursively), if the result-string is ready, it injected at the position it is called within your macro definition ... Sub macros are only evaluated immediately if they are parameters, you macro definition might contain further but these are ignored until the parser reaches them ... It is a pretty simple and "mighty" approach. We have created this originally to deal with replication in its simplest way and thought complex stuff should still be done with javascript ... You can have a look at https://github.com/topics/liascript-template for some inspiration, in nearly all cases here are some more complex macros are defined ... |
It seems that
The text was updated successfully, but these errors were encountered: