Skip to content

Commit

Permalink
feat(developer,common): use unified xml writer
Browse files Browse the repository at this point in the history
Fixes: #12208
  • Loading branch information
srl295 committed Sep 27, 2024
1 parent d540e4c commit 1780b1e
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions developer/src/common/web/utils/src/types/kvks/kvks-file-writer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VisualKeyboard as VK, Constants } from '@keymanapp/common-types';
import KVKSourceFile, { KVKSEncoding, KVKSFlags, KVKSKey, KVKSLayer } from './kvks-file.js';
import { xml2js } from '../../index.js';
import { KeymanXMLWriter } from '../../index.js';

import USVirtualKeyCodes = Constants.USVirtualKeyCodes;
import VisualKeyboard = VK.VisualKeyboard;
Expand All @@ -11,18 +11,6 @@ import VisualKeyboardShiftState = VK.VisualKeyboardShiftState;

export default class KVKSFileWriter {
public write(vk: VisualKeyboard): string {

const builder = new xml2js.Builder({
allowSurrogateChars: true,
attrkey: '$',
charkey: '_',
xmldec: {
version: '1.0',
encoding: 'UTF-8',
standalone: true
}
})

const flags: KVKSFlags = {};
if(vk.header.flags & VisualKeyboardHeaderFlags.kvkhDisplayUnderlying) {
flags.displayunderlying = '';
Expand All @@ -37,8 +25,6 @@ export default class KVKSFileWriter {
flags.useunderlying = '';
}



const kvks: KVKSourceFile = {
visualkeyboard: {
header: {
Expand Down Expand Up @@ -105,7 +91,7 @@ export default class KVKSFileWriter {
l.key.push(k);
}

const result = builder.buildObject(kvks);
const result = new KeymanXMLWriter({type: 'kvks'}).write(kvks);
return result; //Uint8Array.from(result);
}

Expand All @@ -124,4 +110,4 @@ export default class KVKSFileWriter {
}
return '';
}
}
}

0 comments on commit 1780b1e

Please sign in to comment.