Browse Source

Exhaustivity of supported block elements

master
David Larlet 2 years 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

"With, punctuation", "With, punctuation",
"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): def test_widont(in_, out_unicode, out_html):

+ 9
- 2
widont.py View File

NON_BREAKABLE_SPACE = Charactere(unicode="\u00a0", html="&nbsp;") NON_BREAKABLE_SPACE = Charactere(unicode="\u00a0", html="&nbsp;")


# TODISCUSS: part of the configuration? # 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: # Complete list:
# https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements#list_of_inline_elements # https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements#list_of_inline_elements
"span", "span",
"strong", "strong",
"sub", "sub",
"summary",
"sup", "sup",
"u", "u",
] ]
Improvements: Improvements:


* allow the unbreakable unicode character (new option) * 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 * avoid insertion of a non-breakable space if the sentence is a single word
* externalized test suite * externalized test suite
""" """

Loading…
Cancel
Save