Integrate markItUp! Into the Django Admin
What is markItUp?
markItUp! is attempting to be a universal markup editor that will support working with a variety of markup syntaxes. It is simple to setup and can turn any textarea into a full-fledged editor with just a few lines of code. They've also provided a lot of hooks to make it customizable so you can easily add new features or change the behavior. The documentation still needs a fair bit of work, but I was able to get it up and running by just poking around.
My motivation for investigating markItUp was that I realized a need to create some editing tools that would reduce the time it takes me to write posts and automate some of the styling that I like to use to highlight important keywords, people, and sites that I mention in my articles. But aren't markup syntaxes supposed to do this already? Yes they do, but it can still be tedious to manually add lot of links and add specific styling. Let me point out that my mindset with the creation of this blog has been to benefit from the learning experience. While I could of course use this, that, and the other tool/editor out there for building and managing my content, part of the enjoyment for me has been learning about the problem sets accompany publishing and content creation.
I think it is a common pattern for us custom blog builders to represent posts with an Entry model that contains two fields to hold the actual content. One field holds the "raw" content - typically in a markup format - and the other field holds the display content. Then we override the model's save method to process the markup content into HTML suitable for live content and stick that into the display field. So what I was looking for was an easy way to beef up the raw content field with some utilities so that composing entries would be a little easier.
I just happened to come across markItUp and was pleased to see that it would probably provide much of what I wanted and it looks like I'll be able to customize it to provide the shortcuts that are specific to my writing and styling preferences. I'm also a fan of jQuery. Obviously it would be preferable to just extend the admin since it's already so powerful so if I could just drop something in that would make editing a little saner that would seem to be a huge win.
Installing and Configuring markItUp!
I had a little confusion starting out because I followed the download link from the home page, which provides with you with the default set. markItUp uses the notion of "sets" to configure the specific markup language to work with. The default set is simply HTML. Once I found the downloads page I realized that I needed to also grab the Markdown set (my preferred markup syntax at the moment). From there installation proceeded well enough by combining referencing their sparse documentation with a few peeks into Firebug. In fact, I'm writing this post with the editor in place!
Extending the Admin
All we really need to do is drop a few javascript and CSS references and a little javascript snippet into the _
_ to turn our textarea field into a markItUp! editor. If you've never done any admin customization before, take a gander through the chapter in the Django book. I added a change_form.html template to /mytemplates/admin/article/entry. "mytemplates" is specified as a template directory in my Django settings, article is the app, and entry refers to the Entry model. The admin knows to look there first for any appropriate templates and load those rather its own template. Here is what my change_form.html template looks like:{% extends "admin/change_form.html" %} {% block extrahead %} {{block.super}} <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/markitup/markdown/style.css" /> <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/markitup/skins/markitup/style.css" /> <script src="{{MEDIA_URL}}js/jquery.js"></script> <script type="text/javascript" src="{{MEDIA_URL}}js/markitup/jquery.markitup.js"></script> <script type="text/javascript" src="{{MEDIA_URL}}js/markitup/markdown/set.js"></script> <script type="text/javascript" > $(document).ready(function() { $("#id_body").markItUp(mySettings); }); </script> {% endblock %}
A few notes:
-
The code snippet in the Django book does not include {{block.super}}. If you don't include this, then your change form won't pull in all of the helper scripts that provide some of the dynamic functionality you may rely on such as "pre-populate from". I don't know why they don't mention this in the book, but in most cases you'll probably want the admin to have the normal scripts available.
- The "markitup/markdown/style.css" comes from the Markdown set and it provides the styling for the Markdown-specific buttons on the toolbar. The other one comes from the default set and provides some of the basic styling for the editor regardless of what markup set you happen to be working with.
- I had to do a little find/replace on the css files to get the background image paths to match up to my configuration. The stylesheets assume that the images are all located in an images directory located at the root of the site. I house all my media (images,css,js) under a "site_media" directory and then I like to organize resources into subfolders so the markItUp! default scheme didn't work for me.
- The "set.js" comes from the Markdown set. The defaults worked fine for me just to get everything going and I added a previewParserPath (more on that in a minute).
- The little javascript snippet simply directs markItUp! to the textarea on the page and sets up the editor with the settings that are specified in "set.js". #id_body refers to the textarea corresponding to the body field on my Entry model.
This is all you need to do to get the editor working on a textarea on your admin change form page. The editor also has a "Preview" button (the checkmark) which will show the actual output in an iFrame below your textarea - a very handy feature! However you need to do a little extra work to have that functionality available.
Adding Preview Functionality
The editor will simply make an XHR POST with the markup content and dump the response back into the iFrame. So you just need to set up a view that will accept a data POST parameter, format it according to your preferred markup syntax, and return a full HTML page containing the output. Here is what a view could look like - add in your own exception handling and error checking to taste:
from markdown import markdown from django.template.context import RequestContext from django.shortcuts import render_to_response def apply_markdown( request ): markup = markdown( request.POST['data'], extensions=['codehilite'] ) return render_to_response( 'utils/markup/markdown/preview.html', {'preview':markup}, context_instance=RequestContext(request))
You'll notice that I pass the codehilite extension to markdown to handle making code snippets all nice and pretty. You may not need this in which case you can simply omit the second parameter. I am using a RequestContext since I would like access to the MEDIA_URL in the template. This makes it easy to include the special stylesheet utilized by codehilite in a portable manner (syntax.css). Here is the template:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang="en"> <head> <title>Markdown Preview</title> <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/syntax.css" /> </head> <body> {{preview|safe}} </body> </html>
The last thing to get this working is to add the path to your view in the previewParserPath in the set.js. Now you can simply hit the Preview button and get an idea of what your final output will look like. One minor annoyance is that once the Preview iFrame is open there does not appear to be an easy way to close it and what will happen is that as you continue editing your markup the iFrame will refresh whenever you hit Enter.
Conclusion
One issue worth a little attention is that if you are using the built-in development server to serve media with the Django static media view, adding in the markItUp! editor will add a lot of overhead since it pulls in a few extra javascripts, a few extra CSS files, and fair amount of small graphics to provide the toolbar. As the Django documentation clearly states, the development server was not designed with media serving in mind. You may find that your admin pages bog down quite a bit on loading. If this bugs you, I recommend taking a few minutes to set up a local media server for yourself. That way you'll get the benefits of the debug environment combined with the snappy performance of a dedicated file server.
markItUp! has already provided some tangible benefits to my work flow and I am looking forward to doing some further customization to make it even more useful. In a future article I plan to cover any useful bits I come across. markItUp! may not be for everyone. In particular there are some known issues with how Safari handles events on Ctrl and Shift keys. Also, this is still beta software so use at your own risk. As I mentioned, the documentation could benefit from a little more detail and some more code examples.
<< Back to Unbracketed Home Post a Comment Now 121 Comments Below
Comments
Post a comment
- Markdown syntax is allowed. HTML tags will be stripped.
- CodeHilite NOT supported at this time but coming soon...
- Constructive statements and good attitudes are encouraged - being kind is better than being right



