Deprecated: Return type of I::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 62

Deprecated: Return type of I::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 91

Deprecated: Return type of I::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 71

Deprecated: Return type of I::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 101

Deprecated: Return type of I::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 53

Deprecated: Return type of Collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/collection.php on line 80

Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /home/public/kirby/toolkit/lib/url.php on line 135
One Tap Less | Opening Source Codes in Textastic

Opening Source Codes in Textastic

Hello there! I wrote a new version of this script that skips Pythonista. You should check it out here.

Textastic recently added a method to open the source code of any web page you're viewing in the browser right on the app. It involves changing the "http://" from the url to "textastic://" in the address bar manually. Wish I could use a bookmarklet to do it, but how to replace the values? Let's call Pythonista and see how it can help us.

First, let's create a document in Pythonista called Source2Textastic. Then paste the following code:

from urlparse import urlsplit
from webbrowser import open

textastic = 'textastic://' + ''.join(urlsplit(sys.argv[1])[1:])

open(textastic)

Allow me to explain a little bit. sys.argv[1] is the value brought from the external app via URL scheme. Since it is supposed to be an url, we're going to use urlsplit to break it into its parameters and place them in a tuple. Since the part we want to drop is exactly the first item of the tuple, we can join the url again and avoid the netloc in the way. This will generate your whole link, missing only your http:// or https://. Then we append the textastic:// to the url and voilá, you just gotta open it in the internal browser, as we do with open(textastic).

The final touch is, of course, finding a way to get the data inside Pythonista. This can be achieved with a bookmarklet. If you don't remember how to create one, bookmark any page and change its url to the following code:

javascript:window.location='pythonista://Source2Textastic?action=run&args='+encodeURIComponent(location.href)

Just activate this bookmarklet and the source code from your current url will open in Textastic. That's all for the day.