fix(XmbSerializer): add meaning attribute, escape attribute values
This commit is contained in:
@ -85,8 +85,9 @@ function _id(el: HtmlElementAst): string {
|
||||
}
|
||||
|
||||
function _serializeMessage(m: Message): string {
|
||||
let desc = isPresent(m.description) ? ` desc='${m.description}'` : '';
|
||||
return `<msg id='${id(m)}'${desc}>${m.content}</msg>`;
|
||||
const desc = isPresent(m.description) ? ` desc='${_escapeXml(m.description)}'` : '';
|
||||
const meaning = isPresent(m.meaning) ? ` meaning='${_escapeXml(m.meaning)}'` : '';
|
||||
return `<msg id='${id(m)}'${desc}${meaning}>${m.content}</msg>`;
|
||||
}
|
||||
|
||||
function _expandPlaceholder(input: string): string {
|
||||
@ -95,3 +96,15 @@ function _expandPlaceholder(input: string): string {
|
||||
return `<ph name=${nameWithQuotes}></ph>`;
|
||||
});
|
||||
}
|
||||
|
||||
const _XML_ESCAPED_CHARS: [RegExp, string][] = [
|
||||
[/&/g, '&'],
|
||||
[/"/g, '"'],
|
||||
[/'/g, '''],
|
||||
[/</g, '<'],
|
||||
[/>/g, '>'],
|
||||
];
|
||||
|
||||
function _escapeXml(value: string): string {
|
||||
return _XML_ESCAPED_CHARS.reduce((value, escape) => value.replace(escape[0], escape[1]), value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user