Skip to content
Open
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
33 changes: 30 additions & 3 deletions packages/markdown-html/src/ToHtmlStringVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@
*/

'use strict';
/**
* Converts a markdown node to an HTML string.
*
* @param {Object} thing - Markdown AST node
* @returns {string} HTML representation
*/
function renderVariableValue(thing) {
// Handle relationship types (e.g. Party)
if (
thing.elementType &&
thing.elementType.startsWith('org.accordproject.party@') &&
typeof thing.value === 'string'
) {
// Remove quotes if present
const unquoted = thing.value.replace(/^"(.*)"$/, '$1');

// Extract identifier after #
const parts = unquoted.split('#');
return parts.length > 1 ? parts[1] : unquoted;
}

// Default behavior
return thing.value;
}

// const CiceroMarkTransformer = require('@accordproject/markdown-cicero').CiceroMarkTransformer;

Expand Down Expand Up @@ -81,7 +105,8 @@ class ToHtmlStringVisitor {
if (thing.identifiedBy) {
attributes += ` identifiedBy="${thing.identifiedBy}"`;
}
parameters.result += `<span ${attributes}>${thing.value}</span>`;
parameters.result += `<span ${attributes}>${renderVariableValue(thing)}</span>`;

}
break;
case 'FormattedVariable': {
Expand All @@ -92,7 +117,8 @@ class ToHtmlStringVisitor {
if (thing.identifiedBy) {
attributes += ` identifiedBy="${thing.identifiedBy}"`;
}
parameters.result += `<span ${attributes}>${thing.value}</span>`;
parameters.result += `<span ${attributes}>${renderVariableValue(thing)}</span>`;

}
break;
case 'EnumVariable': {
Expand All @@ -104,7 +130,8 @@ class ToHtmlStringVisitor {
if (thing.identifiedBy) {
attributes += ` identifiedBy="${thing.identifiedBy}"`;
}
parameters.result += `<span ${attributes}>${thing.value}</span>`;
parameters.result += `<span ${attributes}>${renderVariableValue(thing)}</span>`;

}
break;
case 'Conditional':
Expand Down