Extendible-BBCode-Parser
Extendible-BBCode-Parser copied to clipboard
Provide a hook for implementing validation errors for individual tags
To help users debug their BBCode markup and to generally enhance the level of error feedback, I've been validating the params
and content
in the openTag
function of my tag specifications.
Here's an example of what I've got working:
Did you ever put any thought into this kind of feature?
I haven't studied your code too much yet, so until I figure out how it works, I threw some global state at the problem and wrote some regretful code: https://gist.github.com/danneu/f5b8b58b87b828b708bb
Obviously that's nasty and this certainly isn't a solution proposal, but it's an example of the kind of validation that would be nice to do.
As for a real solution that might be trivial, one idea off the top of my head would be to be to support an optional property on tag specs:
openTag: ...,
closeTag: ...,
// Returns String (err message) upon validation failure, else returns falsey
errorCheck: function(params, content) {
if (!params) return 'Missing color parameter';
}
Any ideas? Either way, I'll see what kind of abstraction I end up with once I start refactoring my mess.
Also, I know this is an old project of yours, and it's possible that BBCode and this repo aren't at the forefront of your mind these days like it was back when you wrote it.
Hi danneu,
I like the idea for an optional property on the tag spec to do the validating/error checking.
You're correct that it's been a while since I've taken much of a dive into this project, but I'm happy to merge in any changes you do if they look like they'll make the project better.
Did you guys have any work for this issue/ suggestion? I'd love to implement this into my current project.
@xadamxk I ended up implementing the sort of code I have linked in my gist, and then I never touched it again.