clld-markdown-plugin 0.2.0__tar.gz → 0.3.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.
@@ -1,21 +1,21 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clld_markdown_plugin
3
- Version: 0.2.0
3
+ Version: 0.3.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
- Author-email: forkel@shh.mpg.de, florianmatter@gmail.com
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
9
  Classifier: Development Status :: 2 - Pre-Alpha
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.7
15
14
  Classifier: Programming Language :: Python :: 3.8
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
19
  Description-Content-Type: text/markdown
20
20
  Provides-Extra: dev
21
21
  Provides-Extra: test
@@ -1,17 +1,17 @@
1
1
  [metadata]
2
2
  author = Robert Forkel, Florian Matter
3
- author_email = forkel@shh.mpg.de, florianmatter@gmail.com
3
+ author_email = robert_forkel@eva.mpg.de, florianmatter@gmail.com
4
4
  classifiers =
5
5
  Development Status :: 2 - Pre-Alpha
6
6
  Intended Audience :: Science/Research
7
7
  License :: OSI Approved :: Apache Software License
8
8
  Natural Language :: English
9
9
  Programming Language :: Python :: 3
10
- Programming Language :: Python :: 3.7
11
10
  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
14
+ Programming Language :: Python :: 3.12
15
15
  description = Render CLDF markdown in clld apps.
16
16
  long_description = file: README.md
17
17
  long_description_content_type = text/markdown
@@ -19,7 +19,7 @@ name = clld_markdown_plugin
19
19
  project_urls =
20
20
  Bug Tracker = https://github.com/clld/clld-markdown-plugin/issues
21
21
  url = https://github.com/clld/clld-markdown-plugin
22
- version = 0.2.0
22
+ version = 0.3.0
23
23
 
24
24
  [options]
25
25
  zip_safe = False
@@ -66,7 +66,7 @@ source =
66
66
  show_missing = true
67
67
 
68
68
  [tox:tox]
69
- envlist = py37, py38, py39, py310, py311
69
+ envlist = py38, py39, py310, py311, py312
70
70
  isolated_build = true
71
71
  skip_missing_interpreter = true
72
72
 
@@ -7,12 +7,13 @@ from pycldf.ext.markdown import CLDFMarkdownLink
7
7
  from clld.db.meta import DBSession
8
8
  from clld.db.models import common
9
9
  from clld.web.util.helpers import rendered_sentence
10
+ from clld.web.util.htmllib import HTML, literal
10
11
 
11
12
  log = logging.getLogger(__name__)
12
13
 
13
14
  __author__ = "Robert Forkel, Florian Matter"
14
15
  __email__ = "robert_forkel@eva.mpg.de, florianmatter@gmail.com"
15
- __version__ = "0.2.0"
16
+ __version__ = "0.3.0"
16
17
  __all__ = ['markdown', 'includeme']
17
18
 
18
19
 
@@ -82,18 +83,21 @@ def link_entity(req, objid, route, model, session, decorate=None, ids=None, **kw
82
83
  if objid == "__all__":
83
84
  if ids:
84
85
  md_strs = [
85
- link_entity(req, mid, route, model, session, decorate=decorate)
86
+ link_entity(req, mid, route, model, session, decorate=decorate, **kwargs)
86
87
  for mid in ids[0].split(",")
87
88
  ]
88
89
  return comma_and_list(md_strs)
89
90
  raise NotImplementedError("Table not yet implemented") # pragma: no cover
90
91
  else:
91
- entity = session.query(model).filter(model.id == objid)[0]
92
- anchor = kwargs.pop("_anchor", None)
93
- if isinstance(anchor, list):
94
- anchor = anchor[0]
92
+ try:
93
+ entity = session.query(model).filter(model.id == objid)[0]
94
+ except IndexError:
95
+ raise ValueError(objid) # pragma: no cover
96
+ label = kwargs.pop("label", [None])[0]
97
+ anchor = kwargs.pop("_anchor", [None])[0]
95
98
  url = req.route_url(route, id=objid, _anchor=anchor, **kwargs)
96
- md_str = f"""<a class="{model.__tablename__.capitalize()}" href="{url}">{entity.name}</a>"""
99
+ md_str = '<a class="{}" href="{}">{}</a>'.format(
100
+ model.__tablename__.capitalize(), url, label or entity.name)
97
101
  return decorate(md_str) if decorate else md_str
98
102
 
99
103
 
@@ -120,6 +124,7 @@ def markdown(req, s: str, session=None) -> str:
120
124
  '{} must be included in the app config to use the "markdown" function.'.format(
121
125
  __name__))
122
126
  settings = req.registry.settings[__name__]
127
+ source_ids = set()
123
128
 
124
129
  def repl(ml):
125
130
  if ml.is_cldf_link:
@@ -130,6 +135,17 @@ def markdown(req, s: str, session=None) -> str:
130
135
  req, ml.objid, table, session or DBSession, **ml.parsed_url_query)
