diff --git a/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/TextBlock.java b/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/TextBlock.java index 2ffb5a31b..838b42a0d 100644 --- a/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/TextBlock.java +++ b/vspace/src/main/java/edu/asu/diging/vspace/core/model/impl/TextBlock.java @@ -9,6 +9,7 @@ import org.commonmark.renderer.html.HtmlRenderer; import edu.asu.diging.vspace.core.model.ITextBlock; +import edu.asu.diging.vspace.core.util.CitationFormatter; @Entity public class TextBlock extends ContentBlock implements ITextBlock { @@ -46,9 +47,58 @@ public void setText(String text) { @Override @Transient public String htmlRenderedText() { + String processedText = text; + + // First, format citations in the text + if (processedText != null) { + processedText = CitationFormatter.formatCitations(processedText); + } + + // Then process with Markdown Parser parser = Parser.builder().build(); - Node document = parser.parse(text); + Node document = parser.parse(processedText); HtmlRenderer renderer = HtmlRenderer.builder().build(); - return renderer.render(document); + String htmlOutput = renderer.render(document); + + // Add citation-specific CSS classes for styling + htmlOutput = addCitationStyling(htmlOutput); + + return htmlOutput; + } + + /** + * Adds CSS classes to citation elements for proper styling + */ + @Transient + private String addCitationStyling(String html) { + if (html == null) { + return null; + } + + // Add citation class to parenthetical citations + html = html.replaceAll("\\(([^)]+,\\s*\\d{4}[^)]*)\\)", + "($1)"); + + // Add reference class to formatted references (those with italicized titles) + html = html.replaceAll("([^<]+[^<]*\\.)", + "