Skip to content
Permalink
Browse files

"TwigProcessor.js": Add basic SmartyPants filter.

  • Loading branch information
damiendart committed Feb 29, 2020
1 parent 9f0881d commit 3495c041f0a17eb91fe40a5cf1514412d98cd0c0
Showing with 19 additions and 0 deletions.
  1. +19 −0 buildstatic/processors/TwigProcessor.js
@@ -52,6 +52,25 @@ class TwigProcessor {
),
);

twingEnvironment.addFilter(
new TwingFilter(
'smartypants',
// The following is based on Marked's SmartyPants
// implementation. This implementation is only suitable for
// processing plain text as it will happily destroy HTML markup.
(string) => string
.replace(/---/g, '—')
.replace(/--/g, '–')
.replace(/(^|[-—/([{"\s])'/g, '$1‘')
.replace(/'/g, '’')
.replace(/(^|[-—/([{‘\s])"/g, '$1“')
.replace(/"/g, '”')
.replace(/\.{3}/g, '…'),
[],
{ is_safe: ['html'] },
),
);

return twingEnvironment;
}

0 comments on commit 3495c04

Please sign in to comment.
You can’t perform that action at this time.