From f093843f4018c39f82eda6ee327f626071bf3db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 15 Feb 2021 16:19:19 +0100 Subject: [PATCH 01/18] Allow for a custom strong or emphasis symbol --- markdownify/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 5c008d3..4542f9a 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -46,6 +46,7 @@ class MarkdownConverter(object): autolinks = True heading_style = UNDERLINED bullets = '*+-' # An iterable of bullet types. + strong_em_symbol = '*' class Options(DefaultOptions): pass @@ -157,10 +158,11 @@ class MarkdownConverter(object): return ' \n' def convert_em(self, el, text, convert_as_inline): + em_tag = self.options['strong_em_symbol'] prefix, suffix, text = chomp(text) if not text: return '' - return '%s*%s*%s' % (prefix, text, suffix) + return '%s%s%s%s%s' % (prefix, em_tag, text, em_tag, suffix) def convert_hn(self, n, el, text, convert_as_inline): if convert_as_inline: @@ -222,10 +224,11 @@ class MarkdownConverter(object): return '%s\n\n' % text if text else '' def convert_strong(self, el, text, convert_as_inline): + strong_tag = 2 * self.options['strong_em_symbol'] prefix, suffix, text = chomp(text) if not text: return '' - return '%s**%s**%s' % (prefix, text, suffix) + return '%s%s%s%s%s' % (prefix, strong_tag, text, strong_tag, suffix) def convert_img(self, el, text, convert_as_inline): alt = el.attrs.get('alt', None) or '' From b3ac4606a6697c97a08c09dc3c54d98af84eaf59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 15 Feb 2021 16:29:14 +0100 Subject: [PATCH 02/18] Allow for the use of backslash for newlines --- markdownify/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 4542f9a..59aa694 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -47,6 +47,7 @@ class MarkdownConverter(object): heading_style = UNDERLINED bullets = '*+-' # An iterable of bullet types. strong_em_symbol = '*' + newline = 'spaces' class Options(DefaultOptions): pass @@ -155,7 +156,10 @@ class MarkdownConverter(object): if convert_as_inline: return "" - return ' \n' + if self.options['newline'] == 'backslash': + return '\\\n' + else: + return ' \n' def convert_em(self, el, text, convert_as_inline): em_tag = self.options['strong_em_symbol'] From 29a4e551f772fb83f2c22d166bdce2ab24485de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 15 Feb 2021 16:37:13 +0100 Subject: [PATCH 03/18] Update README with the two new options --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index 4d21411..0988ef1 100644 --- a/README.rst +++ b/README.rst @@ -75,6 +75,12 @@ bullets lists are nested. Otherwise, the bullet will alternate based on nesting level. Defaults to ``'*+-'``. +strong_em_symbol + In markdown, both `*` and `_` are used to encode **strong** or *emphasized* texts. The preferred symbol can be passed through this argument, which defaults to `*`. + +newline + Defines the style of marking linebreaks (`
`) in markdown. The default value `'spaces'` of this option means the regular ' \n' will be used (i.e. two spaces and a newline), while `'backslash'` will convert a linebreak to `''\\\n'` (a backslash an a newline). While the latter convention is non-standard, it is commonly preferred and supported by a lot of converters. + Options may be specified as kwargs to the ``markdownify`` function, or as a nested ``Options`` class in ``MarkdownConverter`` subclasses. From a79ed44ec38dc71e9739c5e95463877f4d9fb788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 15 Feb 2021 16:51:20 +0100 Subject: [PATCH 04/18] Fix code ticks in README --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 0988ef1..eac2a00 100644 --- a/README.rst +++ b/README.rst @@ -76,10 +76,10 @@ bullets level. Defaults to ``'*+-'``. strong_em_symbol - In markdown, both `*` and `_` are used to encode **strong** or *emphasized* texts. The preferred symbol can be passed through this argument, which defaults to `*`. + In markdown, both ``*`` and ``_`` are used to encode **strong** or *emphasized* texts. The preferred symbol can be passed through this argument, that defaults to ``*``. newline - Defines the style of marking linebreaks (`
`) in markdown. The default value `'spaces'` of this option means the regular ' \n' will be used (i.e. two spaces and a newline), while `'backslash'` will convert a linebreak to `''\\\n'` (a backslash an a newline). While the latter convention is non-standard, it is commonly preferred and supported by a lot of converters. + Defines the style of marking linebreaks (``
``) in markdown. The default value ``'spaces'`` of this option means the regular `` \n`` will be used (i.e. two spaces and a newline), while ``'backslash'`` will convert a linebreak to ``\\n`` (a backslash an a newline). While the latter convention is non-standard, it is commonly preferred and supported by a lot of interpreters. Options may be specified as kwargs to the ``markdownify`` function, or as a nested ``Options`` class in ``MarkdownConverter`` subclasses. From f320cf87ffa92fb0499eff1bbaf5db5c1fddf564 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Sun, 21 Feb 2021 20:53:41 +0100 Subject: [PATCH 05/18] closing #25 and #18 Adds newlines after blockquotes, allowing for paragraphs after a blockquote. Due to merging problems with @lucafrance 's code I had to quickly copy and paste their code. Thanks for the contribution! --- markdownify/__init__.py | 2 +- tests/test_conversions.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 5c008d3..c9bc9a2 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -148,7 +148,7 @@ class MarkdownConverter(object): if convert_as_inline: return text - return '\n' + line_beginning_re.sub('> ', text) if text else '' + return '\n' + (line_beginning_re.sub('> ', text) + '\n\n') if text else '' def convert_br(self, el, text, convert_as_inline): if convert_as_inline: diff --git a/tests/test_conversions.py b/tests/test_conversions.py index edaefbc..a32bf65 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -75,12 +75,16 @@ def test_b_spaces(): def test_blockquote(): - assert md('
Hello
').strip() == '> Hello' + assert md('
Hello
') == '\n> Hello\n\n' + + +def test_blockquote_with_paragraph(): + assert md('
Hello

