Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
UI TextView Individual Words
-
I am creating an app with Pythonista that lets you write Markdown, and preview it in a built-in browser, or in Safari. But I have been using Editorial for quite some time now, and it has the ability to (in the editor) show bolded text for individual words automatically while typing, even before previewing you get a basic idea of what it'll look like.
I want to do something similar in my app, with Pythonista. While typing the Markdown in the editor (which is a TextView), I want to automatically change fonts and sizes of individual characters and words, not the whole TextView's overall font and size.
Does this make sense to anyone? If so, please help me out here. I've tried a few ways to do this, but so far I am thinking it is not currently possible with Pythonista.
-
It can be done with objc, but this is not trivial, and prone to crashing if you are not careful. in objc this is called attributed text.
See the few files starting with attrib in
https://github.com/jsbain/objc_hacks
for some simple examples.ywangd implemented a very stable and robust implementation of ANSI color codes in stash.
What i would suggest is that instead of using a TextView, use a WebView. Since there are markdown to html converters readily available, it will be easier for you to understand and ultimately implement -- objc in python is not for the faint of heart.
-
😕 alright. Thanks for the information.
-
If you cannot get the text coloring to work, you might take a look at MarkdownView - the main goal there was to make the distance between viewing the HTML and editing in markdown as short as possible. And the additional markdown editing keys could be useful as well, even if you make your own editor.
-
@JonB thanks for the help. I will definitely check that out!
-
@JonB, I have followed your suggestion and tried WebView() for on-the-fly syntax highlighting using a <textarea> and a JavaScript editor like Ace or CodeMirror. The problem is that if you want to edit in place (as @AtomBombed describes), these libraries intercept the keyboard input on iOS, disabling autocorrect, which is a dealbreaker if you are writing prose/plaintext/Markdown/etc. I have not found a way around this. Are you aware of one, and/or has another solution emerged in the four years since this thread was opened?
-
Are you trying to write JavaScript? Or markdown?
Iirc markdown is directly support we in pythonista. For a programming language, I'm not sure that autocorrect is ever appropriate?
-
@JonB I have written a custom markup language for plaintext/prose writing, similar in function to Markdown, but much different syntax. So I am looking for a way to use both autocorrect and customized syntax highlighting.