Skip to content

Commit

Permalink
Add fancylist extension
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Sep 17, 2024
1 parent 6d2d8e5 commit fdf93bd
Show file tree
Hide file tree
Showing 10 changed files with 583 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/src/markdown/.snippets/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
[_emoji]: https://github.com/facelessuser/pymdown-extensions/blob/master/pymdownx/emoji.py "Source"
[_escapeall]: https://github.com/facelessuser/pymdown-extensions/blob/master/pymdownx/escapeall.py "Source"
[_extra]: https://github.com/facelessuser/pymdown-extensions/blob/master/pymdownx/extra.py "Source"
[_fancylists]: https://github.com/facelessuser/pymdown-extensions/blob/master/pymdownx/fancylists.py "Source"
[_highlight]: https://github.com/facelessuser/pymdown-extensions/blob/master/pymdownx/highlight.py "Source"
[_html_block]: https://github.com/facelessuser/pymdown-extensions/blob/feature/directives/pymdownx/blocks/html.py "Source"
[_inlinehilite]: https://github.com/facelessuser/pymdown-extensions/blob/master/pymdownx/inlinehilite.py "Source"
Expand Down Expand Up @@ -67,6 +68,7 @@
[nl2br]: https://python-markdown.github.io/extensions/nl2br/
[octicons]: https://octicons.github.com/
[onready-event]: https://github.com/facelessuser/pymdown-extensions/blob/master/docs/src/js/extra-uml.js
[pandoc-lists]: https://pandoc.org/chunkedhtml-demo/8.7-lists.html
[pep8-naming]: https://pypi.python.org/pypi/pep8-naming
[pygments]: http://pygments.org/
[pymdown-styles]: https://github.com/facelessuser/pymdown-styles/tree/master/pymdown_styles
Expand Down
138 changes: 138 additions & 0 deletions docs/src/markdown/extensions/fancylists.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
[:octicons-file-code-24:][_fancylists]{: .source-link }

# FancyLists

## Overview

FancyLists is inspired by [Pandoc's lists][pandoc-lists] list handling. FancyLists extends the list handling formats
to support parenthesis style lists along with additional ordered formats.

- Support ordered lists as either a trailing dot or single right-parenthesis: `1.` or `1)`.
- Support ordered lists with roman numeral formats, both lowercase and uppercase. Uppercase is treated as a different
list type than lowercase.
- Support ordered lists with alphabetical format, both lowercase and uppercase. Uppercase is treated as a different
list type than lowercase.
- Support a generic numerical format via `#.`. Requires [SaneHeaders](./saneheaders.md) to be enabled.
- Using a different list type will start a new list. Trailing dot vs parenthesis are treated as separate types.
- Ordered lists are sensitive to the starting value and will start a new list using the specified value.

Additional ordered list formats such as Roman numeral, alphabetical, and generic are optional and can be disabled via
[options](#options).

/// note
We do not support Pandoc's list notation that includes full parentheses (`(marker)`).
///

```py3
import markdown
md = markdown.Markdown(
extensions=['pymdownx.fancylists']
)

# Add generic ordered styles
md = markdown.Markdown(extensions=['pymdownx.fancylists', 'pymdownx.saneheaders'])
```

## Rules

1. Lists generally expect to be separated from paragraphs with an empty new line.
2. A new list will be created if the list type changes. This occurs with:
a. A switch from unordered to ordered.
b. Change from using trailing dot or single right-parenthesis.
c. A change from using uppercase vs lowercase.
d. A change in ordered type: numerical, roman numeral, alphabetical, or generic.
3. If using uppercase list markers, a list marker consisting of a single uppercase letter will require two spaces
after the marker instead of the usual 1.
4. The generic ordered list format (`#`) requires [SaneHeaders](./saneheaders.md) to be enabled.
5. Roman numeral ordered lists require valid roman numerals.
6. If a roman numeral consisting of a single letter is used within an alphabetical list (assuming trailing symbol and
case are the same) the list item will be treated as an alphabetical list item.
7. If a Roman numeral is used to start a list and it consists of a single letter, it will be assumed an alphabetical
list unless the letter is `i` or `I`.


/// note
Ordered lists will have the type attribute set appropriately on the `ol` tag, but CSS styling can override appearance.
If it is noted that lists are not rendered correctly, make sure you do not have CSS overriding the style.
///

## Examples

Various list types.


```
1. Item 1
2. Item 2
i. Item 1
ii. Item 2
a. Item 1
b. Item 2
#. Item 1
#. Item 2
```

///// html | div.result
1. Item 1
2. Item 2
i. Item 1
ii. Item 2
a. Item 1
b. Item 2
#. Item 1
#. Item 2
/////

New lists on type change.

```
1. Item 1
2. Item 2
3) Item 1
4) Item 2
```

///// html | div.result
1. Item 1
2. Item 2

3) Item 1
4) Item 2
/////

