From 9c2830f7b0273ae399b771a7d9780ee7a7430fc4 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Wed, 7 Mar 2012 08:43:36 -0500 Subject: Added a bunch of internal links to the docs. --- docs/extensions/api.md | 47 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) (limited to 'docs/extensions') diff --git a/docs/extensions/api.md b/docs/extensions/api.md index c27abf0..8886b8f 100644 --- a/docs/extensions/api.md +++ b/docs/extensions/api.md @@ -7,9 +7,6 @@ next_url: ../test_suite.html Writing Extensions for Python-Markdown ====================================== -Overview --------- - Python-Markdown includes an API for extension writers to plug their own custom functionality and/or syntax into the parser. There are preprocessors which allow you to alter the source before it is passed to the parser, @@ -25,20 +22,8 @@ Additionally, reading the source of some [Available Extensions][] may be helpful. For example, the [Footnotes][] extension uses most of the features documented here. -* [Preprocessors][] -* [InlinePatterns][] -* [Treeprocessors][] -* [Postprocessors][] -* [BlockParser][] -* [Working with the ElementTree][] -* [Integrating your code into Markdown][] - * [extendMarkdown][] - * [OrderedDict][] - * [registerExtension][] - * [Config Settings][] - * [makeExtension][] - -

Preprocessors

+Preprocessors {: #preprocessors } +--------------------------------- Preprocessors munge the source text before it is passed into the Markdown core. This is an excellent place to clean up bad syntax, extract things the @@ -65,7 +50,8 @@ A pseudo example: new_lines.append(line) return new_lines -

Inline Patterns

+Inline Patterns {: #inlinepatterns } +------------------------------------ Inline Patterns implement the inline HTML element syntax for Markdown such as ``*emphasis*`` or ``[links](http://example.com)``. Pattern objects should be @@ -140,7 +126,8 @@ or use as well. Read through the source and see if there is anything you can use. You might even get a few ideas for different approaches to your specific situation. -

Treeprocessors

+Treeprocessors {: #treeprocessors } +----------------------------------- Treeprocessors manipulate an ElemenTree object after it has passed through the core BlockParser. This is where additional manipulation of the tree takes @@ -163,7 +150,8 @@ A pseudo example: For specifics on manipulating the ElementTree, see [Working with the ElementTree][] below. -

Postprocessors

+Postprocessors {: #postprocessors } +----------------------------------- Postprocessors manipulate the document after the ElementTree has been serialized into a string. Postprocessors should be used to work with the @@ -183,7 +171,8 @@ contents to a document: def run(self, text): return MYMARKERRE.sub(MyToc, text) -

BlockParser

+BlockParser {: #blockparser } +----------------------------- Sometimes, pre/tree/postprocessors and Inline Patterns aren't going to do what you need. Perhaps you want a new type of block type that needs to be integrated @@ -309,7 +298,8 @@ the ``BlockParser``. The new class would have to provide the same public API. However, be aware that other extensions may expect the core parser provided and will not work with such a drastically different parser. -

Working with the ElementTree

+Working with the ElementTree {: #working_with_et } +-------------------------------------------------- As mentioned, the Markdown parser converts a source document to an [ElementTree][] object before serializing that back to Unicode text. @@ -363,7 +353,8 @@ For more information about working with ElementTree see the ElementTree [Documentation](http://effbot.org/zone/element-index.htm) ([Python Docs](http://docs.python.org/lib/module-xml.etree.ElementTree.html)). -

Integrating Your Code Into Markdown

+Integrating Your Code Into Markdown {: #integrating_into_markdown } +------------------------------------------------------------------- Once you have the various pieces of your extension built, you need to tell Markdown about them and ensure that they are run in the proper sequence. @@ -383,7 +374,7 @@ instances of your processors and patterns into the appropriate location in an OrderedDict, remove a built-in instance, or replace a built-in instance with your own. -

extendMarkdown

+### extendMarkdown {: #extendmarkdown } The ``extendMarkdown`` method of a ``markdown.extensions.Extension`` class accepts two arguments: @@ -433,7 +424,7 @@ A simple example: # Insert instance of 'mypattern' before 'references' pattern md.inlinePatterns.add('mypattern', MyPattern(md), 'OrderedDict +### OrderedDict {: #ordereddict } An OrderedDict is a dictionary like object that retains the order of it's items. The items are ordered in the order in which they were appended to @@ -518,7 +509,7 @@ To change the location of an existing item: t.link('somekey', 'registerExtension +### registerExtension {: #registerextension } Some extensions may need to have their state reset between multiple runs of the Markdown class. For example, consider the following use of the [Footnotes][] @@ -550,7 +541,7 @@ note that ``reset`` will be called on each registered extension after it is initialized the first time. Keep that in mind when over-riding the extension's ``reset`` method. -

Config Settings

+### Config Settings {: #configsettings } If an extension uses any parameters that the user may want to change, those parameters should be stored in ``self.config`` of your @@ -569,7 +560,7 @@ values, and should be converted at run time. For example: i = int(self.getConfig("SOME_PARAM")) -

makeExtension

+### makeExtension {: #makeextension } Each extension should ideally be placed in its own module starting with the ``mdx_`` prefix (e.g. ``mdx_footnotes.py``). The module must -- cgit v1.2.3