mirror of https://github.com/sveltejs/svelte
Merge pull request #750 from sveltejs/saner-sigils
saner escaping/unescaping of `@` and `#` sigilspull/752/head
commit
4874dc1d89
@ -1,7 +1,9 @@
|
|||||||
export function stringify(data: string) {
|
export function stringify(data: string, options = {}) {
|
||||||
return JSON.stringify(escape(data));
|
return JSON.stringify(escape(data, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function escape(data: string) {
|
export function escape(data: string, { onlyEscapeAtSymbol = false } = {}) {
|
||||||
return data.replace(/([^\\@#])?([@#])/g, '$1\\$2');
|
return data.replace(onlyEscapeAtSymbol ? /(@+)/g : /(@+|#+)/g, (match: string) => {
|
||||||
|
return match + match[0];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
<a href='mailto:{{address}}'>email</a>
|
@ -0,0 +1,3 @@
|
|||||||
|
export default {
|
||||||
|
html: `<a href='mailto:hello@example.com'>email</a>`
|
||||||
|
};
|
@ -0,0 +1,9 @@
|
|||||||
|
<Email address='hello@example.com'/>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Email from './Email.html';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: { Email },
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
Reference in new issue