Browse Source

Exhaustivity of supported block elements

master
David Larlet 9 months ago
parent
commit
7bf91625be
2 changed files with 20 additions and 2 deletions
  1. 11
    0
      test_widont.py
  2. 9
    2
      widont.py

+ 11
- 0
test_widont.py View File

@@ -69,6 +69,17 @@ import pytest
"With, punctuation",
"With, punctuation",
),
(
"<details><summary>Unfold for content</summary></details>",
"<details><summary>Unfold for\u00a0content</summary></details>",
"<details><summary>Unfold for&nbsp;content</summary></details>",
),
# TODISCUSS: we probably want to widont the summary too?
(
"<details><summary>Unfold for content</summary><p>This is the content.</p></details>",
"<details><summary>Unfold for content</summary><p>This is the\u00a0content.</p></details>",
"<details><summary>Unfold for content</summary><p>This is the&nbsp;content.</p></details>",
),
],
)
def test_widont(in_, out_unicode, out_html):

+ 9
- 2
widont.py View File

@@ -13,7 +13,13 @@ class Charactere:
NON_BREAKABLE_SPACE = Charactere(unicode="\u00a0", html="&nbsp;")

# TODISCUSS: part of the configuration?
COMPUTED_BLOCKS = "|".join(["p", "h[1-6]", "li", "dt", "dd"])

# Complete list:
# https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
# Intentionnaly excluded: address, article, aside, blockquote,
# dialog, div, dl, fieldset, figure, footer, form, hgroup, hr, main,
# nav, ol, pre, section, table, ul.
COMPUTED_BLOCKS = "|".join(["details", "dt", "dd", "figcaption", "h[1-6]", "li", "p"])

# Complete list:
# https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements#list_of_inline_elements
@@ -43,6 +49,7 @@ ALLOWED_INLINES = "|".join(
"span",
"strong",
"sub",
"summary",
"sup",
"u",
]
@@ -80,7 +87,7 @@ def widont(text, html=False):
Improvements:

* allow the unbreakable unicode character (new option)
* add the mark element as a potential inline
* consider the support of all pertinent inline and block elements
* avoid insertion of a non-breakable space if the sentence is a single word
* externalized test suite
"""

Loading…
Cancel
Save