Skip to content

Commit

Permalink
Improve quotes for mustache code in text
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Jul 7, 2019
1 parent 16ef602 commit 0817c64
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,18 @@ export const plugin: Plugin = {
code = code.trim();
const type: QuotationType | undefined = quotationType(code);
if ((type === 'SINGLE' && singleQuote) || (type === 'DOUBLE' && !singleQuote)) {
val = '{{ ';
val += code.replace(/['"]/g, (match) => (match === '"' ? "'" : '"'));
val += ' }}';
code = code.replace(/['"]/g, (match: string, index: number, raw: string) => {
if (index !== 0 || index !== raw.length - 1) {
const prevChar = raw[index - 1];
const nextChar = raw[index + 1];
if (/[\S]/.test(prevChar) && /[\S ]/.test(nextChar)) {
return match;
}
}
return match === '"' ? "'" : '"';
});
}
val = `{{ ${code} }}`;
}
if (previousToken && (previousToken.type === 'tag' || previousToken.type === 'id')) {
val = ` ${val}`;
Expand Down

0 comments on commit 0817c64

Please sign in to comment.