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

Original range of element #1

Open
ghost opened this issue Jan 9, 2013 · 4 comments
Open

Original range of element #1

ghost opened this issue Jan 9, 2013 · 4 comments

Comments

@ghost
Copy link

ghost commented Jan 9, 2013

Hi. Thanks for sharing this library. I'm loving it right now.

I want to find the original range of an element. That is - where the element that was parsed was found in the original piece of text.

Say you have this:

NSString *string = @"AND I NEVER THOUGHT [quote author=iffets12345 game=iffets12345 ]Haha, EXACTLY![/quote]";

You parse it with the parser and it returns an element.

Now I want to replace the original location of the element with some new text based on what I have parsed out of the element.

Can this library do anything like that?

Basically - I want to turn that original string into something like this:

AND I NEVER THOUGHT "Haha, EXACTLY!" - iffets12345.

@mrataj
Copy link
Owner

mrataj commented Jan 11, 2013

Hi.

You already have support for something like this. There is also a property named "format" in root element which is returned by the parser after you parse your string.

In your case it will look like this:
AND I NEVER THOUGHT {BB_0_BB}

All you have to do is to replace {BB_0_BB} with quote element's text, quotation marks and author name.

You can do this using regex expression:

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:[BBCodeParser tagRegexPattern] options:0 error:nil];

NSArray *matches = [regex matchesInString:parser.element.format options:0 range:NSMakeRange(0, [parser.element.format length])];

In matches array, there is a NSRange object, which tells you the range of quote element. You can use that range to insert text of a quote element into parser.element.text.

@ghost
Copy link
Author

ghost commented Jan 21, 2013

Ah yes thanks.

Also, it would be good if it supported BBCode like this:

[quote=harry]TEXT TEXT[/quote]

@mrataj
Copy link
Owner

mrataj commented Mar 2, 2013

I am not sure ... what if there would be more than just one attribute?

I can't find any bb code specification ... I guess everyone just makes his own ...

@mkloeppner
Copy link
Contributor

Hey I also love your library so far. Makes fun working with it.

But i also vote for supporting an element being an attribute:

"[quote=harry]TEXT TEXT[/quote]" mentioned by liamparker.

I created a pull request in order to at least recognize these tags: #3

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

2 participants