131
136
  elif table in settings['model_map']:
132
137
  decorate = settings['model_map'][table].get("decorate", None)
138
+ kw = {k: v for k, v in ml.parsed_url_query.items()}
139
+ if table == 'Source':
140
+ if ml.objid != '__all__':
141
+ source_ids.add(ml.objid)
142
+ elif 'cited_only' in ml.parsed_url.query:
143
+ model = settings['model_map'][table]["model"]
144
+ return HTML.ul(*[
145
+ HTML.li(literal(
146
+ (session or DBSession).query(model)
147
+ .filter(model.id == sid)[0].bibtex().text()))
148
+ for sid in sorted(source_ids)])
133
149
  return link_entity(
134
150
  req,
135
151
  ml.objid,
@@ -137,7 +153,7 @@ def markdown(req, s: str, session=None) -> str:
137
153
  settings['model_map'][table]["model"],
138
154
  session or DBSession,
139
155
  decorate=decorate,
140
- **ml.parsed_url_query,
156
+ **kw,
141
157
  )
142
158
  log.error(f"Can't handle [{ml.objid}] ({table}).")
143
159
  return f"{table}:{ml.objid}"
@@ -1,21 +1,21 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clld-markdown-plugin
3
- Version: 0.2.0
3
+ Version: 0.3.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
- Author-email: forkel@shh.mpg.de, florianmatter@gmail.com
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
9
  Classifier: Development Status :: 2 - Pre-Alpha
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.7
15
14
  Classifier: Programming Language :: Python :: 3.8
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
18
17
  Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
19
  Description-Content-Type: text/markdown
20
20
  Provides-Extra: dev
21
21
  Provides-Extra: test
@@ -0,0 +1,31 @@
1
+ import pytest
2
+
3
+ from clld_markdown_plugin import *
4
+
5
+
6
+ @pytest.mark.parametrize(
7
+ 'model_map,renderer_map,md,substring,notsubstring',
8
+ [
9
+ (dict(LanguageTable=None), {}, '[xyz](LanguageTable#cldf:l1)', 'xyz', None),
10
+ ({}, {}, '[xyz](LanguageTable#cldf:l1)', 'The Language', None),
11
+ ({}, {}, '[xyz](LanguageTable?_anchor=abc#cldf:l1)', '#abc', None),
12
+ ({}, {}, '[xyz](LanguageTable?ids=l1,l2,l3#cldf:__all__)', ' and ', None),
13
+ ({}, {}, '[xyz](ExampleTable#cldf:s1)', 'A sentence', None),
14
+ ({}, {}, '[xyz](ExampleTable?as_link#cldf:s1)', 'href=', None),
15
+ ({}, {}, '[xyz](ExampleTable?ids=s1#cldf:__all__)', '', None),
16
+ ({}, {}, '[xyz](NopeTable#cldf:1)', 'NopeTable', None),
17
+ (
18
+ {},
19
+ {},
20
+ '[](Source#cldf:Meier2012)\n[](Source?cited_only#cldf:__all__)',
21
+ 'Meier',
22
+ 'Mueller'),
23
+ ({}, {}, '[xyz](http://example.org)', 'http://example.org', None),
24
+ ]
25
+ )
26
+ def test_markdown(model_map, renderer_map, md, substring, notsubstring, dbsession, req_factory):
27
+ res = markdown(
28
+ req_factory(dict(model_map=model_map, renderer_map=renderer_map)), md, session=dbsession)
29
+ assert substring in res
30
+ if notsubstring:
31
+ assert notsubstring not in res
@@ -1,22 +0,0 @@
1
- import pytest
2
-
3
- from clld_markdown_plugin import *
4
-
5
-
6
- @pytest.mark.parametrize(
7
- 'model_map,renderer_map,md,substring',
8
- [
9
- (dict(LanguageTable=None), {}, '[xyz](LanguageTable#cldf:l1)', 'xyz'),
10
- ({}, {}, '[xyz](LanguageTable#cldf:l1)', 'The Language'),
11
- ({}, {}, '[xyz](LanguageTable?_anchor=abc#cldf:l1)', '#abc'),
12
- ({}, {}, '[xyz](LanguageTable?ids=l1,l2,l3#cldf:__all__)', ' and '),
13
- ({}, {}, '[xyz](ExampleTable#cldf:s1)', 'A sentence'),
14
- ({}, {}, '[xyz](ExampleTable?as_link#cldf:s1)', 'href='),
15
- ({}, {}, '[xyz](ExampleTable?ids=s1#cldf:__all__)', ''),
16
- ({}, {}, '[xyz](NopeTable#cldf:1)', 'NopeTable'),
17
- ({}, {}, '[xyz](http://example.org)', 'http://example.org'),
18
- ]
19
- )
20
- def test_markdown(model_map, renderer_map, md, substring, dbsession, req_factory):
21
- assert substring in markdown(
22
- req_factory(dict(model_map=model_map, renderer_map=renderer_map)), md, session=dbsession)