Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.undercouch.citeproc.csl.CSLDate;
import de.undercouch.citeproc.csl.internal.RenderContext;
import de.undercouch.citeproc.csl.internal.behavior.Affixes;
import de.undercouch.citeproc.csl.internal.behavior.FormattingAttributes;
import de.undercouch.citeproc.csl.internal.locale.LDate;
import de.undercouch.citeproc.csl.internal.token.TextToken;
import de.undercouch.citeproc.csl.internal.token.Token;
Expand Down Expand Up @@ -32,6 +33,7 @@ public class SDate implements SRenderingElement {
private final String datePartsAttr;
private final List<SDatePart> dateParts = new ArrayList<>();
private final Affixes affixes;
private final int formattingAttributes;

/**
* Creates the date element from an XML node
Expand Down Expand Up @@ -72,11 +74,23 @@ public SDate(Node node) {
}

affixes = new Affixes(node);
formattingAttributes = FormattingAttributes.of(node);
}

@Override
public void render(RenderContext ctx) {
affixes.wrap(this::renderInternal).accept(ctx);
affixes.wrap(this::renderWithFormatting).accept(ctx);
}

private void renderWithFormatting(RenderContext ctx) {
if (formattingAttributes == 0) {
renderInternal(ctx);
return;
}

RenderContext tmp = new RenderContext(ctx);
renderInternal(tmp);
ctx.emit(tmp.getResult(), formattingAttributes);
}

private void renderInternal(RenderContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.undercouch.citeproc.csl.internal.RenderContext;
import de.undercouch.citeproc.csl.internal.SElement;
import de.undercouch.citeproc.csl.internal.behavior.Affixes;
import de.undercouch.citeproc.csl.internal.behavior.FormattingAttributes;
import de.undercouch.citeproc.csl.internal.behavior.StripPeriods;
import de.undercouch.citeproc.csl.internal.locale.LTerm;
import de.undercouch.citeproc.helper.NodeHelper;
Expand All @@ -23,6 +24,7 @@ public class SDatePart implements SElement {
private final Affixes affixes;
private final StripPeriods stripPeriods;
private final String rangeDelimiter;
private final int formattingAttributes;

/**
* Creates the date-part element from an XML node
Expand All @@ -40,6 +42,7 @@ public SDatePart(Node node) {
form = NodeHelper.getAttrValue(node, "form");
affixes = new Affixes(node);
stripPeriods = new StripPeriods(node);
formattingAttributes = FormattingAttributes.of(node);

String rd = NodeHelper.getAttrValue(node, "range-delimiter");
rangeDelimiter = Objects.requireNonNullElse(rd, "–");
Expand Down Expand Up @@ -73,7 +76,7 @@ private void renderInternal(RenderContext ctx) {
}

if (value != null) {
ctx.emit(value);
ctx.emit(value, formattingAttributes);
}
}

Expand Down
38 changes: 38 additions & 0 deletions citeproc-java/src/test/java/de/undercouch/citeproc/CSLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,44 @@ public void emptyAsciiDoc() throws Exception {
);
}

/**
* Make sure formatting attributes on date and date-part elements are
* preserved in rendered output.
* @throws Exception if something goes wrong
*/
@Test
public void dateFormattingAttributes() throws Exception {
CSLItemData item = new CSLItemDataBuilder()
.id("DATE-FORMATTING")
.type(CSLType.ARTICLE_JOURNAL)
.issued(2007)
.build();

String dateStyle = "<style xmlns=\"http://purl.org/net/xbiblio/csl\" version=\"1.0\">"
+ "<citation><layout><text value=\"1\"/></layout></citation>"
+ "<bibliography><layout>"
+ "<date variable=\"issued\" font-weight=\"bold\">"
+ "<date-part name=\"year\"/>"
+ "</date>"
+ "</layout></bibliography>"
+ "</style>";

String datePartStyle = "<style xmlns=\"http://purl.org/net/xbiblio/csl\" version=\"1.0\">"
+ "<citation><layout><text value=\"1\"/></layout></citation>"
+ "<bibliography><layout>"
+ "<date variable=\"issued\">"
+ "<date-part name=\"year\" font-weight=\"bold\"/>"
+ "</date>"
+ "</layout></bibliography>"
+ "</style>";

String dateBibliography = CSL.makeAdhocBibliography(dateStyle, "html", item).makeString();
assertTrue(dateBibliography.contains("<span style=\"font-weight: bold\">2007</span>"));

String datePartBibliography = CSL.makeAdhocBibliography(datePartStyle, "html", item).makeString();
assertTrue(datePartBibliography.contains("<span style=\"font-weight: bold\">2007</span>"));
}

/**
* Test if parsing a style with multiple if nodes within a choose node
* throws an exception
Expand Down