[Share code] MarkdownView
- Integrated markdown editing and HTML viewing modes - end editing and HTML is shown, click somewhere on the HTML text and markdown editing starts in the same position.
- Markdown editing supported by additional keys. (Thanks JonB for help on Obj-C.)
- Implements ui.TextView API for easy integration to existing code.
- Customizable through attributes or CSS.
Download (from Github) both the
MarkdownView.pyscript and this
readme.mdfile into same directory, and you can run the script in Pythonista to view and try out editing this readme file.
Import MarkdownView as a module and use wherever you would use a TextView. Markdown text can be set and accessed with the text attribute. Implement a delegate with
textview_did_changemethod to handle saving the contents - see the end of the MarkdownView.py file for an example.
@mikael , sorry long conversation on your share code. It went in a direction I didn't expect. But given I don't need editing this is great. The only bummer is that pygments is not a standard install for Pythonista
pygments is included in pythonista.
anyway, mikael MarkDownView is pretty neat. I really liked the use of the input accessory.
@JonB , well that makes sense. I hate making statements here. More wrong than right. I was sure I had checked for it, but maybe used a wrong case or something. But good to know it's included. I installed or reinstalled it using stash anyway 😱
@JonB , trying to create a small helper around pygments. Don't think it will be that useful to people, but will still share it when I am finished.
I know this sort of stuff you would just write inline, meaning you don't even have to think about it. But a lot of us, not there 😳
Anyway here is the gist
@Phuket2: no worries, you kept the thread visible for a while, and looks like some more people found the MarkdownView because of it.
@JonB: Thanks! I have been refactoring this a bit for a specific purpose, essentially splitting into two separate components, TextView for editing markdown and a WebView that can be touched and you get the corresponding caret position in the markdown text.
Plus I changed the implementation to be proxy-wrapped to get rid of manual relaying of properties and methods.
Plus used a swipe down gesture to hide the keyboard instead of a "Done" button (to get more room on the iPhone - plus, feels nice).
Let me know if these are of specific interest, and I will take the time to polish & document & publish.
But @JonB, where's pygments? Does it have some different name on Pythonista?
I do like the proxy wrapper - your previous post certainly opened my eyes on this subject, and will inform my own custom components in the future.
pygments should be in the standard library /site packages. import pygments should just work... at least in the beta version.
@JonB, no, no pygments here, and I think Sir Phuket did not find it either. Maybe we should put it on the wishlist.
@mikael Hmm, are you sure?
pygmentsshould be included, and I'm fairly certain that was already the case in version 1.5 (or even 1.4).
Pygments v1.6 has been in Pythonista for more than an year and is still in the current release and the current beta on 4 different iOS devices here.
https://github.com/cclauss/pythonista-module-versions/blob/master/pythonista_module_versions.py Click the History button and look at comments in the oldest version from 04 Jan 2015.
@omz and all: My mistake. I could not find any documentation and the code completion did not offer up "pygments" - but if I just import it and run the script, it works - so it must be there somewhere. :-)
The boy who cried wolf