Skip to content
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

Handle nesting of markup functions #2

Closed
asnewman opened this issue Dec 23, 2024 · 0 comments
Closed

Handle nesting of markup functions #2

asnewman opened this issue Dec 23, 2024 · 0 comments

Comments

@asnewman
Copy link
Owner

If you have a function that generates markup, it needs context to its nesting level where it is called from. For example:

-div()
${generateHelloMessage()}

In this case, generateHelloMessage() needs to have a root nesting of 2 dashes, like so::

function generateHelloMessage() {
	return `
		--p()
		---"Hello world"
	`
}

Because of this, now generateHelloMessage() cannot be used in different nesting scenarios. For example:

-div()
${generateHelloMessage()}
--div()
${generateHelloMessage()} <-- will generate incorrect nesting

For this reason, it would be better if generator functions like this don't need to be aware of nesting level, and instead, the caller signifies that anything under it is a child. Something like this:

-div() {
	${generateHelloMessage()}
}
--div() {
	${generateHelloMessage()}
}

...

function generateHelloMessage() {
	return `
		-p()
		--"Hello world"
	`
}

This would automatically add appropriate nesting to the generated markup.

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

No branches or pull requests

1 participant