/
githubmirror
/
english-compiler
Обзор
Документация
Войти
/
githubmirror
/
english-compiler
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/codegen/promptParts/blockWrapper.js
35 строк
1017 B
Eugene Cheah
prompt parts library collection
17 фев 2023, 11:32
17 фев 2023, 11:32
a26dae3
Код
Авторство
О чём код?
/** * Wrap the data within a block delimiter, * adapted according to the input data, to avoid accidental "block escape" * * @param {String} type * @param {String} data */ function blockWrapper(type, data) { // Trim the data provided data = data.trim(); // Handle markdown escape if( data.indexOf("```") >= 0 ) { // Block wrapper line, intentionally split apart, so that this code can eventually be.... // parsed by the code-ai-project let codeLineBreak = "<<" + "{{" + "~~" + "}}" + ">>"; // Wrap it using special character code lines return [ `${type} (between the \`${codeLineBreak}\` lines) :`, codeLineBreak, data.replace(/\<\<\{\{/g, "\\<\\<\\{\\{").replace(/\>\>\}\}/g, "\\>\\>\\}\\}"), codeLineBreak ].join("\n") } // Wrap it using markdown code block return [ `${type} :`, "```", data, "```" ].join("\n") } module.exports = blockWrapper;