README.rst 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Include Pygments highlighted code with reStructuredText
  2. =======================================================
  3. :author: Colin Dunklau
  4. Use this plugin to make writing coding tutorials easier! You can
  5. maintain the example source files separately from the actual article.
  6. Based heavily on ``docutils.parsers.rst.directives.Include``. Include
  7. a file and output as a code block formatted with pelican's Pygments
  8. directive.
  9. Note that this is broken with the Docutils 0.10 release, there's a
  10. circular import. It was fixed in trunk:
  11. http://sourceforge.net/p/docutils/bugs/214/
  12. Directives
  13. ----------
  14. .. code:: rst
  15. .. code-include:: incfile.py
  16. :lexer: string, name of the Pygments lexer to use, default 'text'
  17. :encoding: string, encoding with which to open the file
  18. :tab-width: integer, hard tabs are replaced with `tab-width` spaces
  19. :start-line: integer, starting line to begin reading include file
  20. :end-line: integer, last line from include file to display
  21. ``start-line``, and ``end-line`` have the same meaning as in the
  22. docutils ``include`` directive, that is, they index from zero.
  23. Example
  24. -------
  25. ./incfile.py:
  26. .. code:: python
  27. # These two comment lines will not
  28. # be included in the output
  29. import random
  30. insults = ['I fart in your general direction',
  31. 'your mother was a hampster',
  32. 'your father smelt of elderberries']
  33. def insult():
  34. print random.choice(insults)
  35. # This comment line will be included
  36. # ...but this one won't
  37. ./yourfile.rst:
  38. .. code:: rst
  39. How to Insult the English
  40. =========================
  41. :author: Pierre Devereaux
  42. A function to help insult those silly English knnnnnnniggets:
  43. .. code-include:: incfile.py
  44. :lexer: python
  45. :encoding: utf-8
  46. :tab-width: 4
  47. :start-line: 3
  48. :end-line: 11