ソースを参照

Exhaustivity of supported block elements

master
David Larlet 2年前
コミット
7bf91625be
2個のファイルの変更20行の追加2行の削除
  1. 11
    0
      test_widont.py
  2. 9
    2
      widont.py

+ 11
- 0
test_widont.py ファイルの表示

@@ -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 ファイルの表示

@@ -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
"""

読み込み中…
キャンセル
保存