summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Diemer <git@jensdiemer.de>2022-08-23 08:10:48 +0200
committerGitHub <noreply@github.com>2022-08-23 08:10:48 +0200
commit7e71bf60ca8b57102c81cba5770c53e11cec526e (patch)
tree643b4cbf19bb4ec78bf2ceacc0533ebdd8a591ce
parent956675a7b4c6f9e66e85a3163cbc2c75e138910d (diff)
parent8c37f13d04937dec85056dae7cf8621c9752e157 (diff)
downloadcreole-7e71bf60ca8b57102c81cba5770c53e11cec526e.tar.gz
Merge pull request #71 from jedie/dev
Dev
-rw-r--r--README.creole11
-rw-r--r--README.md13
-rw-r--r--README.rst16
-rw-r--r--creole/__init__.py2
-rw-r--r--creole/emitter/html2markdown_emitter.py28
-rw-r--r--creole/tests/test_html2markdown.py44
-rw-r--r--pyproject.toml2
7 files changed, 90 insertions, 26 deletions
diff --git a/README.creole b/README.creole
index 9df85ba..1bb507f 100644
--- a/README.creole
+++ b/README.creole
@@ -3,8 +3,8 @@
python-creole is a OpenSource (GPL) Python lib for converting markups.
python-creole is pure python. No external libs needed.
-Compatible Python Versions (see [[https://github.com/jedie/python-creole/blob/main/tox.ini|tox.ini]]):
- * 3.9, 3.8, 3.7, 3.6
+Compatible Python Versions (see [[https://github.com/jedie/python-creole/blob/main/pyproject.toml|tox config in pyproject.toml]]):
+ * 3.9, 3.8, 3.7
* PyPy3
@@ -15,6 +15,7 @@ Existing converters:
* reSt -> html (for clean html code)
* html -> reStructuredText markup (only a subset of reSt supported)
* html -> textile markup (not completed yet)
+* html -> markdown markup
The creole2html part based on the creole markup parser and emitter from the MoinMoin project by Radomir Dopieralski and Thomas Waldmann.
@@ -221,9 +222,9 @@ Note: In this case you must install **docutils**! See above.
= history =
-* [[https://github.com/jedie/python-creole/compare/v1.5.0.rc2...master|*dev*]]
+* [[https://github.com/jedie/python-creole/compare/v1.5.0.rc3...master|*dev*]]
** TBC
-* [[https://github.com/jedie/python-creole/compare/v1.4.10...v1.5.0.rc2|v1.5.0.rc2 - 2022-08-20]]
+* [[https://github.com/jedie/python-creole/compare/v1.4.10...v1.5.0.rc3|v1.5.0.rc3 - 2022-08-20]]
** NEW: html2markdown
** creole2html bugfixes:
*** replace wrong {{{<tt>}}} with {{{<code>}}}
@@ -250,7 +251,7 @@ Note: In this case you must install **docutils**! See above.
** new: {{{creole.setup_utils.assert_rst_readme}}} for project setup tests
** use https://github.com/ymyzk/tox-gh-actions on gitlab CI
* v1.4.4 - 2020-02-07 - [[https://github.com/jedie/python-creole/compare/v1.4.3...v1.4.4|compare v1.4.3...v1.4.4]]
-** Fix #44: Move {{{poetry-publish}}} to {{{dev-dependencies}}} and lower {{{docutils}}} requirement to {{^0.15}}
+** Fix #44: Move {{{poetry-publish}}} to {{{dev-dependencies}}} and lower {{{docutils}}} requirement to {{{^0.15}}}
** some code style updated
** Always update README.rst before publish
* v1.4.3 - 2020-02-01 - [[https://github.com/jedie/python-creole/compare/v1.4.2...v1.4.3|compare v1.4.2...v1.4.3]]
diff --git a/README.md b/README.md
index 3442a80..047689f 100644
--- a/README.md
+++ b/README.md
@@ -3,10 +3,10 @@
python-creole is a OpenSource (GPL) Python lib for converting markups.
python-creole is pure python. No external libs needed.
-Compatible Python Versions (see [tox.ini](https://github.com/jedie/python-creole/blob/main/tox.ini)):
+Compatible Python Versions (see [tox config in pyproject.toml](https://github.com/jedie/python-creole/blob/main/pyproject.toml)):
-* 3.9, 3.8, 3.7, 3.6
+* 3.9, 3.8, 3.7
* PyPy3
Existing converters:
@@ -17,6 +17,7 @@ Existing converters:
* reSt -> html (for clean html code)
* html -> reStructuredText markup (only a subset of reSt supported)
* html -> textile markup (not completed yet)
+* html -> markdown markup
The creole2html part based on the creole markup parser and emitter from the MoinMoin project by Radomir Dopieralski and Thomas Waldmann.
@@ -226,9 +227,9 @@ Note: In this case you must install **docutils**! See above.
# history
-* [*dev*](https://github.com/jedie/python-creole/compare/v1.5.0.rc2...master)
+* [*dev*](https://github.com/jedie/python-creole/compare/v1.5.0.rc3...master)
* TBC
-* [v1.5.0.rc2 - 2022-08-20](https://github.com/jedie/python-creole/compare/v1.4.10...v1.5.0.rc2)
+* [v1.5.0.rc3 - 2022-08-20](https://github.com/jedie/python-creole/compare/v1.4.10...v1.5.0.rc3)
* NEW: html2markdown
* creole2html bugfixes:
* replace wrong `<tt>` with `<code>`
@@ -255,7 +256,7 @@ Note: In this case you must install **docutils**! See above.
* new: `creole.setup_utils.assert_rst_readme` for project setup tests
* use [https://github.com/ymyzk/tox-gh-actions](https://github.com/ymyzk/tox-gh-actions) on gitlab CI
* v1.4.4 - 2020-02-07 - [compare v1.4.3...v1.4.4](https://github.com/jedie/python-creole/compare/v1.4.3...v1.4.4)
- * Fix #44: Move `poetry-publish` to `dev-dependencies` and lower `docutils` requirement to ![^0.15](^0.15 "^0.15")
+ * Fix #44: Move `poetry-publish` to `dev-dependencies` and lower `docutils` requirement to `^0.15`
* some code style updated
* Always update README.rst before publish
* v1.4.3 - 2020-02-01 - [compare v1.4.2...v1.4.3](https://github.com/jedie/python-creole/compare/v1.4.2...v1.4.3)
@@ -438,4 +439,4 @@ first source code was written 27.11.2008: [Forum thread (de)](http://www.python-
------------
-``Note: this file is generated from README.creole 2022-08-21 00:49:59 with "python-creole"`` \ No newline at end of file
+``Note: this file is generated from README.creole 2022-08-23 07:57:12 with "python-creole"`` \ No newline at end of file
diff --git a/README.rst b/README.rst
index ab4aa17..4f70129 100644
--- a/README.rst
+++ b/README.rst
@@ -5,9 +5,9 @@ about python-creole
python-creole is a OpenSource (GPL) Python lib for converting markups.
python-creole is pure python. No external libs needed.
-Compatible Python Versions (see `tox.ini <https://github.com/jedie/python-creole/blob/main/tox.ini>`_):
+Compatible Python Versions (see `tox config in pyproject.toml <https://github.com/jedie/python-creole/blob/main/pyproject.toml>`_):
-* 3.9, 3.8, 3.7, 3.6
+* 3.9, 3.8, 3.7
* PyPy3
@@ -23,6 +23,8 @@ Existing converters:
* html -> textile markup (not completed yet)
+* html -> markdown markup
+
The creole2html part based on the creole markup parser and emitter from the MoinMoin project by Radomir Dopieralski and Thomas Waldmann.
+-----------------------------------+
@@ -291,11 +293,11 @@ Note: In this case you must install **docutils**! See above.
history
=======
-* `*dev* <https://github.com/jedie/python-creole/compare/v1.5.0.rc2...master>`_
+* `*dev* <https://github.com/jedie/python-creole/compare/v1.5.0.rc3...master>`_
* TBC
-* `v1.5.0.rc2 - 2022-08-20 <https://github.com/jedie/python-creole/compare/v1.4.10...v1.5.0.rc2>`_
+* `v1.5.0.rc3 - 2022-08-20 <https://github.com/jedie/python-creole/compare/v1.4.10...v1.5.0.rc3>`_
* NEW: html2markdown
@@ -349,7 +351,7 @@ history
* v1.4.4 - 2020-02-07 - `compare v1.4.3...v1.4.4 <https://github.com/jedie/python-creole/compare/v1.4.3...v1.4.4>`_
- * Fix #44: Move ``poetry-publish`` to ``dev-dependencies`` and lower ``docutils`` requirement to |^0.15|
+ * Fix #44: Move ``poetry-publish`` to ``dev-dependencies`` and lower ``docutils`` requirement to ``^0.15``
* some code style updated
@@ -679,8 +681,6 @@ history
* first version cut out from `PyLucid CMS <http://www.pylucid.org>`_
-.. |^0.15| image:: ^0.15
-
first source code was written 27.11.2008: `Forum thread (de) <http://www.python-forum.de/viewtopic.php?f=3&t=16742>`_
-------------
@@ -710,4 +710,4 @@ donation
------------
-``Note: this file is generated from README.creole 2022-08-21 00:49:59 with "python-creole"`` \ No newline at end of file
+``Note: this file is generated from README.creole 2022-08-23 07:57:12 with "python-creole"`` \ No newline at end of file
diff --git a/creole/__init__.py b/creole/__init__.py
index f3b056a..5d394f7 100644
--- a/creole/__init__.py
+++ b/creole/__init__.py
@@ -24,7 +24,7 @@ from creole.parser.creol2html_parser import CreoleParser
from creole.parser.html_parser import HtmlParser
-__version__ = "1.5.0.rc2"
+__version__ = "1.5.0.rc3"
__api__ = "1.0" # Creole 1.0 spec - http://wikicreole.org/
VERSION_STRING = __version__ # remove in future
diff --git a/creole/emitter/html2markdown_emitter.py b/creole/emitter/html2markdown_emitter.py
index 848add0..b9bf8a0 100644
--- a/creole/emitter/html2markdown_emitter.py
+++ b/creole/emitter/html2markdown_emitter.py
@@ -8,7 +8,7 @@
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
-
+from urllib.parse import ParseResult, quote, urlparse, urlunparse
from creole.parser.html_parser import HtmlParser
from creole.shared.base_emitter import BaseEmitter
@@ -16,6 +16,19 @@ from creole.shared.document_tree import DocNode
from creole.shared.markup_table import MarkupTable
+def quote_link(uri):
+ """
+ >>> quote_link('http://foo.tld/a image with spaces.png')
+ 'http://foo.tld/a%20image%20with%20spaces.png'
+
+ >>> quote_link('https://foo.tld/a image.png?bar=1#anchor')
+ 'https://foo.tld/a%20image.png?bar=1#anchor'
+ """
+ scheme, netloc, url, params, query, fragment = urlparse(uri)
+ url = quote(url)
+ return urlunparse(ParseResult(scheme, netloc, url, params, query, fragment))
+
+
class MarkdownEmitter(BaseEmitter):
"""
Build from a document_tree (html2creole.parser.HtmlParser instance) a
@@ -109,11 +122,14 @@ class MarkdownEmitter(BaseEmitter):
def tt_emit(self, node: DocNode):
return self._typeface(node, key='##')
+ def _typeface_html(self, node, tag):
+ return f'<{tag}>{self.emit_children(node)}</{tag}>'
+
def sup_emit(self, node: DocNode):
- return self._typeface(node, key='^^')
+ return self._typeface_html(node, tag='sup')
def sub_emit(self, node: DocNode):
- return self._typeface(node, key=',,')
+ return self._typeface_html(node, tag='sub')
def u_emit(self, node: DocNode):
return self._typeface(node, key='__')
@@ -133,7 +149,9 @@ class MarkdownEmitter(BaseEmitter):
def a_emit(self, node: DocNode):
link_text = self.emit_children(node)
- url = node.attrs['href']
+
+ url = quote_link(node.attrs['href'])
+
title = node.attrs.get('title')
if title:
return f'[{link_text}]({url} "{title}")'
@@ -141,7 +159,7 @@ class MarkdownEmitter(BaseEmitter):
return f'[{link_text}]({url})'
def img_emit(self, node: DocNode):
- src = node.attrs['src']
+ src = quote_link(node.attrs['src'])
title = node.attrs.get('title')
alt = node.attrs.get('alt', '')
diff --git a/creole/tests/test_html2markdown.py b/creole/tests/test_html2markdown.py
index 2651339..7ecba0e 100644
--- a/creole/tests/test_html2markdown.py
+++ b/creole/tests/test_html2markdown.py
@@ -31,6 +31,26 @@ class MarkdownTests(BaseCreoleTest):
# debug=True,
)
+ def test_typeface(self):
+ self.assert_html2markdown(
+ markdown_string='This is ~~Strikethrough~~',
+ html_string='<p>This is <del>Strikethrough</del></p>',
+ debug=True,
+ )
+ self.assert_html2markdown(
+ markdown_string='This is <sub>Subscript</sub>',
+ html_string='<p>This is <sub>Subscript</sub></p>',
+ debug=True,
+ )
+ self.assert_html2markdown(
+ markdown_string='This is <sup>Superscript</sup>',
+ html_string='<p>This is <sup>Superscript</sup></p>',
+ debug=True,
+ )
+ self.assert_html2markdown(
+ markdown_string='**This text is _extremely_ important**',
+ html_string='<p><strong>This text is <em>extremely</em> important</strong></p>',
+ )
def test_lists(self):
self.assert_html2markdown(
markdown_string=cleandoc(
@@ -163,3 +183,27 @@ class MarkdownTests(BaseCreoleTest):
),
# debug=True,
)
+
+ def test_links_with_spaces(self):
+ self.assert_html2markdown(
+ markdown_string=cleandoc(
+ '''
+ [one](/foo%20bar.png)
+
+ [/somewhere/foo bar.exe](https://somewhere/foo%20bar.exe?bar=1#anchor "Foo Bar")
+
+ ![Alt text](https://foo.tld/a%20image.png?bar=1#anchor)
+ '''
+ ),
+ html_string=cleandoc(
+ '''
+ <p><a href="/foo bar.png">one</a></p>
+ <p>
+ <a href="https://somewhere/foo bar.exe?bar=1#anchor" title="Foo Bar">
+ /somewhere/foo bar.exe
+ </a>
+ </p>
+ <p><img alt="Alt text" src="https://foo.tld/a image.png?bar=1#anchor" /></p>
+ '''
+ ),
+ )
diff --git a/pyproject.toml b/pyproject.toml
index 1764142..166a480 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python-creole"
-version = "1.5.0.rc2"
+version = "1.5.0.rc3"
description = "python-creole is an open-source (GPL) markup converter in pure Python for: creole2html, html2creole, html2ReSt, html2textile"
# Will be generated from README.creole with: "poetry run update_rst_readme"