Skip to content

Commit

Permalink
closes #53
Browse files Browse the repository at this point in the history
  • Loading branch information
xrotwang committed Jul 2, 2024
1 parent 6a1b581 commit db53f9b
Showing 6 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changes

## [Unreleased]

- Support more flexible citation labels in `cldfviz.text`.


## [v1.1.0] - 2024-05-07

- Implemented support for visualization of ParameterNetwork data.
12 changes: 9 additions & 3 deletions docs/text.md
Original file line number Diff line number Diff line change
@@ -64,8 +64,14 @@ to include a list of all **cited** sources. This is supported as follows:
at the location where the list should appear.
2. Discovery of cited sources relies on the references being rendered as links. Thus, it is necessary that all
CLDF markdown links in the document are specified adding the `with_internal_ref_link` URL parameter.
3. If `Source` instances are referenced directly, the `ref` URL parameter needs to be supplied,
e.g. `see [Meier 2012](Source?ref&with_internal_ref_links#cldf:Meier2012)`.
3. If `Source` instances are referenced directly (rather than implicitly as reference for another object), the `ref`
URL parameter needs to be supplied, e.g. `see [Meier 2012](Source?ref&with_internal_ref_links#cldf:Meier2012)`.
4. To support flexible link labels, e.g. for cases like "Meier (2012, 2013)", the label of the CLDF markdown
link can be kept in place (and not be replaced with a label generated from the source metadata), by providing
the `keep_label` URL parameter, i.e. with markdown like
```
Meier ([2012](Source?ref&with_internal_ref_links&keep_label#cldf:Meier2012), [2013](Source?ref&with_internal_ref_links&keep_label#cldf:Meier2013))
```


### Render an object using a selected properties
@@ -74,7 +80,7 @@ Sometimes it is desirable to render an object by just displaying a particular pr
display the `name` or `description` of a Parameter as document title. This can be done using the
`property.md` template:
```
# [](ParameterTable?__template__=property.md&name=name#cldf:param1)
# [](ParameterTable?__template__=property.md&property=name#cldf:param1)
```


2 changes: 1 addition & 1 deletion src/cldfviz/templates/text/Source_detail.md
Original file line number Diff line number Diff line change
@@ -8,5 +8,5 @@
{% import "util.md" as util %}
{% set year_brackets = year_brackets or None %}
{% if ref is defined %}
{{ util.sourceref(ctx, year_brackets=year_brackets, with_internal_ref_link=with_internal_ref_link) }}{% else %}
{{ util.sourceref(ctx, year_brackets=year_brackets, with_internal_ref_link=with_internal_ref_link, label=ml_label if keep_label else None) }}{% else %}
{{ util.source(ctx, with_anchor=with_anchor, with_link=with_link) }}{% endif %}
4 changes: 2 additions & 2 deletions src/cldfviz/templates/text/util.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{#
Template macros
#}
{% macro sourceref(src, year_brackets=None, with_internal_ref_link=False) -%}
{% if with_internal_ref_link %}[{% endif %}{{ src.refkey(year_brackets=year_brackets) }}{% if with_internal_ref_link %}
{% macro sourceref(src, year_brackets=None, with_internal_ref_link=False, label=None) -%}
{% if with_internal_ref_link %}[{% endif %}{{ label or src.refkey(year_brackets=year_brackets) }}{% if with_internal_ref_link %}
](#{% if with_internal_ref_link is string %}{{ with_internal_ref_link }}{% else %}source-{{ src.id }}{% endif %}){% endif %}
{%- endmacro %}

1 change: 1 addition & 0 deletions src/cldfviz/text.py
Original file line number Diff line number Diff line change
@@ -143,6 +143,7 @@ def get_tmpl_context(self, ml):
tmpl_context[k] = False
tmpl_context['ctx'] = self.get_object(ml)
tmpl_context['cldf'] = self.dataset_mapping[ml.prefix]
tmpl_context['ml_label'] = ml.label
return tmpl_context

def render_link(self, ml):
5 changes: 5 additions & 0 deletions tests/test_text.py
Original file line number Diff line number Diff line change
@@ -140,3 +140,8 @@ def test_reference_list(StructureDataset):
assert "Gender/Noun classes" in res
assert 'Peterson 2017' in res
assert "Fitting the pieces together" in res


def test_keep_label(StructureDataset):
text = "[xyz](Source?ref&with_internal_ref_link&keep_label#cldf:Peterson2017)"
assert 'xyz' in render(text, StructureDataset)

0 comments on commit db53f9b

Please sign in to comment.