36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.textToParagraphs = textToParagraphs;
|
|
/**
|
|
* Shared engine-to-client turn protocol.
|
|
*/
|
|
const tag_parser_1 = require("../utils/tag-parser");
|
|
function textToParagraphs(text, tags = []) {
|
|
return String(text || '')
|
|
.replace(/\r\n?/g, '\n')
|
|
.split(/\n{2,}/)
|
|
.map((paragraph) => paragraph.trim())
|
|
.filter(Boolean)
|
|
.map((paragraph) => {
|
|
const lines = paragraph.split('\n');
|
|
const paragraphTags = [...tags];
|
|
const textLines = [];
|
|
let tagPrefixOpen = true;
|
|
for (const line of lines) {
|
|
const trimmed = line.trim();
|
|
const maybeTag = tagPrefixOpen && trimmed.startsWith('#') ? (0, tag_parser_1.parseTag)(trimmed) : null;
|
|
if (maybeTag) {
|
|
paragraphTags.push(maybeTag);
|
|
}
|
|
else {
|
|
tagPrefixOpen = false;
|
|
textLines.push(line);
|
|
}
|
|
}
|
|
return {
|
|
text: textLines.join('\n').trim(),
|
|
tags: paragraphTags,
|
|
};
|
|
});
|
|
}
|
|
//# sourceMappingURL=turn-result.js.map
|