From fdddbc5c6e7ed8b633e47a5e607c8f346cd08d0d Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Tue, 23 Aug 2022 07:55:44 +0200 Subject: Bugfix wrong README --- README.creole | 2 +- README.md | 2 +- README.rst | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.creole b/README.creole index 9df85ba..b6c2dbb 100644 --- a/README.creole +++ b/README.creole @@ -250,7 +250,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..81c75ed 100644 --- a/README.md +++ b/README.md @@ -255,7 +255,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) diff --git a/README.rst b/README.rst index ab4aa17..5e6ded5 100644 --- a/README.rst +++ b/README.rst @@ -349,7 +349,7 @@ history * v1.4.4 - 2020-02-07 - `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 +679,6 @@ history * first version cut out from `PyLucid CMS `_ -.. |^0.15| image:: ^0.15 - first source code was written 27.11.2008: `Forum thread (de) `_ ------------- -- cgit v1.2.1 From bb76f33f69ab1326d55a22cb2744e4939dfb5ec8 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Tue, 23 Aug 2022 07:55:57 +0200 Subject: Quote URLs --- README.creole | 4 ++-- README.md | 6 +++--- README.rst | 6 +++--- creole/__init__.py | 2 +- creole/emitter/html2markdown_emitter.py | 21 ++++++++++++++++++--- creole/tests/test_html2markdown.py | 23 +++++++++++++++++++++++ pyproject.toml | 2 +- 7 files changed, 51 insertions(+), 13 deletions(-) diff --git a/README.creole b/README.creole index b6c2dbb..658e3c4 100644 --- a/README.creole +++ b/README.creole @@ -221,9 +221,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 {{{}}} with {{{}}} diff --git a/README.md b/README.md index 81c75ed..c4bfc77 100644 --- a/README.md +++ b/README.md @@ -226,9 +226,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 `` with `` @@ -438,4 +438,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:53:38 with "python-creole"`` \ No newline at end of file diff --git a/README.rst b/README.rst index 5e6ded5..3991f0c 100644 --- a/README.rst +++ b/README.rst @@ -291,11 +291,11 @@ Note: In this case you must install **docutils**! See above. history ======= -* `*dev* `_ +* `*dev* `_ * TBC -* `v1.5.0.rc2 - 2022-08-20 `_ +* `v1.5.0.rc3 - 2022-08-20 `_ * NEW: html2markdown @@ -708,4 +708,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:53:38 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..5e6140a 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 @@ -133,7 +146,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 +156,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..90d4daf 100644 --- a/creole/tests/test_html2markdown.py +++ b/creole/tests/test_html2markdown.py @@ -163,3 +163,26 @@ 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( + ''' +

one

+

+ + /somewhere/foo bar.exe + +

+

Alt text

+ ''' + ), + ) 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" -- cgit v1.2.1 From b1981766858660b34acd59a29de4b9b735e175bf Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Tue, 23 Aug 2022 08:08:07 +0200 Subject: Expand README --- README.creole | 5 +++-- README.md | 7 ++++--- README.rst | 8 +++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.creole b/README.creole index 658e3c4..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. diff --git a/README.md b/README.md index c4bfc77..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. @@ -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-23 07:53:38 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 3991f0c..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 `_): +Compatible Python Versions (see `tox config in 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. +-----------------------------------+ @@ -708,4 +710,4 @@ donation ------------ -``Note: this file is generated from README.creole 2022-08-23 07:53:38 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 -- cgit v1.2.1 From 8c37f13d04937dec85056dae7cf8621c9752e157 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Tue, 23 Aug 2022 08:08:28 +0200 Subject: html2markdown: Handle and --- creole/emitter/html2markdown_emitter.py | 7 +++++-- creole/tests/test_html2markdown.py | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/creole/emitter/html2markdown_emitter.py b/creole/emitter/html2markdown_emitter.py index 5e6140a..b9bf8a0 100644 --- a/creole/emitter/html2markdown_emitter.py +++ b/creole/emitter/html2markdown_emitter.py @@ -122,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)}' + 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='__') diff --git a/creole/tests/test_html2markdown.py b/creole/tests/test_html2markdown.py index 90d4daf..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='

This is Strikethrough

', + debug=True, + ) + self.assert_html2markdown( + markdown_string='This is Subscript', + html_string='

This is Subscript

', + debug=True, + ) + self.assert_html2markdown( + markdown_string='This is Superscript', + html_string='

This is Superscript

', + debug=True, + ) + self.assert_html2markdown( + markdown_string='**This text is _extremely_ important**', + html_string='

This text is extremely important

', + ) def test_lists(self): self.assert_html2markdown( markdown_string=cleandoc( @@ -163,6 +183,7 @@ class MarkdownTests(BaseCreoleTest): ), # debug=True, ) + def test_links_with_spaces(self): self.assert_html2markdown( markdown_string=cleandoc( -- cgit v1.2.1