Text Decorator Extension for Python-Markdown.
Project description
Text Decorator Extension for Python-Markdown
This extension add Text Decorate handler to Python-Markdown.
Spec
This extension supports following expressions.
Type | Markdown | HTML |
---|---|---|
delete | --text-- |
<del>text</del> |
insert | ++text++ |
<ins>text</ins> |
mark | !!text!! |
<mark>text</mark> |
overline | ===text=== |
<span class="overline" style="...">text</span> |
ruby | {text:rt-text} |
<ruby>text<rt>rt-text</rt></ruby> |
strikethrough | ~~text~~ |
<s>text</s> |
subscript | ^text^ |
<sub>text</sub> |
superscript | ^^text^^ |
<sup>text</sup> |
underline | =text= |
<span class="underline" style="...">text</span> |
underoverline | ==text== |
<span class="underoverline" style="...">text</span> |
Extension Param
Name | Type | Default | Description |
---|---|---|---|
priority | int | 100 | When you use other extensions, Try to adjust this param. * Higher value will be prioritized proccessing. Ref) Registries priority |
Installation
python3 -m pip install markdown_text_decorator
Usage
Sample Code
from markdown import Markdown
MARKDOWN_EXTENSIONS = [
"markdown_text_decorator"
]
MARKDOWN_EXTENSION_CONFS={
"markdown_text_decorator": { "priority": 90 }
}
md2html = Markdown(extensions=MARKDOWN_EXTENSIONS,
extension_configs=MARKDOWN_EXTENSION_CONFS)
markdown_input = """
# Markdown Text Decoration Expression
~~This is~~ strikethrough ~~line~~
++This is++ insert ++line++
--This is-- delete --line--
^^This is^^ superscript ^^line^^
^This is^ subscript ^line^
!!This is!! mark !!line!!
=This is= underline =line=
==This is== underoverline ==line==
===This is=== overline ===line===
{ Markdown Text Decorator : mɑ́ːkdàun tékst dékərèitər }
{ 日本語: !!Japanese!! } { 英語: !!English!! }
# Python-Markdown Standard Expression
This is nomal line
*This is* italic-1 *line*
_This is_ italic-2 _line_
**This is** bold-1 **line**
__This is__ bold-2 __line__
***This is*** bold+italic-1 ***line***
___This is___ bold+italic-2 ___line___
**_This is_** bold+italic-3 **_line_**
"""
html_output = md2html.convert(markdown_input)
print(html_output)
Sample Output
<h1>Markdown Text Decoration Expression</h1>
<p><s>This is</s> strikethrough <s>line</s></p>
<p><ins>This is</ins> insert <ins>line</ins> </p>
<p><del>This is</del> delete <del>line</del></p>
<p><sup>This is</sup> superscript <sup>line</sup></p>
<p><sub>This is</sub> subscript <sub>line</sub></p>
<p><mark>This is</mark> mark <mark>line</mark></p>
<p><span class="underline" style="text-decoration: underline">This is</span> underline <span class="underline" style="text-decoration: underline">line</span></p>
<p><span class="underoverline" style="text-decoration: underline overline">This is</span> underoverline <span class="underoverline" style="text-decoration: underline overline">line</span></p>
<p><span class="overline" style="text-decoration: overline">This is</span> overline <span class="overline" style="text-decoration: overline">line</span></p>
<p><ruby>Markdown Text Decorator<rt>mɑ́ːkdàun tékst dékərèitər</rt></ruby></p>
<p><ruby>日本語<rt><mark>Japanese</mark></rt></ruby> <ruby>英語<rt><mark>English</mark></rt></ruby></p>
<h1>Python-Markdown Standard Expression</h1>
<p>This is nomal line</p>
<p><em>This is</em> italic-1 <em>line</em></p>
<p><em>This is</em> italic-2 <em>line</em></p>
<p><strong>This is</strong> bold-1 <strong>line</strong></p>
<p><strong>This is</strong> bold-2 <strong>line</strong></p>
<p><strong><em>This is</em></strong> bold+italic-1 <strong><em>line</em></strong></p>
<p><strong><em>This is</em></strong> bold+italic-2 <strong><em>line</em></strong></p>
<p><strong><em>This is</em></strong> bold+italic-3 <strong><em>line</em></strong></p>
Test Result
MarkdownTextDecoratorTest
----------------------------------------------------------------------
test_bold_italic_p1 (__main__.MarkdownStandardTextDecoratorTestCase)
test for bold_italic pattern 1 ... ok
test_bold_italic_p2 (__main__.MarkdownStandardTextDecoratorTestCase)
test for bold_italic pattern 2 ... ok
test_bold_italic_p3 (__main__.MarkdownStandardTextDecoratorTestCase)
test for bold_italic pattern 3 ... ok
test_bold_p1 (__main__.MarkdownStandardTextDecoratorTestCase)
test for bold pattern 1 ... ok
test_bold_p2 (__main__.MarkdownStandardTextDecoratorTestCase)
test for bold pattern 2 ... ok
test_italic_p1 (__main__.MarkdownStandardTextDecoratorTestCase)
test for italic pattern 1 ... ok
test_italic_p2 (__main__.MarkdownStandardTextDecoratorTestCase)
test for italic pattern 2 ... ok
test_normal (__main__.MarkdownStandardTextDecoratorTestCase)
test for normal ... ok
test_all (__main__.MarkdownTextDecoratorTestCase)
test for all at once ... ok
test_delete (__main__.MarkdownTextDecoratorTestCase)
test for delete ... ok
test_insert (__main__.MarkdownTextDecoratorTestCase)
test for insert ... ok
test_mark (__main__.MarkdownTextDecoratorTestCase)
test for mark ... ok
test_overline (__main__.MarkdownTextDecoratorTestCase)
test for overline ... ok
test_ruby (__main__.MarkdownTextDecoratorTestCase)
test for ruby ... ok
test_strikethrough (__main__.MarkdownTextDecoratorTestCase)
test for strikethrough ... ok
test_subscript (__main__.MarkdownTextDecoratorTestCase)
test for subscript ... ok
test_superscript (__main__.MarkdownTextDecoratorTestCase)
test for superscript ... ok
test_underline (__main__.MarkdownTextDecoratorTestCase)
test for underline ... ok
test_underoverline (__main__.MarkdownTextDecoratorTestCase)
test for underoverline ... ok
----------------------------------------------------------------------
Ran 19 tests in 0.020s
CHANGE LOG
v3.2.0
Add Extension param "priority".
v3.1.1
Fix bug.
v3.1.0
Refactor codes and update README.
v3.0.1
Add unittest for Checking markdown_text_decorator does not destruct Python-Markdown standard text decoration.
- Italic, Bold, Italic+Bold.
v3.0.0
Support overline, underline and underoverline.
Add unittest for them.
v2.0.0
Support ruby and add unittest for ruby.
v1.2.0
Support mark and add unittest for mark.
v1.1.1
Add unittest for strikethrough, insert, delete, superscript and subscript.
v1.1.0
Support superscript and subscript.
v1.0.1
Support multi-pairs in one line release.
v1.0.0
Initial Release.
Reference
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for markdown_text_decorator-3.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f5ae326b2c743fefbf768758a7a3a1a08d97b6254c70a10f42c1d47ef876c4a |
|
MD5 | e4341d4628db70224086395b0b4017a1 |
|
BLAKE2b-256 | 61a81a45f94a2a54326be32b7c300b18672f71d084c3f5b85e63292ae47b9af0 |