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

similey replacement & other text changes #4

Open
ajorias opened this issue Apr 26, 2013 · 3 comments
Open

similey replacement & other text changes #4

ajorias opened this issue Apr 26, 2013 · 3 comments

Comments

@ajorias
Copy link

ajorias commented Apr 26, 2013

i'm enjoying jbbcode :)

i just had to hack the core for my needs to do some replacements on plain text. i had to parse such plain text to put in smileys and do some automagic link creation stuff.

for such i had to change TextNode like this:

    /**
     * Returns the text string value of this text node.
     *
     * @return string
     */
    public function getValue()
    {
        // I know, it hurts ...
        if ( get_class($this->getParent()) == 'JBBCode\DocumentElement' )
        {
            return nl2br(autoLinkUsers(parseSmileys($this->value)));
        }
        else
        {
            return $this->value;
        }
    }

if there is a cleaner solution to do this i would like to know. if not it may be good option to allow such stuff via an official api.

cheers,
alexander

@jbowens
Copy link
Owner

jbowens commented Apr 28, 2013

Hi Alexander,

It's not a perfect solution, but I recommend using a visitor. I just updated the source to allow visitors to modify the value of text nodes. I added an example visitor: https://github.com/jbowens/jBBCode/blob/master/visitors/SmileyVisitor.php

Since this involves actually modifying the text value of the node, it's not a great solution. Calls to Parser.getAsText() will yield html. I agree this is a place where the api should be improved. I'll think about it and post again later.

@ajorias
Copy link
Author

ajorias commented May 2, 2013

thanks for the heads up! I completely missed the visitor stuff and will give it a try now that you changed the core. i agree that the solution is still not optimal (html stuff returned by getAsText()).

initially i thought i would be able to register a pseudo CodeDefinition for "plain text" so i would be able to handle non-bbcode style transformations through it.

considering that TextNode plays an integral part and that it holds data for everything and of course should make no assumption about what type its parent is (as in my hack) I tend towards a solution where the caller is aware of the context for the stuff i need here.

considering on the other side that most of the parsed text will not have any bbcode it seems inefficent in terms of resource consumption and performance to create additional instances for plain texts.

maybe the option to register a callback to "postprocess" plain (non bbcode) text would be enough?

@prateem
Copy link

prateem commented Jan 1, 2014

Has there been any update about converting to smileys without having to use visitors to rewrite the actual text?

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

No branches or pull requests

3 participants