bob
fJhYJM hi nice site thanks http://peace.com
vAlhIuPKNZEcyz
C4kyhv
lola
interesting post thx
liza
nice work man 10x
teen pink
cool post dude thx )) teen thongs
peeing teens
cool site thanks teen pics
teen pregnancy
great work man 10x teen topanga
preteen models
interesting site bookmark you joel olsteen
amateur teen
nice site cool work thx japanese teens
black teens
cool idei thanks ) preteen cp sites
hardcore teen
thanks great site teen adorables
hot nude teens
sweet site dude )) i love u preteen underwear models
teenage
gdfsgs gafDASF FGDF GGDF free hardcore teen sex pics
teen gallery
gdfg gdfsg gdfg gdsfg pre teen schoolgirl gallery
stories sex
gfdgs gsafds fgfdsghf asfsd teen naturalist galleries
hentai
fghdgfjh gsdgs ggjg gdfgds gdf teens gallery
male models
gfdhf adgsgds asf dasfs gdfg hot young girl teen
teen clips
gdfg hgfhdfh gdfg gdfghdgf gfdh dsgdfg teenier inset
celebrities nudity
hjhgdf gfhf gdfhgf dghfh hgfh darks lolita teens
teen games
gfdg sdg gdfh gh gfhdgfjh dfg dgfhg teen boy idols
teenagers
gdfggf sdfd hgfh ghfh gdfd g shower teen
teens abusive
hfh fgdfg hgfj dhdfh dfhgf gfh teen bisexual orgy
nonnude
tdtreyh gdfg gdhjdf hgfhf sagdh dfhdf preteen labia
naghty teen
ghfj ghff fdghjhdgfhgfd dfsgdf ghgfh german teens
gay teen
gdfgd gfhfgh fdsgdf gdfh ggfh preteen model toplist
russian sex
gfdg ggfhj fsdg hgf dghfgh gfdg monologues for teen drama classes
eighteen
ytrui gf gdfh dhgdghgjfjdfg hgfh teen nudity beach photo gallery
top and mini
dfgfj gfhdf dsfgdsfh jhgfjhg fg h smallest pussy lolita
sex girls
dfgsd hgfj sdfgdfg hgfh hdgfh lolita model nude
nude
gdfgs dgfh gdsfgdf fgd gdfg dsdgfh sexy lolitas
bred
hello everybody! purchase ativan >:-OOO
kate
cool site man cheap propecia emlt
joseph
sweet site thx buy soma 351046 propecia pills 973805
sylvia
please look at this ativan addiction %-DD
adult
hi nice site thx cheapest soma >:-P
mona
hi great site 10x order soma 310519 ultram sjle
james
cool site man order ultram gara
lola
please look at this purchase diazepam edgu
bob
great work man thx buy valium :)) ultram addiction >:D
kris
please look at this diazepam addiction 36271
joseph
sweet site thx order valium vxslke
mona
it's nice site!!! levitra no prescription 5285
kris
hello everybody! levitra pills =[
bred
see this thanks viagra pills 715803
john
it's nice site!!! generic lipitor imfb
bob
cool post dude viagra alternative 5029
john
it's nice site!!! lipitor addiction dtshpb
bob
good post man thx xanax no prescription cew
john
nice work man 10x xanax pills axwlkz cheap xanax 6922
Utyyztfq
cool site man amateur sex video %-)) sex photos :[[[ free adult video fcrdpf adult porn wjui adult friend finder nkkpo worldsex 123 amateur sex 70298 free adult movie 8-OO amateur porn 405 adult gallery >:[[
Zntochtb
very best job nakedfeed %-[ smalltits 8DD xxxmoviemart 37961 bangla sex =((( ultrawiredsex cbbyot xxx thumbnails feli ratemytits syfmnf 8teenporn 003 ultrapornstars dmxjry 24hrsfreeporn 60663
Biwarswk
cool site 10x sexy japanese lesbian 8( vixena 7235 iloveinterracial 42296 sexhungrymoms 8] teen model kzoqyk adult 09308 directsex llkr seks 764022 mom mature son gallery >:-D kaktuz fkrew
Qjzxcmgs
hi nice site thx small.pussy ffnmti sexual movies porn 411645 sexy teens adx sexsearch 8[ sologals rmarh sexycollegegirls jjg sexy ladies 6866 sexmachines.cum vrls teenel int small tits 320
Odphkekg
bookmark you thx teensluts kwbcah tittys vjauyw webcamnow %( transexuals 7121 videosex 92398 underage lolitaz girls xxx :]]] teenporn =) xxxstash cajn vladmodels hddey too young porn 4540
Cniernqq
hi great site 10x free porn pic dskegr free xxx porn 3987 free porn video qjwvq free porn npohl indian porn 19059 home porn >:-P free porn vids 360 free lesbian porn bzec kim possible porn 175026 hard porn 686
Gknbfjwx
Cool site goodluck :) youamateurporn gnzz sexcams 1834 bigboobpass 87627 softporn 8793 transsexuals 8-P nakedsword 3608 pussypictures 816487 gaydonalds =( cumsuckers 2265 gigantits oieai
Dhwkpmot
great work dude thx teenpussyorg =[[[ adulthumor >:-DD preteen angel %))) free mature couples >:O sisters hot friend >:-[ freeporngraphy %O gay sex toy pmc mandingo anal 212693 virginal sex mtcg hardcore anal 008
Vgfgtpgt
hi great site 10x blackgaychat 720157 bigblacktits :-[ black mature wzkhs blackcocks :-DDD cfnm utce big cocks =-((( big clitoris 8-PP clubseventeen :-[ big asian tits 529 boobfilter 847058
Tiliqjld
bookmark you thx bikini babes ierefb sex toons mnqnix world sex 8-DD teen anal :D bikini dare qsffzz sex slave %-(( ebony ass 1690 sex video 8393 8th latinas street >:-]]] thong bikini >:OOO
OFKsTMZzttvRqaLwFuC
tickets_3.txt;2;2
Heglwtba
Best Site good looking teens prelolitas 191 pantypoop fuv preteenporn 388 preteen lolitas bbs :-]]] little lolitas models :( sexdy little lolitas twy wordlsex vjcot little naked lolitas 912 disneyporn 1721 little models lolitas =]
vFMdGDaVjFstQQ
tickets_4.txt;2;2
Phpxhpyp
bookmark you thx girl webcam :((( adult add znshju sexy legs 664870 young teens fijzen gay pron :-O query %-O beast sex =-[[[ latina porn 014814 petite teens jnysgm nude celebritys :]]]
hlESKJZmdFuLhZ
tickets_5.txt;2;2
Tdeaivde
hi nice site thx interracial sex 137546 hot sex zussrb henati 8((( lolita picture 373370 jays xxx 386 lesbiantube 357732 latinpussy %-P lolitampegs xvlo illegal porn noeho lolitasex cwgvs
Zlurmemo
Best Site Good Work preteenies =-)) little young teen lolitas dvglnt ls magazine bbs lolita porn 8[[[ little lolitas naked 1938 maturezzzone idjk dark portal-preteen 722316 lolitaporn >:-DD hotteen zpeia preteen lolita bbs image boards 8[ legal lolita porn sites ijzdq
Vmuyfqwz
this is be cool 8) little lolitas photos xoeuhe russian little lolitas bbs ls bd 837 preteen lolita nude models >:OO meporn ltjz nude preteen nymphets dpd nudephotos %OOO teenforcash 0935 preteenssex =-((( porno korean flrn little lolitas pussy qpu
Cimuekhr
Cool site goodluck :) dorki preteen jld teen pronography wtd 18teen osl sexyoldwomen gemtwc freeteenpics 816723 gloryhole 06799 preteens lolitas nymphets models 0348 euro preteen lolita 8330 lolita teen porn bbs >:-)) teenporno fbnbpw
Cnuqccab
hi nice site thx preteen pix hqoty scooby doo hentai 954372 preteen cp 914 qporno 046558 preteen nude loli =OO preteen uyuur prelolitas van selfsuck :O preteensex 7785 preteen girl %D
Ycbnoetp
nice work man 10x big dicks pictures 960 free lady sonia mpng women having sex with dogs ehxaow blackpussy zbtj pornoamateur 33242 horse sex tvsbm pictures porno 210187 pornoxxx 8))) porntube 002 free horse sex trailers =D
Myzakopz
bookmark you thx ywebcams 940306 movieshark ejjlk tekken =]] dick blick bpvyix nudeography =-[ anal 8O erotic biyn xxxrated 6578 givemepink fkdw sexy graphics keac
Uluvqjmq
Thanks funny site preteen underwear model =-]] lolitasxxx =(( nnteens >:))) teen puusy vvoh sexy nude teenes %-))) sexyteen 579083 mclt preteen sex wmrbqd teenboy ohgllb seannateen 422503 teendreams 7784
Uakgsrpj
interesting site man sexstory 020 sexteens ykywp shemale hardcore 68314 sexclips 489382 sexolandia >:-(( suck my dick %((( sex toons jhwqjw sexyandfunny 617 sexy mature women 084357 sexpic udyf
Yzaebxpr
sweet site thx family guy porn 141 lolita sex =[[[ free celebrity nudes wphjyz hardcoresex 827946 bangbus 2076 the hun yellow pages >:) preteen nude models 417592 lolitas 7041 lick pussy 712330 cliphunter tcpmj
Hoqiuzby
very best job imgboard preteen :) little sun lolitas bbs sfvr littleteen sex 29234 little cute preteen models 7922 hot preeteen models 9435 gayteen studio 742315 gay preteen underwear photos 2322 lolitas bbs little lolitas :-] little lolita top porn 344 lol rompl bbs teen pkkg
Dipmmfsz
cool site man pinkpornstars kgjved gaybeef eoog sexyteens vhzu sexpictures 664 monstercocks zoljq hard core sex 8-P teen titans hentai haebxr wwwsex 1661 nudewomen :]] hard sex 8659
Spzosdze
Very funny pictures nu preteens doh porn pictures of young illegal preteens 8OOO manias blue teen links bdbaca pokemonsex xdpixo nonnude preteen models =-) preeteen list 220 lolitas little kides sex uxhim porn lolita 886155 preeteen non nude pictures gcr nn pre teen models >:-D
Sfgyeuyc
cool site 10x yuporn 5639 sexvedio 503841 pussyplace lkfkn adultfriendfiender %))) babygotboobs %[ animalporno aqsgif pussygalore tfpru pornput =-[ amateurcurves 355 youporno :(((
Lromknyf
magic story very thanks teenie pussie ehjac smallpussy 795226 teen18 %P underage preteen links %-] underage illegal lolita porn ucezal teen\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'spussy =-D very little illegal lolitas deg sexy preteens bbs 070 very young forbidden lolita porn picks 388244 teens in tights revt
Itxdxsox
real beauty page young preteens in bikinis 4834 young asian preteens mgbw young japan incest preteens =OOO very young preteens naked 8O young preteens nude models muibql very young girl preteens hktkrz sexygirlschannel :]] exploitedteens pjfuf young preteens naked 085 young hot preteens =[[
Rykcypcq
good work man non nude teen models 7779 pedo stories %[[[ melissa midwest hardcore videos %-[[[ pink pussy 8-[ maturesex 288 porneskimo >:-[[[ lolita bbs lfn preteen models 2887 pokemonxxx 04152 momsonsex 407
Dthictld
Gloomy tales freesexcams wkcxrw preteen lolita art fhjzq lolitas little angels >:-[[[ pregnantsex 48323 lolita preeteen boys pictures wwxh top 50 preteen models 814803 little love lolitas pics dhca teensexy com 522 sexywoman 24106 alt.binaries.pictures.erotica.pre-teen hsjz
Skkfvkhv
good site dude monster cocks pictures 8D preeteen 8-))) naturist preteen 8-[[ pussylicking =-D qmov hfwnke pinkpornstar pvks sexual abuse dgqdgr sexpussy csqvz preteen pussy 704024 megaporndump 25980
Xpovyawg
free easter skits for teens vwv pedo teen girls %[[ preteenpreteen hygth young preteens having sex uujg preteengallery >:[[[ blue-teen link 963 free movie wifeys world >:(( amatuer teen twinks schoolboys tgp optgyn preteens young underwear 2580 interracialsex fuunzt
Eqxzxyes
nice site dude teens for cash 357 young girls 71901 street blowjobs 96684 underageporn 1777 offlolita 96841 southerncharms 56966 superzooi 69038 sexylingerie >:DD xxxteens 8))) hotporn 655
Jrvufumz
bookmark you thx pornvids :) pornofilia 750331 pornspinner 5577 redheadsex 034553 pornvue 8-[[ porno =-D preteengirls rcqjr porntower 286 sex89 33809 pornorama 33538
Txuhigdu
good work man filipino sex ojqdi maturecharm tqzvbg myfriendshotmom asofpy teenass xxem cock and ball torture >:[[ pornpic nfl sexo :-O midgetporn >:-((( screech sex tape 721086 freegaypics 0236
Wainlvju
good job man sexinpublic 8PP sexkorea nxnake sexnhumor 671 sexphotos tbwkj sexview 7822 sextasya 8-O sexswan xwlon sexpicture 8-OO sexoasis 35785 sexfilm bbk
Pxyohhuj
cool site 10x teenboys khyc sunporno 0656 unreal boobs :-] xxx :))) sleepingsex yhs sexyfilm 0380 sexy 8819 xxxpictures xtjqbj xxx 89 clips %-( teenah jpcn
Msfsxtah
best work man great castingcouchteens :))) 8teen 8OO teensfromtokyo 508 hugepussy 097530 sexcom gljgp sexsy gazggd xxxxx >:[[ bigtitsatschool 541464 sexgirl 831 animalsexmovies 08684
Ludsmlne
bookmark you thx anal sluts 929656 free lesbian stories 020625 gaydemon 8-((( magicteapot 008547 freeblowjobs pdt hot milf 237941 swingingheaven 0501 horror gay rape pictures 55846 largecocks gvcik teenwhores %(
Tviajsmv
Good crew it's cool :) gayhentai %] myfirstsexteacher =-[[[ asiananal 363 tranysex %-DDD sex positions >:]] sexygaymes 569 grannytits nvoi alfasex 846700 virginpussy 3464 preteen models search engines teby
Vhquceut
hi nice site thx blacktits 8]] freedailyporn 0988 eroticstories :) anywebcam =-((( my first sex teacher 189172 pornoamateurs %-[[ kind girls :-[[[ livesexlist 623 dildo bike sqsuv internationalsexguide 6375
Jzjqjquc
this is be cool 8) gayboy 8[ preteens models 1867 farmanimalsex kzusn sexaben 54285 creampiethais zqzxrt hotboobs 8175 moviexxx giiys eonsex ravk analteens aayjo 3gp video clips free download 715044
Prajlwhh
cool site man younge nude girls %-OOO welovecock 4063 zoo sex oivehr anime sex gtybq arabicsex 8PP ashley gellar nude dmsqio youramateurporn wnznlk zoophilie =-[[[ big butts 71318 www sex com %-O
Oswsiisu
nice work man 10x vanessa hudgins nude photos >:OOO simpsonsxxx nslzpr amateursgonewild rizrqx freebigmovies 379 rough sex 273 sun lolita tqag oldersex 464602 pissing :-OO free adult pics 8-DDD teen thong pics 4074
Ygmycfsi
see this thanks freaksofcocks 654651 ebony blackhoes 8))) fatpussy 197765 free nude teens tmop free nude women 8) ebonysex vui free tranny porn oxe dickgirl 550123 freeanimalsex 7501 eskimoporn 231634
Upuahqxs
It's serious sexypics wicjlz freehardcoreporn >:( gangbangers >:OO freelivesex >:-PP fatblackpussy 52362 12yo lolitas porn indian girls 8830 eurosexparty =-PP pornopat =-( teenanal 9925 sexylegs %(
Ocqxzczx
Hello good day porno sites %(( vintageporn aufsli lolita free nude preeteen art wqxfcb prettypussy %-[[[ analsluts 558167 nicetits :OO smallboobs 107269 naked little lolitas =-PP matures 92598 pree teen nude pics mesksh
Gvoscymr
hi nice site thx http://google.us/group/cteens 8teenboy =))
Abrpzaba
nice site dude http://google.us/group/dteens younger teens 8)))
Sczejuab
good post man thx http://google.us/group/bteens pre teen bikini models 51664
Nbzprywl
It's serious http://google.us/group/qteens sweet sixteen themes wlkru
Tjpbtkat
cool post dude http://google.us/group/hteens extreme teen video xxx %[[
Nptrtxxn
It's funny goodluck http://google.us/group/wticket last minute tickets iaau http://google.us/group/qticket disney tickets =-)))
tube8
good work cool site thanks ww you tube8 com
pornhub
beautiful site thx sites like pornhub great...
sextube
cool post dude thx =) youporn sextube
xtube
nice thanks man www xtube colm
uporn
wow cool interesting site 10x uporn tube
youporno
nice work man 10x www youporno tv com
youporne
great post thx see u www youporne copm
nexxx
hi it's jessy cool site thx :) www nexxx
redtube
wow interesting site thx www redtube c see later
porntube
thanks cool post adult porntube
youporn
hi nice thanks =) www youporn com top_rated
porn hub
cool site dude 10x japanese porn hub
tube
wow cool post dude thx tube 8 map london
boob tube
fdsfdasfsd evacuated tube hot water fdsfgdsfg zootube co
hqtube
best site man see u hqtube com main
pornotv
hi it's britney thx :) see u pornotv blogspot