do you use custom macros and commands ? let’s share !
I’ll start:
making it easier to add iframes:
in my workflow I often use iframes to embed web references in logseq pages :
then I can quickly pull text or images
define a macro named ‘iframe’ in config.edn
:macros {
"iframe" "<iframe src=\"$1\" style=\"width:calc(100% - 4px);height:650px\"></iframe>"
}
then define related commands :
:commands [
["iframe" [[:editor/input "{{{iframe }}}" {:backward-pos 3}]]]
["iframe-wikipedia" [[:editor/input "{{{iframe https://en.wikipedia.org/wiki/}}}" {:backward-pos 3}]]]
["iframe-google" [[:editor/input "{{{iframe https://www.google.com/search?q=}}}" {:backward-pos 3}]]]
["iframe-google-images" [[:editor/input "{{{iframe https://www.google.com/search?tbm=isch&q=}}}" {:backward-pos 3}]]]
]
**usage: ** now everytime I use slash command /iframe
I can quickly embed a url or I can use /iframe-wikipedia
| /iframe-google
| /iframe-google-images
followed by a search term and get embedded results from which I can pull data without switching to a browser window
8 Likes
Hello. I am new to LoqSeq, jumping from Roam.
Where do you place this code?
thanks in advance
Ramses
August 11, 2022, 7:11pm
3
Welcome to the community @DavidPlummerMD !
Depending on how technically proficient you are, I’d warn against using macros if you’re new to Logseq.
As the OP points out, you’d need to change the config.edn
file. If you don’t know what that is, I suggest you first get some more experience with simpler stuff like a daily template: How to Set Up an Automated Daily Template in Logseq
It also helps if you get experience with queries, starting with simple queries and then slowly move up to Datalog queries. See #learning-sprints:queries for learning resources.
1 Like
cmiles
October 11, 2022, 9:50pm
4
I am brand new to macro and commands. But I really wanted status labels and this post helped me achieve that.
{{pill grey,inactive}} {{pill blue,info}} {{pill green,success}} {{pill yellow,warning}} {{pill red,important}}
config.edn
:macros {
"pill" "<span class=\"pill pill-$1\">$2</span>"
}
:commands [
["pill-red" [[:editor/input "{{pill red,}}" {:backward-pos 2}]]]
["pill-yellow" [[:editor/input "{{pill yellow,}}" {:backward-pos 2}]]]
["pill-blue" [[:editor/input "{{pill blue,}}" {:backward-pos 2}]]]
["pill-green" [[:editor/input "{{pill green,}}" {:backward-pos 2}]]]
["pill-grey" [[:editor/input "{{pill grey,}}" {:backward-pos 2}]]]
]
custom.css
html[data-theme=dark] {
--red: #cb4b16;
--orange: #ffb86c;
--yellow: #b58902;
--blue:#656aa4;
--green: #219d85;
--grey: #586e75;
}
span.pill {
border-radius: var(--ls-border-radius-low);
background-color: var(--ls-page-inline-code-bg-color);
border: 1px solid;
padding-left: 0.3em;
padding-right: 0.3em;
}
span.pill-red {
border-color: var(--red);
color: var(--red);
}
span.pill-yellow {
border-color: var(--yellow);
color: var(--yellow);
}
span.pill-blue {
border-color: var(--blue);
color: var(--blue);
}
span.pill-green {
border-color: var(--green);
color: var(--green);
}
span.pill-grey {
border-color: var(--grey);
color: var(--grey);
}
span.inline div {
display:inline;
}
Note: The last rule for span.inline div
is because Logseq will wrap the macros in divs that are blocks, otherwise forcing each label onto a new line.
The following are things I learnt that others who are new to this might benefit from.
You can press Ctrl
+ Shift
+ I
to open an inspector that lets you examine how Logseq is rendering your macro.
To define multiple macros, put each on a new line – coming from PHP, this is a strange format to me
The :backward-pos
value in the command tells Logseq where to position the cursor after selecting the command.
What I still don’t know is if there is a difference between the using two or three pairs of {
to wrap a macro. I.e. {{macro}}
vs {{{macro}}}
3 Likes
Ash
November 7, 2022, 10:10am
5
Thank you @cannibalox for this inspiration.
I was wondering if it’s possible to render a template via macro directly. That would expand the functionality like supertags in tana.
I’m not a coder nor have any background knowledge of coding; just a PKM enthusiast trying to optimize and enjoy daily note taking processes.
Ash
November 7, 2022, 10:38am
6
Seems like there is some discussion on same lines here
As I am beginning to use templates and attributes for organisation, the templates are organically growing and becoming more useful. Currently, updating a template doesn’t propagate to the existing pages using that template: Templates - how to create, edit, and insert?
However, this functionality would be very useful to buildup and maintain consistency. I realise there are issues with overwriting a local instance when the global template changes, but a smart management of these should be possibl…