New list on case change.

```
a. Item 1
b. Item 2
C. Item 1
D. Item 2
```

///// html | div.result
a. Item 1
b. Item 2

C. Item 1
D. Item 2
/////

Generic ordered list format.

```
#. Item 1
#. Item 2
```

///// html | div.result
#. Item 1
#. Item 2
/////

## Options

Option | Type | Default | Description
--------------------------- | -------- | ------------------------------------- | ------------
`additional_ordered_styles` | [string] | `#!py3 ['roman', 'alpha', 'generic']` | Add additional ordered list styles. Accepted inputs include `roman`, `alpha`, and `generic`.
14 changes: 10 additions & 4 deletions docs/src/markdown/extensions/saneheaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

SaneHeaders is an extension that alters the default hashed headers extension to require headers to have spaces after the
hashes (`#`) in order to be recognized as headers. This allows for other extension syntaxes to use `#` in their syntaxes
as long as no spaces follow the `#` at the beginning of a line. For instance,
[MagicLink's issue syntax](./magiclink.md#issues-and-pull-requests) issue syntax uses hashes followed by numbers
(`#998`) to represent issue links. There may be extensions that use names after hashes to provide tags (`#tag`). With
SaneHeaders, these syntaxes can coexist. Those familiar with CommonMark may recognize this behavior.
as long as no spaces follow the `#` at the beginning of a line.

Currently, Pymdown Extensions has two extensions where SaneHeaders can help.

1. [MagicLink's issue syntax](./magiclink.md#issues-and-pull-requests) uses hashes followed by numbers (`#998`) to
represent issue links. There may be extensions that use names after hashes to provide tags (`#tag`). With
SaneHeaders, these syntaxes can coexist. Those familiar with CommonMark may recognize this behavior.

2. [FancyLists' sytax](./fancylists.md) exposes a a generic ordered list style that doesn't require you to provide
numbers. This syntax utilize the `#.` marker for list items.

```py3
import markdown
Expand Down
2 changes: 2 additions & 0 deletions docs/src/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ nav:
- Emoji: extensions/emoji.md
- EscapeAll: extensions/escapeall.md
- Extra: extensions/extra.md
- Fancylists: extensions/fancylists
- Highlight: extensions/highlight.md
- InlineHilite: extensions/inlinehilite.md
- Keys: extensions/keys.md
Expand Down Expand Up @@ -172,6 +173,7 @@ markdown_extensions:
- pymdownx.tabbed:
alternate_style: true
- pymdownx.saneheaders:
- pymdownx.fancylists:
- pymdownx.blocks.admonition:
types:
- new
Expand Down
10 changes: 10 additions & 0 deletions docs/src/scss/_material.scss
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ html {
color: var(--md-text-color);
text-transform: none;
}

ol ol{
// Nested ordered list
list-style-type: revert-layer;

// Triply nested ordered list
ol {
list-style-type: revert-layer;
}
}
}

.md-typeset__scrollwrap,
Expand Down
1 change: 0 additions & 1 deletion docs/theme/assets/pymdownx-extras/extra-8611f6c398.css.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/theme/assets/pymdownx-extras/extra-ea58a5cc04.css.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ nav:
- Emoji: extensions/emoji.md
- EscapeAll: extensions/escapeall.md
- Extra: extensions/extra.md
- Fancylists: extensions/fancylists
- Highlight: extensions/highlight.md
- InlineHilite: extensions/inlinehilite.md
- Keys: extensions/keys.md
Expand Down Expand Up @@ -172,6 +173,7 @@ markdown_extensions:
- pymdownx.tabbed:
alternate_style: true
- pymdownx.saneheaders:
- pymdownx.fancylists:
- pymdownx.blocks.admonition:
types:
- new
Expand Down Expand Up @@ -234,7 +236,7 @@ extra:
link: https://github.com/facelessuser
extra_css:
# - https://cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.css
- assets/pymdownx-extras/extra-8611f6c398.css
- assets/pymdownx-extras/extra-ea58a5cc04.css
extra_javascript:
- https://unpkg.com/mermaid@10.6.1/dist/mermaid.min.js
# - https://cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.js
Expand Down
Loading

0 comments on commit fdf93bd

Please sign in to comment.