reddit-moderator-toolbox
reddit-moderator-toolbox copied to clipboard
Replace RR HTML parsing with replaced tokens
Instead of using stuff like <textarea>
, <select>
, <input>
inside removal reason bodies to get custom text input, we should have tokens that are replaced with the appropriate elements without having to parse HTML. For example:
-
<input type="text">
~>{textfield}
-
<textarea>
~>{textarea}
-
<select>
~>{option|other option|etc}
part of #93
things we'll have to do
- [ ] new schema version, remove html parsing
- [ ] write conversion from old to new (make sense of as much old html as we can)
- [ ] implement syntax for the multiple-choice one - will probably require regex parsing, and should also support escaping the inner pipes and right-brace if possible so those can be included literally in options
~~blocked on #119~~
I would suggest to use |
as delimiter as it's seldom used in comments/posts.
And for templating, I'd suggest to mix two chars for start and finish, or use them twice.
{$ thing here $}
{% thing here %}
{{ thing here }} <-- I prefer this one
This is so you can use the characters in the comments without running into issues so easily. And we can make sure people can fix it if they want by escaping
{{select
|I am an \| option
|I'm \{\{ enclosed }}
}}
If we ever introduce parameters for types, we can do something like
{{switch;name:fancyname|Switch label here}}
{{select;typeahead;hidden-by:fancyname|foo|bar|baz}}
Edit: Some more options
{{start-select;option;option2}}
{{start-item}}
I am an | option
{{end-item}}
{{start-item}}
I'm \{\{ enclosed }}
{{end-item}}
{{end-select}}
@start-select(option, option2)
@start-item
I am an | option
@end-item
@start-item
I'm {{ enclosed }}
@end-item
@end-select
Just going over issues at the moment and wanted to note that:
I would suggest to use | as delimiter as it's seldom used in comments/posts.
Probably isn't true as I have seen it used in footers a bunch to put in a bunch of links to stuff like rules, wikis, etc.
Not sure what the best approach here is except possibly building in escape functionality for whatever delimiter character we decide on.
So, instead of doing tokens. Another option would be to keep HTML parsing but utilize web-components (if that's possible).
-
<input type="text">
~><tb-text>
-
<textarea>
~><tb-text multiline>
-
<select>
~><tb-select><tb-option option></tb-option></tb-select>
This means we can
- filter out everything that isn't our components,
- associate toolbox info for each component, and
- still parse HTML to get attributes in an easy way
Or will there still be an issue with escaping and whatnot?