Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion readme_renderer/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

__all__ = [
"__title__",
Expand Down
1 change: 0 additions & 1 deletion readme_renderer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function
1 change: 0 additions & 1 deletion readme_renderer/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import, print_function
import argparse
from readme_renderer.rst import render
import sys
Expand Down
1 change: 0 additions & 1 deletion readme_renderer/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

import functools
from typing import Any, Dict, Iterator, List, Optional
Expand Down
3 changes: 1 addition & 2 deletions readme_renderer/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

import re
import warnings
Expand Down Expand Up @@ -117,7 +116,7 @@ def replacer(match: Match[Any]) -> str:

highlighted = pygments.highlight(code, lexer, formatter)

return '<pre>{}</pre>'.format(highlighted)
return f'<pre>{highlighted}</pre>'

result = code_expr.sub(replacer, html)

Expand Down
3 changes: 1 addition & 2 deletions readme_renderer/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

import io
from typing import Any, Dict, IO, Optional, Union
Expand Down Expand Up @@ -43,7 +42,7 @@ def emptytag(
if "height" in node:
attributes["height"] = node["height"]

return super(ReadMeHTMLTranslator, self).emptytag(
return super().emptytag(
node, tagname, suffix, **attributes
)

Expand Down
10 changes: 1 addition & 9 deletions readme_renderer/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

import sys
from typing import Any, Optional

from .clean import clean

if sys.version_info >= (3,):
from html import escape as html_escape
else:
from cgi import escape

def html_escape(s):
return escape(s, quote=True).replace("'", '&#x27;')
from html import escape as html_escape


def render(raw: str, **kwargs: Any) -> Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
license_file = LICENSE
license_files = LICENSE
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

import os
import pathlib

import setuptools

base_dir = os.path.dirname(__file__)
base_dir = pathlib.Path(__file__).parent

with open(os.path.join(base_dir, "readme_renderer", "__about__.py")) as f:
with open(base_dir.joinpath("readme_renderer", "__about__.py")) as f:
about = {}
exec(f.read(), about)

with open(os.path.join(base_dir, "README.rst")) as f:
with open(base_dir.joinpath("README.rst")) as f:
long_description = f.read()


Expand Down
27 changes: 8 additions & 19 deletions tests/test_markdown.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
import io
import glob
import os
from pathlib import Path

import pytest

from readme_renderer.markdown import render, variants


MD_FIXTURES = [
(fn, os.path.splitext(fn)[0] + ".html", variant)
for variant in variants
for fn in glob.iglob(
os.path.join(
os.path.dirname(__file__),
"fixtures",
"test_" + variant + "*.md"
)
)
]


@pytest.mark.parametrize(
("md_filename", "html_filename", "variant"),
MD_FIXTURES,
[
(pytest.param(fn, fn.with_suffix(".html"), variant, id=fn.name))
for variant in variants
for fn in Path(__file__).parent.glob(f"fixtures/test_{variant}*.md")
],
)
def test_md_fixtures(md_filename, html_filename, variant):
# Get our Markup
with io.open(md_filename, encoding='utf-8') as f:
with open(md_filename, encoding='utf-8') as f:
md_markup = f.read()

# Get our expected
with io.open(html_filename, encoding="utf-8") as f:
with open(html_filename, encoding="utf-8") as f:
expected = f.read()

assert render(md_markup, variant=variant) == expected
Expand Down
13 changes: 5 additions & 8 deletions tests/test_rst.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import io
import glob
import os.path
from pathlib import Path

import pytest

Expand All @@ -10,19 +9,17 @@
@pytest.mark.parametrize(
("rst_filename", "html_filename"),
[
(fn, os.path.splitext(fn)[0] + ".html")
for fn in glob.glob(
os.path.join(os.path.dirname(__file__), "fixtures", "test_*.rst")
)
(pytest.param(fn, fn.with_suffix(".html"), id=fn.name))
for fn in Path(__file__).parent.glob("fixtures/test_*.rst")
],
)
def test_rst_fixtures(rst_filename, html_filename):
# Get our Markup
with io.open(rst_filename, encoding='utf-8') as f:
with open(rst_filename, encoding='utf-8') as f:
rst_markup = f.read()

# Get our expected
with io.open(html_filename, encoding="utf-8") as f:
with open(html_filename, encoding="utf-8") as f:
expected = f.read()

out = render(rst_markup)
Expand Down
14 changes: 5 additions & 9 deletions tests/test_txt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import io
import glob
import os.path
from pathlib import Path

import pytest

Expand All @@ -10,19 +8,17 @@
@pytest.mark.parametrize(
("txt_filename", "html_filename"),
[
(fn, os.path.splitext(fn)[0] + ".html")
for fn in glob.glob(
os.path.join(os.path.dirname(__file__), "fixtures", "test_*.txt")
)
(pytest.param(fn, fn.with_suffix(".html"), id=fn.name))
for fn in Path(__file__).parent.glob("fixtures/test_*.txt")
],
)
def test_txt_fixtures(txt_filename, html_filename):
# Get our Markup
with io.open(txt_filename, encoding='utf-8') as f:
with open(txt_filename, encoding='utf-8') as f:
txt_markup = f.read()

# Get our expected
with io.open(html_filename, encoding="utf-8") as f:
with open(html_filename, encoding="utf-8") as f:
expected = f.read()

out = render(txt_markup)
Expand Down