jeremenichelli / eleventy-xml-plugin

👩‍🔬 Useful set of Liquid filters for XML files composition in Eleventy projects
MIT License
6 stars 3 forks source link

Doesn't seem to be working? #6

Open cfjedimaster opened 4 years ago

cfjedimaster commented 4 years ago

Sorry for the vague title, but that's the best I can say. I installed the plugin and then tried to use it, but it doesn't seem to do anything. So for example:

<title>{{ post.data.title | xml_escape }} {{ "ray <a>link</a>" | 'xml_escape' }}</title>

When output, the tags in the hard coded string are not escaped as I'd expect.

kaleb commented 4 years ago

It seems to be correctly decoding entities but not the < and >.

kaleb commented 4 years ago

According to https://www.rubydoc.info/gems/jekyll/Jekyll%2FFilters%3Axml_escape the output is this:

xml_escape('foo "bar" <baz>')
# => "foo &quot;bar&quot; &lt;baz&gt;"
sentience commented 2 years ago

For anyone else being bitten by this, I've created a temporary branch that you can install from GitHub, with this in your package.json:

  "devDependencies": {
    "@11ty/eleventy": "^1.0.0",
    "eleventy-xml-plugin": "github:sentience/eleventy-xml-plugin#dist"
  }
jcubic commented 1 year ago

The library is all wrong, it use decode from html-entities instead of encode. So it unescape. Just ignore the library that is useless and use html-entities directly:

const { encode } = require('html-entities');
module.exports = function(eleventyConfig) {
    // ... other config
    eleventyConfig.addFilter("xml_escape", function(str) {
        return encode(str, {level: 'xml'});
    });
};

The library is only 4 lines of code that use obsolete version of html-entities anyway.