diff options
author | Waylan Limberg <waylan@gmail.com> | 2011-06-20 06:55:12 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2011-06-20 06:55:12 -0400 |
commit | af59bf74725937ab2be70fe5de711fa7e4ddfb02 (patch) | |
tree | 4c1bb224c95e23b2d77b57654214211c85a6e609 | |
parent | c2cca0cefe6fb9977a23008af17641531e3b9e43 (diff) | |
download | markdown-af59bf74725937ab2be70fe5de711fa7e4ddfb02.tar.gz markdown-af59bf74725937ab2be70fe5de711fa7e4ddfb02.tar.bz2 markdown-af59bf74725937ab2be70fe5de711fa7e4ddfb02.zip |
Added docs and tests to attr_list ext. Closes #7.
-rw-r--r-- | docs/extensions/attr_list.txt | 74 | ||||
-rw-r--r-- | tests/extensions/attr_list.html | 17 | ||||
-rw-r--r-- | tests/extensions/attr_list.txt | 35 | ||||
-rw-r--r-- | tests/extensions/test.cfg | 3 |
4 files changed, 129 insertions, 0 deletions
diff --git a/docs/extensions/attr_list.txt b/docs/extensions/attr_list.txt new file mode 100644 index 0000000..6bfe07b --- /dev/null +++ b/docs/extensions/attr_list.txt @@ -0,0 +1,74 @@ +Attribute Lists +=============== + +Summary +------- + +An extension to Python-Markdown that adds a syntax to define attributes on +the various HTML elements in markdown's output. + +This extension is included in the standard Markdown library. + +Syntax +------ + +The basic syntax was inspired by [Maruku][]'s Attribute List feature. + +[Maruku]: http://maruku.rubyforge.org/proposal.html#attribute_lists + +### The List ### + +An example attribute list might look like this: + + {: #someid .someclass somekey='some values' } + +A word which starts with a hash `#` will set the id of an element. + +A word which starts with a dot `.` will add to the list of classes assigned to +an element. + +A key/value pair will assign that pair to the element. + +Be aware that while the dot syntax will add to a class, using key/value pairs +will always override the previously defined attribute. Consider the following: + + {: #id1 .class1 id=id2 class="class2 class3" .class4 } + +The above example would result in the following attributes being defined: + + id="id2 class="class2 class3 class4" + +### Block Level ### + +To define attributes for a block level element, the attribute list should +be defined on the last line of the block by itself. + + This is a paragraph. + {: #an_id .a_class } + +The above results in the following output: + + <p id="an_id" class="a_class">This is a paragraph.</p> + +The one exception is headers, as they are only ever allowed on one line. + + A setext style header {: #setext} + ================================= + + ### A hash style header ### {: #hash } + +The above results in the following output: + + <h1 id="setext">A setext style header</h1> + <h3 id="hash">A hash style header</h3> + +### Inline ### + +To define attributes on inline elements, the attribute list should be defined +immediately after the inline element with no whitespace. + + [link](http://example.com){: class="foo bar" title="Some title! } + +The above results in the following output: + + <p><a href="http://example.com" class="foo bar" title="Some title!">link</a></p> diff --git a/tests/extensions/attr_list.html b/tests/extensions/attr_list.html new file mode 100644 index 0000000..1e9c182 --- /dev/null +++ b/tests/extensions/attr_list.html @@ -0,0 +1,17 @@ +<h1 id="setext">This is a sextext header</h1> +<p class="myclass" id="par1">A paragraph with some text. +Line two of the paragraph.</p> +<h2 class="someclass" id="sextext2">This is another</h2> +<p>Test some <em class="inline">inline</em> text. +A <a class="linkkyclass" href="http://example.com" title="A title.">link</a> +And a <strong class="nest">nested <a class="linky2" href="http://example.com" title="Some title">link</a></strong></p> +<h3 id="hash">This is a hash Header</h3> +<p bar="b az" baz="blah blah" foo="foo" title="I wasn't kidding!">And now some random attributes.</p> +<h3 id="hash2">No closing hash header</h3> +<p class="foo bar addme" id="overridden">Now test overrides</p> +<pre><code># A code block which contains attr_list syntax +# This should be ignored. +{: #someid .someclass } +</code></pre> +<h3 id="hash3">No colon for compatability with Headerid ext</h3> +<p id="the_end">Also a codespan: <code class="foo">{: .someclass}</code>.</p>
\ No newline at end of file diff --git a/tests/extensions/attr_list.txt b/tests/extensions/attr_list.txt new file mode 100644 index 0000000..d7ed274 --- /dev/null +++ b/tests/extensions/attr_list.txt @@ -0,0 +1,35 @@ +This is a sextext header {: #setext} +==================================== + +A paragraph with some text. +Line two of the paragraph. +{: #par1 .myclass } + +This is another {: #sextext2 .someclass} +---------------------------------------- + +Test some _inline_{: .inline} text. +A [link](http://example.com){: .linkkyclass title="A title."} +And a __nested [link][]{: .linky2}__{: .nest} + +[link]: http://example.com "Some title" + +### This is a hash Header ### {: #hash} + +And now some random attributes. +{:foo bar='b az' baz="blah blah" title="I wasn't kidding!" } + +### No closing hash header {: #hash2} + +Now test overrides +{: #overrideme .andme id=overridden class='foo bar' .addme } + + # A code block which contains attr_list syntax + # This should be ignored. + {: #someid .someclass } + +### No colon for compatability with Headerid ext { #hash3 } + +Also a codespan: `{: .someclass}`{: .foo}. +{: #the_end} + diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg index fd57ef1..671f2a5 100644 --- a/tests/extensions/test.cfg +++ b/tests/extensions/test.cfg @@ -1,3 +1,6 @@ +[attr_list] +extensions=attr_list + [codehilite] extensions=codehilite # This passes or not based on version of pygments. |