# Source

 Carl Meyer 9388440 2010-01-28 Carl Meyer 771c113 2011-07-12 Carl Meyer 9388440 2010-01-28 Carl Meyer 771c113 2011-07-12 Carl Meyer 9388440 2010-01-28 Mikhail Korobov fdd0099 2011-02-25 Carl Meyer 9388440 2010-01-28 Carl Meyer 771c113 2011-07-12 Carl Meyer 9388440 2010-01-28 Carl Meyer 771c113 2011-07-12 Carl Meyer 9388440 2010-01-28 Mikhail Korobov 137b8f6 2011-02-25 Carl Meyer 9388440 2010-01-28 Carl Meyer 0a4001d 2012-03-04 Carl Meyer 9388440 2010-01-28 Mikhail Korobov 137b8f6 2011-02-25 Carl Meyer 9388440 2010-01-28 Carl Meyer 0a4001d 2012-03-04 Sergey Fursov a6903a3 2012-03-03 Carl Meyer 9388440 2010-01-28 Mikhail Korobov 137b8f6 2011-02-25 Carl Meyer 9388440 2010-01-28 Carl Meyer 3be618c 2011-11-26 Carl Meyer 9388440 2010-01-28 Carl Meyer 771c113 2011-07-12 Carl Meyer 9388440 2010-01-28 Carl Meyer 3be618c 2011-11-26 Carl Meyer 9388440 2010-01-28 Carl Meyer 3be618c 2011-11-26 TakeruWolf 37f23dc 2011-11-26 Carl Meyer 9388440 2010-01-28 Carl Meyer ce853ec 2010-03-24 Mikhail Korobov 137b8f6 2011-02-25 Carl Meyer ce853ec 2010-03-24 Carl Meyer 9388440 2010-01-28 Carl Meyer 0121d7c 2011-07-12 Carl Meyer 9388440 2010-01-28 Carl Meyer 771c113 2011-07-12 Carl Meyer 9388440 2010-01-28 Carl Meyer 771c113 2011-07-12 Carl Meyer 9388440 2010-01-28 Carl Meyer 0a4001d 2012-03-04   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 =============== django-markitup =============== A Django reusable application for end-to-end markup handling. Includes: * Easy integration of the MarkItUp!_ markup editor widget (by Jay Salvat) in Django projects, with server-side support for MarkItUp!'s AJAX preview. Plug in MarkItUp! via form widget or template tags. * MarkupField, a TextField that automatically renders and stores both its raw and rendered values in the database, on the assumption that disk space is cheaper than CPU cycles in a web application. .. _MarkItUp!: http://markitup.jaysalvat.com/ Installation ============ Install from PyPI with easy_install or pip:: pip install django-markitup or get the in-development version_:: pip install django-markitup==tip .. _in-development version: http://bitbucket.org/carljm/django-markitup/get/tip.gz#egg=django_markitup-tip To use django-markitup in your Django project: 1. Add 'markitup' to your INSTALLED_APPS setting. 2. Make the contents of the markitup/static/markitup directory available at STATIC_URL/markitup; the simplest way is via django.contrib.staticfiles_. 3. Set the MARKITUP_FILTER setting_. 4. If you want to use AJAX-based preview, add url(r'^markitup/', include('markitup.urls')) in your root URLconf. .. _django.contrib.staticfiles: https://docs.djangoproject.com/en/dev/howto/static-files/ Dependencies ------------ django-markitup 1.0 requires Django_ 1.3 or later and Python 2.5 or later. The 0.6.x series supports Django_ 1.1 and 1.2; it is missing 1.3-compatibility additions but otherwise has feature-parity with 1.0, so remains a fine choice for older Django versions. MarkItUp!_ is not an external dependency; it is bundled with django-markitup. .. _Django: http://www.djangoproject.com/ Using the MarkItUp! widget ========================== The MarkItUp! widget lives at markitup.widgets.MarkItUpWidget, and can be used like any other Django custom widget. To assign it to a form field:: from markitup.widgets import MarkItUpWidget class MyForm(forms.Form): content = forms.CharField(widget=MarkItUpWidget()) When this form is displayed on your site, you must include the form media somewhere on the page using {{ form.media }}, or the MarkItUpWidget will have no effect. By default {{ form.media }} also includes the jQuery library based on your JQUERY_URL_ setting. To prevent including jQuery, set the JQUERY_URL_ setting to None. MarkItUpWidget accepts three optional keyword arguments: markitup_set and markitup_skin (see Choosing a MarkItUp! button set and skin_) and auto_preview (to override the value of the MARKITUP_AUTO_PREVIEW_ setting). To use the widget in the Django admin:: from markitup.widgets import AdminMarkItUpWidget class MyModelAdmin(admin.ModelAdmin): ... def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name == 'content': kwargs['widget'] = AdminMarkItUpWidget() return super(MyModelAdmin, self).formfield_for_dbfield(db_field, **kwargs) You can also use the formfield_overrides attribute of the ModelAdmin, which is simpler but only allows setting the widget per field type (so it isn't possible to use the MarkItUpWidget on one TextField in a model and not another):: from markitup.widgets import AdminMarkItUpWidget class MyModelAdmin(admin.ModelAdmin): formfield_overrides = {models.TextField: {'widget': AdminMarkItUpWidget}} If you use MarkupField_ in your model, it is rendered in the admin with an AdminMarkItUpWidget by default. Using MarkItUp! via templatetags ================================ In some cases it may be inconvenient to use MarkItUpWidget (for instance, if the form in question is defined in third-party code). For these cases, django-markitup provides template tags to achieve the same effect purely in templates. First, load the django-markitup template tag library:: {% load markitup_tags %} Then include the MarkItUp! CSS and Javascript in the of your page:: {% markitup_media %} By default the markitup_media tag also includes jQuery, based on the value of your JQUERY_URL_ setting, with a fallback to the version hosted at Google Ajax APIs. To suppress the inclusion of jQuery (if you are already including it yourself), set the JQUERY_URL_ setting to None. If you prefer to link CSS and Javascript from different locations, the markitup_media tag can be replaced with two separate tags, markitup_css and markitup_js. markitup_js accepts a parameter to suppress jQuery inclusion, just like markitup_media. (Note that jQuery must be included in your template before the markitup_editor tag is used). Last, use the markitup_editor template tag to apply the MarkItUp! editor to a textarea in your page. It accepts one argument, the HTML id of the textarea. If you are rendering the textarea in the usual way via a Django form object, that id value is available as form.fieldname.auto_id:: {{ form.fieldname }} {% markitup_editor form.fieldname.auto_id %} You can use markitup_editor on as many different textareas as you like. markitup_editor accepts an optional second parameter, which can be either "auto_preview" or "no_auto_preview" to override the value of the MARKITUP_AUTO_PREVIEW_ setting. The actual HTML included by these templatetags is defined by the contents of the templates markitup/include_css.html, markitup/include_js.html, and markitup/editor.html. You can override these templates in your project and customize them however you wish. MarkupField =========== You can apply the MarkItUp! editor control to any textarea using the above techniques, and handle the markup on the server side however you prefer. For a seamless markup-handling solution, django-markitup also provides a MarkupField model field that automatically renders and stores both its raw and rendered values in the database, using the value of the MARKITUP_FILTER setting_ to parse the markup into HTML. A MarkupField is easy to add to any model definition:: from django.db import models from markitup.fields import MarkupField class Article(models.Model): title = models.CharField(max_length=100) body = MarkupField() MarkupField automatically creates an extra non-editable field _body_rendered to store the rendered markup. This field doesn't need to be accessed directly; see below. Accessing a MarkupField on a model ---------------------------------- When accessing an attribute of a model that was declared as a MarkupField, a Markup object is returned. The Markup object has two attributes: raw: The unrendered markup. rendered: The rendered HTML version of raw (read-only). This object also has a __unicode__ method that calls django.utils.safestring.mark_safe on rendered, allowing MarkupField attributes to appear in templates as rendered HTML without any special template tag or having to access rendered directly. Assuming the Article model above:: >>> a = Article.objects.all()[0] >>> a.body.raw u'*fancy*' >>> a.body.rendered u'

