Force the generator to not indent specific lines/block content?

15 views
Skip to first unread message

Zuni Leone

unread,
Jul 1, 2026, 3:40:54 AM (2 days ago) Jul 1
to Blockly
In my case specifically, for Lua's long strings, e.g:

_ = [[
hello
world
]]

If this is within an indented context, the indent will affect the content of the string, which I don't want. I'm using a custom generator (which is currently almost a copy of the built in LuaGenerator) — is there a way to un-indent these inner lines, short of doing some messy stuff rewriting the parent CodeGenerator class?

Thanks, Blockly people :)

Neil Fraser

unread,
Jul 1, 2026, 4:03:39 AM (2 days ago) Jul 1
to blo...@googlegroups.com
That's a valid and interesting use case.

You can easily turn off all indentation with a simple property assignment.  Here's where I'm doing this for assembly language:

That said, you want very specific lines within an already assembled block of code to not indent, while allowing all other lines to indent.  I can't think of any clean ways of doing this.  The active code is here:

It's not pretty, but might I suggest this approach:
1) When generating a long string literal, prefix each non-indenting line with a special character.  The null character '\0' would probably be the best choice.
2) Allow indenting to happen as normal.
3) On the final generated program, run this regexp: .replace(/^\s+\0/g, '') This will strip all the unwanted indents from those lines.

--
Neil Fraser, Switzerland
https://neil.fraser.name

Neil Fraser

unread,
Jul 1, 2026, 4:06:32 AM (2 days ago) Jul 1
to blo...@googlegroups.com
Er, make that regexp:  .replace(/^\s*\0/g, '')

So that it also catches cases where there is no indent.

Zuni Leone

unread,
Jul 1, 2026, 4:19:41 AM (2 days ago) Jul 1
to Blockly
Thanks! That worked great, with a tiny regex tweak: .replace(/^\s*\0/gm, "")
Reply all
Reply to author
Forward
0 new messages