diff --git a/CHANGELOG.md b/CHANGELOG.md index e55386e..7e3682e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/docs/text.md b/docs/text.md index 826bf02..c85fb03 100644 --- a/docs/text.md +++ b/docs/text.md @@ -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) ``` diff --git a/src/cldfviz/templates/text/Source_detail.md b/src/cldfviz/templates/text/Source_detail.md index 2b5ad99..0debe56 100644 --- a/src/cldfviz/templates/text/Source_detail.md +++ b/src/cldfviz/templates/text/Source_detail.md @@ -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 %} \ No newline at end of file diff --git a/src/cldfviz/templates/text/util.md b/src/cldfviz/templates/text/util.md index 5f77471..e1d0e42 100644 --- a/src/cldfviz/templates/text/util.md +++ b/src/cldfviz/templates/text/util.md @@ -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 %} diff --git a/src/cldfviz/text.py b/src/cldfviz/text.py index 6c17123..537daab 100644 --- a/src/cldfviz/text.py +++ b/src/cldfviz/text.py @@ -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): diff --git a/tests/test_text.py b/tests/test_text.py index 808bbc0..1295c7b 100644 --- a/tests/test_text.py +++ b/tests/test_text.py @@ -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)