fancy

' >>> print unicode(a.body)

fancy

Assignment to a.body is equivalent to assignment to a.body.raw. .. note:: a.body.rendered is only updated when a.save() is called Editing a MarkupField in a form ------------------------------- When editing a MarkupField model attribute in a ModelForm (i.e. in the Django admin), you'll generally want to edit the original markup and not the rendered HTML. Because the Markup object returns rendered HTML from its __unicode__ method, it's necessary to use the MarkupTextarea widget from the markupfield.widgets module, which knows to return the raw markup instead. By default, a MarkupField uses the MarkItUp! editor control in the admin (via the provided AdminMarkItUpWidget), but a plain MarkupTextarea in other forms. If you wish to use the MarkItUp! editor with this MarkupField in your own form, you'll need to use the provided MarkItUpWidget rather than MarkupTextarea. If you apply your own custom widget to the form field representing a MarkupField, your widget must either inherit from MarkupTextarea or its render method must convert its value argument to value.raw. Choosing a MarkItUp! button set and skin ======================================== MarkItUp! allows the toolbar button-set to be customized in a Javascript settings file. By default, django-markitup uses the "default" set (meant for HTML editing). Django-markitup also includes basic "markdown" and "textile" sets (these are available from the MarkItUp site _), as well as a "restructuredtext" set. To use an alternate set, assign the MARKITUP_SET setting a URL path (absolute or relative to STATIC_URL) to the set directory. For instance, to use the "markdown" set included with django-markitup:: MARKITUP_SET = 'markitup/sets/markdown' MarkItUp! skins can be specified in a similar manner. Both "simple" and "markitup" skins are included, by default "simple" is used. To use the "markitup" skin instead:: MARKITUP_SKIN = 'markitup/skins/markitup' Neither of these settings has to refer to a location inside django-markitup's media. You can define your own sets and skins and store them anywhere, as long as you set the MARKITUP_SET and MARKITUP_SKIN settings to the appropriate URLs. Set and skin may also be chosen on a per-widget basis by passing the markitup_set and markitup_skin keyword arguments to MarkItUpWidget. Using AJAX preview ================== If you've included markitup.urls in your root URLconf (as demonstrated above under Installation_), all you need to enable server-side AJAX preview is the MARKITUP_FILTER setting_. The rendered HTML content is displayed in the Ajax preview wrapped by an HTML page generated by the markitup/preview.html template; you can override this template in your project and customize the preview output. .. note:: Using the MarkItUpWidget or markitup_editor template tag will automatically set the previewParserPath in your MarkItUp! set to reverse('markitup_preview'), if markitup.urls is included in your URLconf. The MARKITUP_FILTER setting =========================== The MARKITUP_FILTER setting defines how markup is transformed into HTML on your site. This setting is only required if you are using MarkupField or MarkItUp! AJAX preview. MARKITUP_FILTER must be a two-tuple. The first element must be a string, the Python dotted path to a markup filter function. This function should accept markup as its first argument and return HTML. It may accept other keyword arguments as well. You may parse your markup using any method you choose, as long as you can wrap it in a function that meets these criteria. The second element must be a dictionary of keyword arguments to pass to the filter function. The dictionary may be empty. For example, if you have python-markdown installed, you could use it like this:: MARKITUP_FILTER = ('markdown.markdown', {'safe_mode': True}) Alternatively, you could use the "textile" filter provided by Django like this:: MARKITUP_FILTER = ('django.contrib.markup.templatetags.markup.textile', {}) (The textile filter function doesn't accept keyword arguments, so the kwargs dictionary must be empty in this case.) django-markitup provides one sample rendering function, render_rest in the markitup.renderers module. render_markup template filter ============================= If you have set the MARKITUP_FILTER setting_ and use the MarkItUp! AJAX preview, but don't wish to store rendered markup in the database with MarkupField_ (or are using third-party models that don't use MarkupField_), you may want a convenient way to render content in your templates using your MARKITUP_FILTER function. For this you can use the render_markup template filter:: {% load markitup_tags %} {{ post.content|render_markup }} Other settings ============== MARKITUP_PREVIEW_FILTER ----------------------- This optional setting can be used to override the markup filter used for the Ajax preview view, if for some reason you need it to be different from the filter used for rendering markup in a MarkupField. It has the same format as MARKITUP_FILTER; by default it is set equal to MARKITUP_FILTER. MARKITUP_AUTO_PREVIEW --------------------- If set to True, the preview window will be activated by default. Defaults to False. JQUERY_URL ---------- MarkItUp! requires the jQuery Javascript library. By default, django-markitup links to the most recent minor version of jQuery 1.6 available at ajax.googleapis.com (via the URL http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js). If you wish to use a different version of jQuery, or host it yourself, set the JQUERY_URL setting. For example:: JQUERY_URL = 'jquery.min.js' This will use the jQuery available at STATIC_URL/jquery.min.js. A relative JQUERY_URL is relative to STATIC_URL. If you include the jQuery library manually in your templates and don't want django-markitup to include it, set JQUERY_URL to None. 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.