Open chrisamanse opened 8 years ago
Salut! I think it's more of HTML tags rather than "custom" tags, since the syntax, apart from the {}
, which ordinarily should be <>
, is HTML. We went with {}
, because we're already using XML, which uses <>
. So to avoid getting our parser confused, we kept using <>
for XML and {}
for the HTML tags.
I would think that iOS would have libraries to parse embedded HTML in Strings just like in Android.
Html.fromHtml(String)
If so, it would resolve the other HTML tags issues that occur due to this. For example...
Merci beaucoup toujours!
Updated the title. How did you implement this in Java? Did you first convert the {}
characters into <>
, then run the HTML parser?
If so, this may be our solution: http://stackoverflow.com/questions/4217820/convert-html-to-nsattributedstring-in-ios
Salut! Oui, exactement! I instructed UsbongKit (Android) to modify the {}
characters into <>
, and then run the HTML parser.
However, I also have it do other things such as for custom tags that are not recognized in HTML. For example, processing indent, i.e. {indent}
, which is equivalent to 5 spaces. UsbongKit (Android) also does store
and load
of variables.
Having said this, getting UsbongKit (iOS) to parse even just HTML tags for the time being would be a significant improvement.
You can find the actual method I use, i.e. public static String applyTagsInString(Activity a, String myCurrUsbongNode) {
, on line 1949.
https://github.com/usbong/usbong/blob/master/src/usbong/android/utils/UsbongUtils.java
Merci beaucoup!
Thanks, @masarapmabuhay!
Here is the location of where the parsing of the text occurs in UsbongKit iOS: https://github.com/usbong/UsbongKit/blob/master/UsbongKit/Usbong/UsbongTree/UsbongTree.swift#L569-L575
While it is possible to use the function stringByReplacingOccurrencesOfString
on the text multiple times for custom tags such as {indent}, this may affect the performance every time a text is loaded, since it is O(n)
complexity every time stringByReplacingOccurrencesOfString
runs. I haven't tested this yet, so let's try this solution first and see if the performance is okay.
Salut! I can understand your concern. However, the string is not really supposed to be long. While the screen is configured to allow scrolling, our goal is not to put a massive amount of text on only one screen; rather, it is to divide the text into several screens. Therefore, although the complexity to run stringByReplacingOccurrencesOfString
may indeed be as you say O(n)
, the size of n
would hardly reach 1000 words, let alone 100 words. Merci bien!
Parse custom tags such as
{font color='#5e5c5b'}
. Suggested by @masarapmabuhay in usbong/LIKHA-Guide#12.