handsome

') == '\n> Hello\n\nhandsome\n\n' def test_nested_blockquote(): - text = md('
And she was like
Hello
').strip() - assert text == '> And she was like \n> > Hello' + text = md('
And she was like
Hello
') + assert text == '\n> And she was like \n> > Hello\n> \n> \n\n' def test_br(): From ed406d3206d6509b9c8c349fd92ebacaf5768729 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Sun, 21 Feb 2021 20:57:57 +0100 Subject: [PATCH 06/18] bump to v0.6.4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ec7dea2..498879d 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read() pkgmeta = { '__title__': 'markdownify', '__author__': 'Matthew Tretter', - '__version__': '0.6.1', + '__version__': '0.6.4', } From 99365de66946f31e9bc85d4073b56de8016c638b Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Sun, 21 Feb 2021 23:06:21 +0100 Subject: [PATCH 07/18] upgrading code for python 3.x closes #38 --- .github/workflows/python-app.yml | 2 +- setup.py | 11 +++++++---- tests/test_escaping.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 41240f8..de87672 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -23,7 +23,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8==2.5.4 pytest + pip install flake8==3.8.4 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | diff --git a/setup.py b/setup.py index 498879d..9488cd2 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ class LintCommand(Command): yield "%s.py" % filename def run(self): - from flake8.engine import get_style_guide + from flake8.api.legacy import get_style_guide flake8_style = get_style_guide(config_file='setup.cfg') paths = self.distribution_files() report = flake8_style.check_files(paths) @@ -70,13 +70,13 @@ setup( zip_safe=False, include_package_data=True, setup_requires=[ - 'flake8', + 'flake8>=3.8,<4', ], tests_require=[ - 'pytest', + 'pytest>=6.2,<7', ], install_requires=[ - 'beautifulsoup4', 'six' + 'beautifulsoup4>=4.9,<5', 'six>=1.15,<2' ], classifiers=[ 'Environment :: Web Environment', @@ -87,6 +87,9 @@ setup( 'Programming Language :: Python :: 2.5', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Topic :: Utilities' ], cmdclass={ diff --git a/tests/test_escaping.py b/tests/test_escaping.py index 9b0d4fa..23a828c 100644 --- a/tests/test_escaping.py +++ b/tests/test_escaping.py @@ -2,7 +2,7 @@ from markdownify import markdownify as md def test_underscore(): - assert md('_hey_dude_') == '\_hey\_dude\_' + assert md('_hey_dude_') == r'\_hey\_dude\_' def test_xml_entities(): From fd293a9714f41d470f0cd767401ee194225ea13c Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Sun, 21 Feb 2021 23:08:49 +0100 Subject: [PATCH 08/18] use python 3.8 instead of 3.6 --- .github/workflows/python-app.yml | 4 ++-- .github/workflows/python-publish.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index de87672..000c0b2 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -16,10 +16,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python 3.6 + - name: Set up Python 3.8 uses: actions/setup-python@v2 with: - python-version: 3.6 + python-version: 3.8 - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 1a03a7b..9e3a349 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -17,7 +17,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.x' + python-version: '3.8' - name: Install dependencies run: | python -m pip install --upgrade pip From a59e4b9f48c87bf2633b02bba9d46869c5355613 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Sun, 21 Feb 2021 23:09:44 +0100 Subject: [PATCH 09/18] bump to v0.6.5 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9488cd2..848f8bc 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read() pkgmeta = { '__title__': 'markdownify', '__author__': 'Matthew Tretter', - '__version__': '0.6.4', + '__version__': '0.6.5', } From 8da0bdf998d6792016e8ef96fc6452a4be15b6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 5 Apr 2021 10:28:46 +0200 Subject: [PATCH 10/18] Test strong_em_symbol --- tests/test_conversions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_conversions.py b/tests/test_conversions.py index edaefbc..fef2203 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -65,6 +65,7 @@ def test_a_no_autolinks(): def test_b(): assert md('Hello') == '**Hello**' + assert md('Hello', strong_em_symbol='_') == '__Hello__' def test_b_spaces(): @@ -89,6 +90,7 @@ def test_br(): def test_em(): assert md('Hello') == '*Hello*' + assert md('Hello', strong_em_symbol='_') == '_Hello_' def test_em_spaces(): @@ -174,6 +176,7 @@ def test_atx_closed_headings(): def test_i(): assert md('Hello') == '*Hello*' + assert md('Hello', strong_em_symbol='_') == '_Hello_' def test_ol(): @@ -187,6 +190,7 @@ def test_p(): def test_strong(): assert md('Hello') == '**Hello**' + assert md('Hello', strong_em_symbol='_') == '__Hello__' def test_ul(): From c04ec855dd5c4ed3697d219d99209da4528fa3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 5 Apr 2021 10:44:20 +0200 Subject: [PATCH 11/18] Change option to newline_style and use variables like heading_style does --- README.rst | 4 ++-- markdownify/__init__.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index eac2a00..6ab4911 100644 --- a/README.rst +++ b/README.rst @@ -78,8 +78,8 @@ bullets strong_em_symbol In markdown, both ``*`` and ``_`` are used to encode **strong** or *emphasized* texts. The preferred symbol can be passed through this argument, that defaults to ``*``. -newline - Defines the style of marking linebreaks (``
``) in markdown. The default value ``'spaces'`` of this option means the regular `` \n`` will be used (i.e. two spaces and a newline), while ``'backslash'`` will convert a linebreak to ``\\n`` (a backslash an a newline). While the latter convention is non-standard, it is commonly preferred and supported by a lot of interpreters. +newline_style + Defines the style of marking linebreaks (``
``) in markdown. The default value ``SPACES`` of this option means the regular `` \n`` will be used (i.e. two spaces and a newline), while ``BACKSLASH`` will convert a linebreak to ``\\n`` (a backslash an a newline). While the latter convention is non-standard, it is commonly preferred and supported by a lot of interpreters. Options may be specified as kwargs to the ``markdownify`` function, or as a nested ``Options`` class in ``MarkdownConverter`` subclasses. diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 59aa694..5aa6f91 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -15,6 +15,9 @@ ATX_CLOSED = 'atx_closed' UNDERLINED = 'underlined' SETEXT = UNDERLINED +# Newline style +SPACES = 'spaces' +BACKSLASH = 'backslash' def escape(text): if not text: @@ -47,7 +50,7 @@ class MarkdownConverter(object): heading_style = UNDERLINED bullets = '*+-' # An iterable of bullet types. strong_em_symbol = '*' - newline = 'spaces' + newline_style = SPACES class Options(DefaultOptions): pass @@ -156,7 +159,7 @@ class MarkdownConverter(object): if convert_as_inline: return "" - if self.options['newline'] == 'backslash': + if self.options['newline_style'] == BACKSLASH: return '\\\n' else: return ' \n' From 16dbc471b989847eeae685a0e26fc924e23cc174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 5 Apr 2021 10:47:55 +0200 Subject: [PATCH 12/18] Test newline_style --- tests/test_conversions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_conversions.py b/tests/test_conversions.py index fef2203..5f2ada7 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -1,4 +1,4 @@ -from markdownify import markdownify as md, ATX, ATX_CLOSED +from markdownify import markdownify as md, ATX, ATX_CLOSED, BACKSLASH import re @@ -86,6 +86,7 @@ def test_nested_blockquote(): def test_br(): assert md('a
b
c') == 'a \nb \nc' + assert md('a
b
c', newline_style=BACKSLASH) == 'a\\\nb\\\nc' def test_em(): From 7ee87b1d3260250e2654c18056b1c55e18ca009e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 5 Apr 2021 10:50:23 +0200 Subject: [PATCH 13/18] Use .lower() on _style option fetching --- markdownify/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 5aa6f91..a23964c 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -159,7 +159,7 @@ class MarkdownConverter(object): if convert_as_inline: return "" - if self.options['newline_style'] == BACKSLASH: + if self.options['newline_style'].lower() == BACKSLASH: return '\\\n' else: return ' \n' @@ -175,7 +175,7 @@ class MarkdownConverter(object): if convert_as_inline: return text - style = self.options['heading_style'] + style = self.options['heading_style'].lower() text = text.rstrip() if style == UNDERLINED and n <= 2: line = '=' if n == 1 else '-' From 650f377b645b85c460caba99cde0e91bb76a90e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 5 Apr 2021 11:13:19 +0200 Subject: [PATCH 14/18] Fix linting --- markdownify/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index a23964c..08819aa 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -19,6 +19,7 @@ SETEXT = UNDERLINED SPACES = 'spaces' BACKSLASH = 'backslash' + def escape(text): if not text: return '' From 5580b0b51d57d21d99e9cf27cbdaff15e72fbcf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 5 Apr 2021 11:13:52 +0200 Subject: [PATCH 15/18] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6ab4911..a19fabe 100644 --- a/README.rst +++ b/README.rst @@ -79,7 +79,7 @@ strong_em_symbol In markdown, both ``*`` and ``_`` are used to encode **strong** or *emphasized* texts. The preferred symbol can be passed through this argument, that defaults to ``*``. newline_style - Defines the style of marking linebreaks (``
``) in markdown. The default value ``SPACES`` of this option means the regular `` \n`` will be used (i.e. two spaces and a newline), while ``BACKSLASH`` will convert a linebreak to ``\\n`` (a backslash an a newline). While the latter convention is non-standard, it is commonly preferred and supported by a lot of interpreters. + Defines the style of marking linebreaks (``
``) in markdown. The default value ``SPACES`` of this option will adopt the usual two spaces and a newline, while ``BACKSLASH`` will convert a linebreak to ``\\n`` (a backslash an a newline). While the latter convention is non-standard, it is commonly preferred and supported by a lot of interpreters. Options may be specified as kwargs to the ``markdownify`` function, or as a nested ``Options`` class in ``MarkdownConverter`` subclasses. From e877602a5e988a665b9160158a020f8f825233c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Mon, 5 Apr 2021 11:28:42 +0200 Subject: [PATCH 16/18] Separate the strong_em_symbol and newline style tests --- tests/test_conversions.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/test_conversions.py b/tests/test_conversions.py index 5f2ada7..d07d487 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -65,7 +65,6 @@ def test_a_no_autolinks(): def test_b(): assert md('Hello') == '**Hello**' - assert md('Hello', strong_em_symbol='_') == '__Hello__' def test_b_spaces(): @@ -86,12 +85,10 @@ def test_nested_blockquote(): def test_br(): assert md('a
b
c') == 'a \nb \nc' - assert md('a
b
c', newline_style=BACKSLASH) == 'a\\\nb\\\nc' def test_em(): assert md('Hello') == '*Hello*' - assert md('Hello', strong_em_symbol='_') == '_Hello_' def test_em_spaces(): @@ -177,7 +174,6 @@ def test_atx_closed_headings(): def test_i(): assert md('Hello') == '*Hello*' - assert md('Hello', strong_em_symbol='_') == '_Hello_' def test_ol(): @@ -191,7 +187,6 @@ def test_p(): def test_strong(): assert md('Hello') == '**Hello**' - assert md('Hello', strong_em_symbol='_') == '__Hello__' def test_ul(): @@ -221,3 +216,14 @@ def test_img(): def test_div(): assert md('Hello World') == 'Hello World' + + +def test_strong_em_symbol(): + assert md('Hello', strong_em_symbol='_') == '__Hello__' + assert md('Hello', strong_em_symbol='_') == '__Hello__' + assert md('Hello', strong_em_symbol='_') == '_Hello_' + assert md('Hello', strong_em_symbol='_') == '_Hello_' + + +def test_newline_style(): + assert md('a
b
c', newline_style=BACKSLASH) == 'a\\\nb\\\nc' From 29c794e17d8a04ff879ac2c6e520d74b12e0e250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20van=20Delft?= Date: Sun, 18 Apr 2021 18:13:29 +0200 Subject: [PATCH 17/18] Introduce OPTIONs for `strong_em_symbol` --- README.rst | 10 ++++++++-- markdownify/__init__.py | 6 +++++- tests/test_conversions.py | 10 +++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index a19fabe..1e245c1 100644 --- a/README.rst +++ b/README.rst @@ -76,10 +76,16 @@ bullets level. Defaults to ``'*+-'``. strong_em_symbol - In markdown, both ``*`` and ``_`` are used to encode **strong** or *emphasized* texts. The preferred symbol can be passed through this argument, that defaults to ``*``. + In markdown, both ``*`` and ``_`` are used to encode **strong** or + *emphasized* texts. Either of these symbols can be chosen by the options + ``ASTERISK`` (default) or ``UNDERSCORE`` respectively. newline_style - Defines the style of marking linebreaks (``
``) in markdown. The default value ``SPACES`` of this option will adopt the usual two spaces and a newline, while ``BACKSLASH`` will convert a linebreak to ``\\n`` (a backslash an a newline). While the latter convention is non-standard, it is commonly preferred and supported by a lot of interpreters. + Defines the style of marking linebreaks (``
``) in markdown. The default + value ``SPACES`` of this option will adopt the usual two spaces and a newline, + while ``BACKSLASH`` will convert a linebreak to ``\\n`` (a backslash an a + newline). While the latter convention is non-standard, it is commonly + preferred and supported by a lot of interpreters. Options may be specified as kwargs to the ``markdownify`` function, or as a nested ``Options`` class in ``MarkdownConverter`` subclasses. diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 08819aa..6f90d73 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -19,6 +19,10 @@ SETEXT = UNDERLINED SPACES = 'spaces' BACKSLASH = 'backslash' +# Strong and emphasis style +ASTERISK = '*' +UNDERSCORE = '_' + def escape(text): if not text: @@ -50,7 +54,7 @@ class MarkdownConverter(object): autolinks = True heading_style = UNDERLINED bullets = '*+-' # An iterable of bullet types. - strong_em_symbol = '*' + strong_em_symbol = ASTERISK newline_style = SPACES class Options(DefaultOptions): diff --git a/tests/test_conversions.py b/tests/test_conversions.py index d07d487..e974c78 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -1,4 +1,4 @@ -from markdownify import markdownify as md, ATX, ATX_CLOSED, BACKSLASH +from markdownify import markdownify as md, ATX, ATX_CLOSED, BACKSLASH, UNDERSCORE import re @@ -219,10 +219,10 @@ def test_div(): def test_strong_em_symbol(): - assert md('Hello', strong_em_symbol='_') == '__Hello__' - assert md('Hello', strong_em_symbol='_') == '__Hello__' - assert md('Hello', strong_em_symbol='_') == '_Hello_' - assert md('Hello', strong_em_symbol='_') == '_Hello_' + assert md('Hello', strong_em_symbol=UNDERSCORE) == '__Hello__' + assert md('Hello', strong_em_symbol=UNDERSCORE) == '__Hello__' + assert md('Hello', strong_em_symbol=UNDERSCORE) == '_Hello_' + assert md('Hello', strong_em_symbol=UNDERSCORE) == '_Hello_' def test_newline_style(): From d4882b86b9c308699fa73dfe79747799f19c5192 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Thu, 22 Apr 2021 12:12:51 +0200 Subject: [PATCH 18/18] bump to v0.6.6 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 848f8bc..db71182 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read() pkgmeta = { '__title__': 'markdownify', '__author__': 'Matthew Tretter', - '__version__': '0.6.5', + '__version__': '0.6.6', }