Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
class-liu-fullstack committed Dec 23, 2024
2 parents 0b81549 + 3bef01c commit 80cf006
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export class Message<AD extends Adapter> {
export function parseFromTemplate(template: string | MessageElem): MessageElem[] {
if (typeof template !== 'string') return [template];
const result: MessageElem[] = [];
const closingReg = /<(\S+)(\s[^\/]+)?\/>/;
const twinningReg = /<(\S+)(\s[^>]+)?>([^<]*)<\/\1>/;
const closingReg = /^<(\S+)(\s[^>]+)?\/>/;
const twinningReg = /^<(\S+)(\s[^>]+)?>([\s\S]*?)<\/\1>/;
while (template.length) {
const [_, type, attrStr = '', child = ''] = template.match(closingReg) || template.match(twinningReg) || [];
const [_, type, attrStr = '', child = ''] = template.match(twinningReg) || template.match(closingReg) || [];
if (!type) break;
const isClosing = closingReg.test(template);
const matched = isClosing ? `<${type}${attrStr}/>` : `<${type}${attrStr}>${child}</${type}>`;
Expand All @@ -70,6 +70,10 @@ export function parseFromTemplate(template: string | MessageElem): MessageElem[]
}
}),
);
if (child) {
// TODO temporarily use 'message' as the key of the child MessageElem
data.message = parseFromTemplate(child).map(({ type, data }) => ({ type, ...data }))
}
result.push({
type: type,
data,
Expand Down

0 comments on commit 80cf006

Please # to comment.