# Lua

**URL:** https://community.silverbullet.md/c/lua/15.md

[Latest](https://community.silverbullet.md/latest.md) · [Categories](https://community.silverbullet.md/categories.md)

---

## [About the Lua category](https://community.silverbullet.md/t/about-the-lua-category/1654)

<div class="topic-metadata">

**Author:** [@zef](https://community.silverbullet.md/u/zef)\
**Replies:** 0\
**Last updated:** [January 15, 2025, 7:26pm UTC](https://community.silverbullet.md/t/about-the-lua-category/1654 "2025-01-15T19:26:02Z")

</div>

The Lua category is to ask all your questions, post ideas regarding the upcoming Space Lua feature.

---

## [Markdown customizations and external Lua programs](https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443)

<div class="topic-metadata">

**Author:** [@Offray](https://community.silverbullet.md/u/Offray)\
**Replies:** 6\
**Last updated:** [October 16, 2026, 12:46pm UTC](https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443 "2026-10-16T12:46:36Z")

</div>

Hi again, TL;DR: Authors using SB are asking for a short syntax to include metadata in the page or a custom Markdown syntax, which are requirements that I and others have found many times before while authoring in Mar…

---

## [How Do I Search Certain Frontmatter?](https://community.silverbullet.md/t/how-do-i-search-certain-frontmatter/4457)

<div class="topic-metadata">

**Author:** [@toridnyc](https://community.silverbullet.md/u/toridnyc)\
**Replies:** 2\
**Last updated:** [October 16, 2026, 11:42am UTC](https://community.silverbullet.md/t/how-do-i-search-certain-frontmatter/4457 "2026-10-16T11:42:05Z")

</div>

I know that I can use something like the following to give me a list of pages with a certain Tag. But how do I do the same type of query for a different piece of frontmatter? ${template.each(query\[\[from index.tag "plann…

---

## [Why Lua is cool](https://community.silverbullet.md/t/why-lua-is-cool/2018)

<div class="topic-metadata">

**Author:** [@zef](https://community.silverbullet.md/u/zef)\
**Replies:** 19\
**Last updated:** [October 11, 2026, 3:35pm UTC](https://community.silverbullet.md/t/why-lua-is-cool/2018 "2026-10-11T15:35:10Z")

</div>

Not production ready but here’s the essence of the Git plug reimplemented in Lua: \`\`\`space-lua git = {} function git.commit(message) message = message or "Snapshot" print "Comitting..." shell.run("git", {"add", "…

---

## [Sort Order in queries](https://community.silverbullet.md/t/sort-order-in-queries/4365)

<div class="topic-metadata">

**Author:** [@greencow](https://community.silverbullet.md/u/greencow)\
**Replies:** 3\
**Last updated:** [September 10, 2026, 6:39pm UTC](https://community.silverbullet.md/t/sort-order-in-queries/4365 "2026-09-10T18:39:59Z")

</div>

run this query to pull all meetings but it lists them oldest first... how can I just the sort order ${query\[\[ from p = tags.mtg select templates.pageItem(p) order by ????? \]\]}

---

## [Counter that increments with a button click?](https://community.silverbullet.md/t/counter-that-increments-with-a-button-click/2546)

<div class="topic-metadata">

**Author:** [@Whanake](https://community.silverbullet.md/u/Whanake)\
**Replies:** 7\
**Last updated:** [September 4, 2026, 5:29pm UTC](https://community.silverbullet.md/t/counter-that-increments-with-a-button-click/2546 "2026-09-04T17:29:32Z")

</div>

This is probably a very simple question, but I am really struggling to get my head around it at the moment. How do I set up a simple integer variable (local to a page) that increments by 1 each time I press a button (on…

---

## [Is space.writePage() an official API?](https://community.silverbullet.md/t/is-space-writepage-an-official-api/4327)

<div class="topic-metadata">

**Author:** [@finestream](https://community.silverbullet.md/u/finestream)\
**Replies:** 2\
**Last updated:** [August 17, 2026, 4:49am UTC](https://community.silverbullet.md/t/is-space-writepage-an-official-api/4327 "2026-08-17T04:49:05Z")

</div>

Hi there I am writing a library that relies on writing new pages. I found that space.writePage() works however it is not documented on space is the API official? if not what is the official alternative to write a new…

---

## [Zola block shortcodes parsing using Custom Syntax](https://community.silverbullet.md/t/zola-block-shortcodes-parsing-using-custom-syntax/4196)

<div class="topic-metadata">

**Author:** [@v3rmine](https://community.silverbullet.md/u/v3rmine)\
**Replies:** 0\
**Last updated:** [June 5, 2026, 12:16pm UTC](https://community.silverbullet.md/t/zola-block-shortcodes-parsing-using-custom-syntax/4196 "2026-06-05T12:16:59Z")

</div>

Hi I'm starting to use SilverBullet to edit my Zola website. I successfully added support for inline shortcodes, but when I tried to implement block ones, I couldn't because the regex seems to be applied line by line. D…

---

## [I don't know how to use \`index.getObjectByRef\`](https://community.silverbullet.md/t/i-dont-know-how-to-use-index-getobjectbyref/4189)

<div class="topic-metadata">

**Author:** [@drhayes](https://community.silverbullet.md/u/drhayes)\
**Replies:** 4\
**Last updated:** [June 2, 2026, 5:08pm UTC](https://community.silverbullet.md/t/i-dont-know-how-to-use-index-getobjectbyref/4189 "2026-06-02T17:08:44Z")

</div>

Everything I pass in returns nil. For example: index.getObjectByRef('index', 'page', 'index') in my space, which I would think would get me my index page, returns nil. I think I know the difference between the page argu…

---

## [How are task states implemented?](https://community.silverbullet.md/t/how-are-task-states-implemented/3920)

<div class="topic-metadata">

**Author:** [@Krishna-Sivakumar](https://community.silverbullet.md/u/Krishna-Sivakumar)\
**Replies:** 6\
**Last updated:** [February 28, 2026, 1:18pm UTC](https://community.silverbullet.md/t/how-are-task-states-implemented/3920 "2026-02-28T13:18:27Z")

</div>

I noticed that the taskItem template takes a state variable, and any changes to the state variable is synced to the task. How do I programmatically manipulate this from custom widgets? Do I just manipulate the associate…

---

## [\[NEED HELP\] Dynamic widget and extension renderer](https://community.silverbullet.md/t/need-help-dynamic-widget-and-extension-renderer/2206)

<div class="topic-metadata">

**Author:** [@malys](https://community.silverbullet.md/u/malys)\
**Replies:** 1\
**Last updated:** [February 14, 2026, 3:02pm UTC](https://community.silverbullet.md/t/need-help-dynamic-widget-and-extension-renderer/2206 "2026-02-14T15:02:12Z")

</div>

My goal is to create pages (“person” template): --- description: "Create a person" tags: - template - custom hooks.newPage: suggestedName: "" confirmName: true openIfExists: true command: "new person" frontmatt…

---

## [Sorting in Lua (beginners question)](https://community.silverbullet.md/t/sorting-in-lua-beginners-question/3734)

<div class="topic-metadata">

**Author:** [@Mike](https://community.silverbullet.md/u/Mike)\
**Replies:** 1\
**Last updated:** [January 7, 2026, 1:09pm UTC](https://community.silverbullet.md/t/sorting-in-lua-beginners-question/3734 "2026-01-07T13:09:57Z")

</div>

Hi, I’m a Silverbullet beginner with no lua experience, trying to create an lua script that will give me a list of the most common tags, but I can’t get the sort function to work. The function I wrote so far is below (…

---

## [Converting v1 query to v2](https://community.silverbullet.md/t/converting-v1-query-to-v2/3615)

<div class="topic-metadata">

**Author:** [@daveb](https://community.silverbullet.md/u/daveb)\
**Replies:** 9\
**Last updated:** [December 9, 2025, 8:05am UTC](https://community.silverbullet.md/t/converting-v1-query-to-v2/3615 "2025-12-09T08:05:42Z")

</div>

Hi, I’m trying to convert this query that worked in v1 to a query that will work in v2. It shows displays all tags and a count of how many time the tag appears eg tag (3) This is the v1 query {{#each {tag select name w…

---

## [Rendering task states in a query](https://community.silverbullet.md/t/rendering-task-states-in-a-query/3621)

<div class="topic-metadata">

**Author:** [@oxmhpark](https://community.silverbullet.md/u/oxmhpark)\
**Replies:** 2\
**Last updated:** [December 6, 2025, 5:38pm UTC](https://community.silverbullet.md/t/rendering-task-states-in-a-query/3621 "2025-12-06T17:38:43Z")

</div>

Hi, I’ve wrote a query like: # Checklist ${query\[\[ from item = index.tag "task" where table.includes(item.itags, "project") and not item.done order by item.page, item.pos select { state = "\["…

---

## [Using JS function in Space Lua](https://community.silverbullet.md/t/using-js-function-in-space-lua/3593)

<div class="topic-metadata">

**Author:** [@Krishna-Sivakumar](https://community.silverbullet.md/u/Krishna-Sivakumar)\
**Replies:** 2\
**Last updated:** [November 27, 2025, 10:59pm UTC](https://community.silverbullet.md/t/using-js-function-in-space-lua/3593 "2025-11-27T22:59:27Z")

</div>

Is it possible to expose a function written in a plug as a lua function? How can I do this?

---

## [Can't get script working](https://community.silverbullet.md/t/cant-get-script-working/3565)

<div class="topic-metadata">

**Author:** [@Krishna-Sivakumar](https://community.silverbullet.md/u/Krishna-Sivakumar)\
**Replies:** 7\
**Last updated:** [November 23, 2025, 1:15am UTC](https://community.silverbullet.md/t/cant-get-script-working/3565 "2025-11-23T01:15:32Z")

</div>

Hello, I’m a new user (one day old) and I’d like to get a function working in my pages. Let me know if this is not the spot to post these questions! I added the following function within a page, and tried to call it wi…

---

## [Clustering words by their distances or by custom classes](https://community.silverbullet.md/t/clustering-words-by-their-distances-or-by-custom-classes/3563)

<div class="topic-metadata">

**Author:** [@mjf](https://community.silverbullet.md/u/mjf)\
**Replies:** 0\
**Last updated:** [November 20, 2025, 1:13pm UTC](https://community.silverbullet.md/t/clustering-words-by-their-distances-or-by-custom-classes/3563 "2025-11-20T13:13:18Z")

</div>

I find it useful from time to time so sharing here (see examples at the bottom, at least some of them may work for you too): gist. I will later publish it as a Library (as soon as the contept settles down).

---

## [How to flatten and remove duplicates in query results?](https://community.silverbullet.md/t/how-to-flatten-and-remove-duplicates-in-query-results/3397)

<div class="topic-metadata">

**Author:** [@thick.cliff](https://community.silverbullet.md/u/thick.cliff)\
**Replies:** 4\
**Last updated:** [October 16, 2025, 10:12pm UTC](https://community.silverbullet.md/t/how-to-flatten-and-remove-duplicates-in-query-results/3397 "2025-10-16T22:12:10Z")

</div>

Using the following query I get a list of arrays. I want to flatten these arrays into one array and remove duplicates. Not sure what built in functions are available. ${query\[\[ from index.tag "page" where name:start…

---

## [Clickable link from Lua query](https://community.silverbullet.md/t/clickable-link-from-lua-query/3310)

<div class="topic-metadata">

**Author:** [@amandasystems](https://community.silverbullet.md/u/amandasystems)\
**Replies:** 9\
**Last updated:** [October 1, 2025, 11:16am UTC](https://community.silverbullet.md/t/clickable-link-from-lua-query/3310 "2025-10-01T11:16:47Z")

</div>

I’ve laboriously trialled-and-error’d the following terrible query to do the standard “find pages tagged such and such”: ${query\[\[ from index.tag "page" where table.includes(tags, "draft") or \_.draft order by last…

---

## [\[BUG\] Broken infinity comparison compatibility](https://community.silverbullet.md/t/bug-broken-infinity-comparison-compatibility/3257)

<div class="topic-metadata">

**Author:** [@mjf](https://community.silverbullet.md/u/mjf)\
**Replies:** 3\
**Last updated:** [September 23, 2025, 12:50pm UTC](https://community.silverbullet.md/t/bug-broken-infinity-comparison-compatibility/3257 "2025-09-23T12:50:29Z")

</div>

Please, try this: Space Lua | Lua 5.4.x -|- ${ 1/ 0 == 1/ 0 } | \`true\` ${ 1/ 0 == -1/ 0 } | \`false\` ${ 1/ 0 == 1/-0 } | \`true\` ${ 1/ 0 == -1/-0 } | \`false\` ${ -1/ 0 == 1/ 0 } | \`false\` ${ -1/ 0 == -1/ 0 } | \`true…

---

## [Recently modified files filtered by tags issue](https://community.silverbullet.md/t/recently-modified-files-filtered-by-tags-issue/3122)

<div class="topic-metadata">

**Author:** [@Thaurin](https://community.silverbullet.md/u/Thaurin)\
**Replies:** 0\
**Last updated:** [September 1, 2025, 7:38pm UTC](https://community.silverbullet.md/t/recently-modified-files-filtered-by-tags-issue/3122 "2025-09-01T19:38:24Z")

</div>

Hi! I’ve managed to rewrite my recently modified files inline template to Lua after upgrading to v2 this afternoon. This shows the last 10 recently modified files, but omits pages that have any tag on them that contains…

---

## [Calling CodeMirror commands from Space Lua](https://community.silverbullet.md/t/calling-codemirror-commands-from-space-lua/3124)

<div class="topic-metadata">

**Author:** [@laurybueno](https://community.silverbullet.md/u/laurybueno)\
**Replies:** 0\
**Last updated:** [September 2, 2025, 2:10am UTC](https://community.silverbullet.md/t/calling-codemirror-commands-from-space-lua/3124 "2025-09-02T02:10:25Z")

</div>

Is there a way of enabling more CodeMirror features in the SilverBullet markdown editor? I was hoping to use stuff like selectNextOccurrence and allowMultipleSelections. I can see that a good chunk of functionality has…

---

## [How to open a page with Lua?](https://community.silverbullet.md/t/how-to-open-a-page-with-lua/3118)

<div class="topic-metadata">

**Author:** [@molnarti](https://community.silverbullet.md/u/molnarti)\
**Replies:** 3\
**Last updated:** [September 1, 2025, 9:00pm UTC](https://community.silverbullet.md/t/how-to-open-a-page-with-lua/3118 "2025-09-01T21:00:07Z")

</div>

I am trying to create a custom command to open an existing page/create a new one, but cant figure out the Lua command for it. Found nothing among the space or editor APIs. In v1 i solved this by editing the Quick Note t…

---

## [Idea: Make the \`query\` a callable table?](https://community.silverbullet.md/t/idea-make-the-query-a-callable-table/3086)

<div class="topic-metadata">

**Author:** [@mjf](https://community.silverbullet.md/u/mjf)\
**Replies:** 0\
**Last updated:** [August 25, 2025, 7:53am UTC](https://community.silverbullet.md/t/idea-make-the-query-a-callable-table/3086 "2025-08-25T07:53:35Z")

</div>

This is just an idea… TL;DR I’ve been working on API to work with tables for some time (still huge VIP, not something anybody should really see atm., sorry), because for example we still do not have group by and aggreg…

---

## [dostring function equivalent](https://community.silverbullet.md/t/dostring-function-equivalent/3049)

<div class="topic-metadata">

**Author:** [@marcoswur](https://community.silverbullet.md/u/marcoswur)\
**Replies:** 7\
**Last updated:** [August 22, 2025, 12:28am UTC](https://community.silverbullet.md/t/dostring-function-equivalent/3049 "2025-08-22T00:28:55Z")

</div>

Hello. I used dostring function to execute code in string. I will do this PlotaDiario = function() local s = \[==\[ --- ${columns( preenche\_semana2(editor.getCurrentPage()) ) } Últimas mofificadas ${template.each (q…

---

## [How to extend index from hooks?](https://community.silverbullet.md/t/how-to-extend-index-from-hooks/3060)

<div class="topic-metadata">

**Author:** [@mjf](https://community.silverbullet.md/u/mjf)\
**Replies:** 4\
**Last updated:** [August 21, 2025, 11:13am UTC](https://community.silverbullet.md/t/how-to-extend-index-from-hooks/3060 "2025-08-21T11:13:04Z")

</div>

Does any way exist to extend the index from appropriate hooks? TL;DR I am trying to extend index for pages with custom value. I dully hoped the following will work (intuitively): \`\`\`space-lua event.listen { name = '…

---

## [Incorrect timestamp returned by \`os.time\`](https://community.silverbullet.md/t/incorrect-timestamp-returned-by-os-time/2682)

<div class="topic-metadata">

**Author:** [@euler](https://community.silverbullet.md/u/euler)\
**Replies:** 4\
**Last updated:** [August 3, 2025, 9:13am UTC](https://community.silverbullet.md/t/incorrect-timestamp-returned-by-os-time/2682 "2025-08-03T09:13:47Z")

</div>

Hey there. I newly discovered a weird problem that I cannot really understand. I am running the following Lua snippet: ${os.time({year=2025, month=9, day=30})} I know that os.time returns the timestamp in seconds. So …

---

## [Seeing Tags like Linked Mentions](https://community.silverbullet.md/t/seeing-tags-like-linked-mentions/2686)

<div class="topic-metadata">

**Author:** [@Skraut](https://community.silverbullet.md/u/Skraut)\
**Replies:** 0\
**Last updated:** [July 31, 2025, 4:53pm UTC](https://community.silverbullet.md/t/seeing-tags-like-linked-mentions/2686 "2025-07-31T16:53:55Z")

</div>

I’m trying to figure out a Lua query that I can add to my pages to let me view tags associated with that page in a view similar to the Linked Mentions where you see some context, or at least the line that is on the page. …

---

## [Basic question for porgramming](https://community.silverbullet.md/t/basic-question-for-porgramming/2657)

<div class="topic-metadata">

**Author:** [@lukwro](https://community.silverbullet.md/u/lukwro)\
**Replies:** 7\
**Last updated:** [July 28, 2025, 11:52am UTC](https://community.silverbullet.md/t/basic-question-for-porgramming/2657 "2025-07-28T11:52:47Z")

</div>

Hi all, I’m new in Silverbullet nad currently trying to link from my Home page to the newest daily. Can you haelp in creatinf a fucntion which will work \[\[Daily/{{today}}\]\] Thank you

---

## [How to edit paragraph using a function?](https://community.silverbullet.md/t/how-to-edit-paragraph-using-a-function/2623)

<div class="topic-metadata">

**Author:** [@mjf](https://community.silverbullet.md/u/mjf)\
**Replies:** 2\
**Last updated:** [July 18, 2025, 8:22am UTC](https://community.silverbullet.md/t/how-to-edit-paragraph-using-a-function/2623 "2025-07-18T08:22:28Z")

</div>

I need some reformatting shortcut for paragraphs. What is the way to run particular function on particular paragraph and replace it’s content with what the function returned? It should work as new command with keyboard s…

[Next page](https://community.silverbullet.md/c/lua/15.md?page=1)
