Skip to content

Commit

Permalink
Merge pull request #54 from AtilioA/refactor/improve-handle-generatio…
Browse files Browse the repository at this point in the history
…n-1-loca-file-encode-newlines

Refactor handle content generation and loca file selection
  • Loading branch information
ghostboats authored May 21, 2024
2 parents 71f963b + a85d723 commit f42c7e1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions commands/insertHandleUUID.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function updateLocaXmlFiles(changes) {

let selectedLocaFiles = locaFiles;
// If user doesn't want to add handles to all loca files, prompt for selection from the list of all loca files
if (!addHandlesToAllLocas) {
if (!addHandlesToAllLocas && locaFiles.length > 1) {
const fileItems = locaFiles.map(file => ({
label: path.basename(file.fsPath),
description: path.relative(workspaceFolder.uri.fsPath, file.fsPath),
Expand Down Expand Up @@ -134,7 +134,12 @@ async function updateLocaXmlFile(locaFileUri, changes, edit) {
}

function generateContent(handle, handleContent) {
return ` <content contentuid="${handle}" version="1">${handleContent.trim()}</content>\n`;
function convertNewlinesToBr(text) {
return text.replace(/(\\r\\n|\\n|\\r)/g, '&lt;br&gt;');
}

const preparedContent = convertNewlinesToBr(handleContent).trim();
return ` <content contentuid="${handle}" version="1">${preparedContent}</content>\n`;
}

function generateHandle() {
Expand Down

0 comments on commit f42c7e1

Please sign in to comment.