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

Add callback support for handling unknown tags #60

Closed
subsoap opened this issue Aug 1, 2020 · 2 comments
Closed

Add callback support for handling unknown tags #60

subsoap opened this issue Aug 1, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@subsoap
Copy link
Contributor

subsoap commented Aug 1, 2020

Allow the user to setup a callback function to run if the user wants to use tags which are not defined in the normal extension.

Example for a possible action tag would be

<action=particles:text_emitter>Make this pretty</action>

and

<action=sound:ding/>

The main thing the callback needs to be used for is defining how the data of the tag is handled so in the sound case the "sound:ding" would need to be handled when doing parse_tag.

local parse = require("richtext.parse")
parse.callback = function(tag, params, settings)
	if tag == "action" then
		local action_type, action_option = params:match("(.-):(.*)")
		settings.action = {
			type = action_type,
			option = action_option
		}
	end
end


.... in parse.lua below other tag definitions

	elseif M.callback then
		M.callback(tag, params, settings)
	end
@subsoap
Copy link
Contributor Author

subsoap commented Aug 1, 2020

More complicated non-data tags would require multiple callbacks too though, how to handle them in all of the situations of RichText, but just the data part would be useful to people no doubt.

And in these cases users may want to just edit RichText itself or suggest / contribute new core feature tags.

@subsoap
Copy link
Contributor Author

subsoap commented Aug 2, 2020

Another possible case would be a macro tag, which could be used by people to apply multiple common effects to text based on the macro name

Input
<macro=lotus>undying lotus</macro>

Ouput
<action=particles:text_emitter_red><color=lotus_red>undying lotus</color></action>

@britzl britzl added the enhancement New feature or request label Aug 12, 2020
@britzl britzl closed this as completed in 0d3e543 Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants