clld-markdown-plugin 0.5.0__tar.gz → 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/PKG-INFO +18 -4
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/setup.cfg +6 -4
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/src/clld_markdown_plugin/__init__.py +49 -40
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/src/clld_markdown_plugin.egg-info/PKG-INFO +19 -5
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/src/clld_markdown_plugin.egg-info/requires.txt +3 -0
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/LICENSE +0 -0
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/README.md +0 -0
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/pyproject.toml +0 -0
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/setup.py +0 -0
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/src/clld_markdown_plugin.egg-info/SOURCES.txt +0 -0
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/src/clld_markdown_plugin.egg-info/dependency_links.txt +0 -0
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/src/clld_markdown_plugin.egg-info/not-zip-safe +0 -0
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/src/clld_markdown_plugin.egg-info/top_level.txt +0 -0
- {clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/tests/test_unit.py +0 -0
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: clld_markdown_plugin
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Render CLDF markdown in clld apps.
|
|
5
5
|
Home-page: https://github.com/clld/clld-markdown-plugin
|
|
6
6
|
Author: Robert Forkel, Florian Matter
|
|
7
7
|
Author-email: robert_forkel@eva.mpg.de, florianmatter@gmail.com
|
|
8
8
|
Project-URL: Bug Tracker, https://github.com/clld/clld-markdown-plugin/issues
|
|
9
|
-
Classifier: Development Status ::
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
10
|
Classifier: Intended Audience :: Science/Research
|
|
11
11
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
12
|
Classifier: Natural Language :: English
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.9
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
20
|
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: frontmatter<1.2; python_version < "3.10"
|
|
23
|
+
Requires-Dist: clldutils
|
|
24
|
+
Requires-Dist: pycldf
|
|
25
|
+
Requires-Dist: clld
|
|
26
|
+
Requires-Dist: markdown
|
|
20
27
|
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: flake8; extra == "dev"
|
|
29
|
+
Requires-Dist: twine; extra == "dev"
|
|
30
|
+
Requires-Dist: wheel; extra == "dev"
|
|
31
|
+
Requires-Dist: build; extra == "dev"
|
|
21
32
|
Provides-Extra: test
|
|
22
|
-
|
|
33
|
+
Requires-Dist: pytest; extra == "test"
|
|
34
|
+
Requires-Dist: pytest-mock; extra == "test"
|
|
35
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
36
|
+
Requires-Dist: tox; extra == "test"
|
|
23
37
|
|
|
24
38
|
# clld-markdown-plugin
|
|
25
39
|
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
[metadata]
|
|
2
|
-
version = 0.
|
|
2
|
+
version = 1.0.0
|
|
3
3
|
author = Robert Forkel, Florian Matter
|
|
4
4
|
author_email = robert_forkel@eva.mpg.de, florianmatter@gmail.com
|
|
5
5
|
classifiers =
|
|
6
|
-
Development Status ::
|
|
6
|
+
Development Status :: 5 - Production/Stable
|
|
7
7
|
Intended Audience :: Science/Research
|
|
8
8
|
License :: OSI Approved :: Apache Software License
|
|
9
9
|
Natural Language :: English
|
|
10
10
|
Programming Language :: Python :: 3
|
|
11
|
-
Programming Language :: Python :: 3.8
|
|
12
11
|
Programming Language :: Python :: 3.9
|
|
13
12
|
Programming Language :: Python :: 3.10
|
|
14
13
|
Programming Language :: Python :: 3.11
|
|
15
14
|
Programming Language :: Python :: 3.12
|
|
15
|
+
Programming Language :: Python :: 3.13
|
|
16
|
+
Programming Language :: Python :: 3.14
|
|
16
17
|
description = Render CLDF markdown in clld apps.
|
|
17
18
|
long_description = file: README.md
|
|
18
19
|
long_description_content_type = text/markdown
|
|
@@ -28,6 +29,7 @@ packages = find:
|
|
|
28
29
|
package_dir =
|
|
29
30
|
=src
|
|
30
31
|
install_requires =
|
|
32
|
+
frontmatter<1.2;python_version<"3.10"
|
|
31
33
|
clldutils
|
|
32
34
|
pycldf
|
|
33
35
|
clld
|
|
@@ -67,7 +69,7 @@ source =
|
|
|
67
69
|
show_missing = true
|
|
68
70
|
|
|
69
71
|
[tox:tox]
|
|
70
|
-
envlist =
|
|
72
|
+
envlist = py39, py310, py311, py312, py313, py314
|
|
71
73
|
isolated_build = true
|
|
72
74
|
skip_missing_interpreter = true
|
|
73
75
|
|
{clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/src/clld_markdown_plugin/__init__.py
RENAMED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"""Top-level package for clld-markdown-plugin."""
|
|
2
|
-
import typing
|
|
3
2
|
import logging
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from typing import Optional, Callable, Any
|
|
4
5
|
|
|
5
6
|
from markdown import Markdown
|
|
6
7
|
from markdown import markdown as base_markdown
|
|
7
8
|
from pycldf.ext.markdown import CLDFMarkdownLink
|
|
9
|
+
from clld.web.app import ClldRequest
|
|
8
10
|
from clld.db.meta import DBSession
|
|
9
11
|
from clld.db.models import common
|
|
10
12
|
from clld.web.util.helpers import rendered_sentence
|
|
@@ -16,11 +18,12 @@ log = logging.getLogger(__name__)
|
|
|
16
18
|
|
|
17
19
|
__author__ = "Robert Forkel, Florian Matter"
|
|
18
20
|
__email__ = "robert_forkel@eva.mpg.de, florianmatter@gmail.com"
|
|
19
|
-
__version__ = "0.
|
|
21
|
+
__version__ = "1.0.0"
|
|
20
22
|
__all__ = ['markdown', 'includeme']
|
|
21
23
|
|
|
22
24
|
|
|
23
|
-
def settings(custom:
|
|
25
|
+
def settings(custom: Optional[dict[str, Any]] = None) -> dict[str, Any]:
|
|
26
|
+
"""Settings relevant for rendering CLDF Markdown."""
|
|
24
27
|
def full_spec(spec):
|
|
25
28
|
return spec if isinstance(spec, dict) else {
|
|
26
29
|
'route': spec.__name__.split('.')[-1].lower() if spec else '', 'model': spec}
|
|
@@ -47,7 +50,7 @@ def settings(custom: typing.Optional[dict] = None) -> dict:
|
|
|
47
50
|
"keep_link_labels": False,
|
|
48
51
|
}
|
|
49
52
|
custom = custom or {}
|
|
50
|
-
for key in res:
|
|
53
|
+
for key in res: # pylint: disable=consider-using-dict-items
|
|
51
54
|
if key == 'model_map':
|
|
52
55
|
for k, v in custom.get(key, {}).items():
|
|
53
56
|
res[key][k] = full_spec(v)
|
|
@@ -78,41 +81,48 @@ def includeme(config):
|
|
|
78
81
|
return config
|
|
79
82
|
|
|
80
83
|
|
|
81
|
-
def
|
|
84
|
+
def _comma_and_list(entries: Sequence[str], sep1: str = ", ", sep2: str = " and ") -> str:
|
|
82
85
|
output = entries[0]
|
|
83
86
|
for entry in entries[1:-1]:
|
|
84
87
|
output += sep1 + entry
|
|
85
88
|
return output + sep2 + entries[-1]
|
|
86
89
|
|
|
87
90
|
|
|
88
|
-
def link_entity(
|
|
91
|
+
def link_entity( # pylint: disable=R0913,R0917
|
|
92
|
+
req: ClldRequest,
|
|
93
|
+
objid: str,
|
|
94
|
+
route: str,
|
|
95
|
+
model: type,
|
|
96
|
+
session,
|
|
97
|
+
decorate: Optional[Callable[[str], str]] = None,
|
|
98
|
+
ids: Optional[Sequence[str]] = None,
|
|
99
|
+
**kwargs,
|
|
100
|
+
) -> str:
|
|
101
|
+
"""Render a CLDF Markdown link as HTML."""
|
|
89
102
|
if objid == "__all__":
|
|
90
103
|
if ids:
|
|
91
|
-
|
|
104
|
+
return _comma_and_list([
|
|
92
105
|
link_entity(req, mid, route, model, session, decorate=decorate, **kwargs)
|
|
93
106
|
for mid in ids[0].split(",")
|
|
94
|
-
]
|
|
95
|
-
return comma_and_list(md_strs)
|
|
107
|
+
])
|
|
96
108
|
raise NotImplementedError("Table not yet implemented") # pragma: no cover
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def render_ex(req, objid, table, session, ids=None, **kw):
|
|
109
|
+
try:
|
|
110
|
+
entity = session.query(model).filter(model.id == objid)[0]
|
|
111
|
+
except IndexError as e:
|
|
112
|
+
raise ValueError(objid) from e # pragma: no cover
|
|
113
|
+
label = kwargs.pop("label", [None])[0] or entity.name
|
|
114
|
+
anchor = kwargs.pop("_anchor", [None])[0]
|
|
115
|
+
url = req.route_url(route, id=objid, _anchor=anchor, **kwargs)
|
|
116
|
+
md_str = f'<a class="{model.__tablename__.capitalize()}" href="{url}">{label}</a>'
|
|
117
|
+
return decorate(md_str) if decorate else md_str
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def render_ex(req: ClldRequest, objid: str, table: str, session, ids=None, **_) -> str:
|
|
121
|
+
"""Render an IGT example."""
|
|
111
122
|
if objid == "__all__":
|
|
112
123
|
if ids:
|
|
113
124
|
ex_strs = [
|
|
114
|
-
render_ex(req, mid, table, session, subexample=True) for mid in ids[0].split(",")
|
|
115
|
-
]
|
|
125
|
+
render_ex(req, mid, table, session, subexample=True) for mid in ids[0].split(",")]
|
|
116
126
|
return '\n\n'.join(ex_strs)
|
|
117
127
|
return rendered_sentence(session.query(common.Sentence).filter(common.Sentence.id == objid)[0])
|
|
118
128
|
|
|
@@ -127,9 +137,8 @@ def markdown(req, s: str, session=None) -> str:
|
|
|
127
137
|
"""
|
|
128
138
|
if __name__ not in req.registry.settings: # pragma: no cover
|
|
129
139
|
raise KeyError(
|
|
130
|
-
'{} must be included in the app config to use the "markdown" function.'
|
|
131
|
-
|
|
132
|
-
settings = req.registry.settings[__name__]
|
|
140
|
+
f'{__name__} must be included in the app config to use the "markdown" function.')
|
|
141
|
+
settings_ = req.registry.settings[__name__]
|
|
133
142
|
source_ids = set()
|
|
134
143
|
|
|
135
144
|
def repl(ml):
|
|
@@ -141,19 +150,19 @@ def markdown(req, s: str, session=None) -> str:
|
|
|
141
150
|
if ml.is_cldf_link:
|
|
142
151
|
try:
|
|
143
152
|
table = ml.table_or_fname
|
|
144
|
-
if table in
|
|
145
|
-
return
|
|
153
|
+
if table in settings_['renderer_map'] and "as_link" not in ml.parsed_url_query:
|
|
154
|
+
return settings_['renderer_map'][table](
|
|
146
155
|
req, ml.objid, table, session or DBSession, **ml.parsed_url_query)
|
|
147
|
-
|
|
148
|
-
decorate =
|
|
149
|
-
kw =
|
|
150
|
-
if ml.label and
|
|
156
|
+
if table in settings_['model_map']:
|
|
157
|
+
decorate = settings_['model_map'][table].get("decorate", None)
|
|
158
|
+
kw = dict(ml.parsed_url_query.items())
|
|
159
|
+
if ml.label and settings_['keep_link_labels']:
|
|
151
160
|
kw.setdefault('label', [ml.label])
|
|
152
161
|
if table == 'Source':
|
|
153
162
|
if ml.objid != '__all__':
|
|
154
163
|
source_ids.add(ml.objid)
|
|
155
164
|
elif 'cited_only' in ml.parsed_url.query:
|
|
156
|
-
model =
|
|
165
|
+
model = settings_['model_map'][table]["model"]
|
|
157
166
|
return HTML.ul(*[
|
|
158
167
|
HTML.li(literal(ref(
|
|
159
168
|
(session or DBSession).query(model).filter(model.id == sid)[0]
|
|
@@ -162,16 +171,16 @@ def markdown(req, s: str, session=None) -> str:
|
|
|
162
171
|
return link_entity(
|
|
163
172
|
req,
|
|
164
173
|
ml.objid,
|
|
165
|
-
|
|
166
|
-
|
|
174
|
+
settings_['model_map'][table]["route"],
|
|
175
|
+
settings_['model_map'][table]["model"],
|
|
167
176
|
session or DBSession,
|
|
168
177
|
decorate=decorate,
|
|
169
178
|
**kw,
|
|
170
179
|
)
|
|
171
|
-
log.error(
|
|
180
|
+
log.error("Can't handle [%s] (%s).", ml.objid, table)
|
|
172
181
|
return f"{table}:{ml.objid}"
|
|
173
|
-
except: # noqa: E722
|
|
182
|
+
except: # noqa: E722 # pylint: disable=W0702
|
|
174
183
|
return ml.label
|
|
175
184
|
return ml
|
|
176
185
|
|
|
177
|
-
return Markdown(extensions=
|
|
186
|
+
return Markdown(extensions=settings_["extensions"]).convert(CLDFMarkdownLink.replace(s, repl))
|
{clld_markdown_plugin-0.5.0 → clld_markdown_plugin-1.0.0}/src/clld_markdown_plugin.egg-info/PKG-INFO
RENAMED
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
|
-
Name:
|
|
3
|
-
Version: 0.
|
|
2
|
+
Name: clld_markdown_plugin
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Render CLDF markdown in clld apps.
|
|
5
5
|
Home-page: https://github.com/clld/clld-markdown-plugin
|
|
6
6
|
Author: Robert Forkel, Florian Matter
|
|
7
7
|
Author-email: robert_forkel@eva.mpg.de, florianmatter@gmail.com
|
|
8
8
|
Project-URL: Bug Tracker, https://github.com/clld/clld-markdown-plugin/issues
|
|
9
|
-
Classifier: Development Status ::
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
10
|
Classifier: Intended Audience :: Science/Research
|
|
11
11
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
12
|
Classifier: Natural Language :: English
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.9
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
20
|
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: frontmatter<1.2; python_version < "3.10"
|
|
23
|
+
Requires-Dist: clldutils
|
|
24
|
+
Requires-Dist: pycldf
|
|
25
|
+
Requires-Dist: clld
|
|
26
|
+
Requires-Dist: markdown
|
|
20
27
|
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: flake8; extra == "dev"
|
|
29
|
+
Requires-Dist: twine; extra == "dev"
|
|
30
|
+
Requires-Dist: wheel; extra == "dev"
|
|
31
|
+
Requires-Dist: build; extra == "dev"
|
|
21
32
|
Provides-Extra: test
|
|
22
|
-
|
|
33
|
+
Requires-Dist: pytest; extra == "test"
|
|
34
|
+
Requires-Dist: pytest-mock; extra == "test"
|
|
35
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
36
|
+
Requires-Dist: tox; extra == "test"
|
|
23
37
|
|
|
24
38
|
# clld-markdown-plugin
|
|
25
39
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|