|
|
#1 |
|
parsing text similar to markdown
I'm gonna try and create a simple iOS text parser, nothing complicated at all, I need it to be customisable, thats the reason I'm attempting this.
A markdown parser is great, but its meant as a publishing tool and is too extensive. I want something very similar in concept, Forexample, Consider a text file with: Code:
A paragraph with with title with maybe a couple of lines without a title.
Title
-----
A paragraph with a title.
Title
-----
A paragraph with a title, this also includes bullet list.
1. item0
2. item1
3. item2
My question is, whats the best way to parse these items? How can I: 1. Separate each of those paras into items. 1. Check if item has a "title" 2. If it does, Separate the "Title" and paragraph text in each of those items. Any comments is very very appreciated. |
|
|
|
0
|
|
|
#2 |
|
I'm not quite sure I understand what you're looking to do, but I think NSString's componentsSeperatedByString: method will prove useful to you.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed. Like it on Facebook! |
|
|
|
0
|
|
|
#3 |
|
APIs to use for parsing something like this include:
Code:
NSScanner NSString enumerateLinesUsingBlock: NSString componentsSeparatedByString: NSString componentsSeparatedByCharactersInSet: |
|
|
|
0
|
|
|
#4 |
|
Also remember that iOS now has regular-expression support.
|
|
|
|
0
|
|
|
#5 |
|
Thanks for the input guys,
I got the basic idea, I'm wondering if thats the right way to go. Code:
NSScanner NSString enumerateLinesUsingBlock: NSString componentsSeparatedByString: NSString componentsSeparatedByCharactersInSet: 1- Find sets of paragraph, Divide paragraphs - [separated by string: @"\n\n"]; 2- Go over each paragraph, check if @"\n---" exists, if it does, strip out title and text below it. 3. if the text has numbers with a period and a return @"\n" preceding it, and lots of them, its a numbered list, capture em, put them in an array. Pretty much possible, except when the text does not follow specific pattern, which is pushing me toward NSRegularExpression as dejo rightly mentioned. Any good guides on NSRegularExpression? Its really hard to understand. |
|
|
|
0
|
|
|
#6 |
|
If Markdown is too much, would you consider just using a subset of it? Or perhaps another markup syntax like Textile?
I really think that by rolling your own markup syntax and parser, you're unnecessarily complicating things and trying to solve a problem which has already been solved many different ways. Let the inevitable edge cases be somebody else's problem.
__________________
Garrett Albright - The Tokyo Drupal guy! |
|
|
|
0
|
|
|
#7 | |
|
Quote:
Textile is exactly what I need, However, I cannot find an ObjC library. |
||
|
|
0
|
|
|
#8 | |
|
Quote:
http://stackoverflow.com/questions/2...in-objective-c Edit: Although the link seems to be broken?
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed. Like it on Facebook! |
||
|
|
0
|
|
|
#9 |
|
Well, the whole point of me doing this was Not to use a UIWebView. The data type didnt really require it.
|
|
|
|
0
|
|
|
#10 |
|
And we were supposed to know this how?
__________________
|
|
|
|
0
|
|
|
#11 |
|
|
0
|
|
|
#12 | |
|
My bad, should have made it clear before.
Quote:
Like if i can recognise a bullet list from a textfile, I can create an NSArray out of it, and use it in a uitableview. |
||
|
|
0
|
![]() |
|
| Tags |
| ios, markdown |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 08:19 PM.







I support the 
Linear Mode
