Skip to content

Conversation

@fig-eater
Copy link
Contributor

@fig-eater fig-eater commented Nov 18, 2025

Adds an optional argument convert_tab_size to CLI and Markdown formatter options. The argument is optional the user may provide an integer in the range of [0, 255] to convert tabs into that number of spaces.

I just used replaceOwned to do this as that is what was already being done with turning \n to \n\n but this could be a point of improvement, changing points where we replace these with a alloc-less writer.

I was struggling run the executable for bbcodez to test this so I needed to make some additional fixes:
Fixes:

  • Use createFile instead of openFile for creating the output file.
  • Flush after writing a textElement, no output was being generated for text-only input.

bbcode:

this should show as a tab: "	"
this should show as a tab: `	`
this should show as a tab: [code]	[/code]
this should show as backslash t: "\t"
this should show as backslash t: `\t`
this should show as backslash t: [code]\t[/code]
escaped: \[code\]	[/code\]

generated markdown (4 space tabs):

this should show as a tab: "    "

this should show as a tab: `    `

this should show as a tab: `    `

this should show as backslash t: "\t"

this should show as backslash t: `\t`

this should show as backslash t: `\t`

escaped: [code]    [/code]

Closes #1

@fig-eater
Copy link
Contributor Author

For changes required on the gdzig side of things, we would just need to add this argument to the renderDocument call in docs.zig:
https://github.com/gdzig/gdzig/blob/9ec99bf4344cec830d509124821a96f68f3c5e3c/gdzig_bindgen/Context/docs.zig#L257

    try bbcodez.fmt.md.renderDocument(allocator, doc, &output.writer, .{
        .write_element_fn = writeElement,
        .user_data = @ptrCast(@constCast(&doc_ctx)),
        .convert_tab_size = 4, // new, may want to put as a const at the top of file.
    });

@deevus deevus merged commit 5a4f5bd into gdzig:main Nov 19, 2025
7 checks passed
@deevus
Copy link
Collaborator

deevus commented Nov 19, 2025

Nice one. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add convert_tabs_to_spaces configuration option (default: false)

2 participants