An open API service indexing awesome lists of open source software.

https://github.com/launchpadlab/xmp-escape-loader

Escape HTML in <xmp> tags
https://github.com/launchpadlab/xmp-escape-loader

Last synced: about 1 year ago
JSON representation

Escape HTML in <xmp> tags

Awesome Lists containing this project

README

          

# xmp-escape-loader

A loader that automatically escapes text within `` tags. This allows you to use `` tags within React components and have the inner HTML render correctly:

```jsx

function MyXMPComponent () {
return (


I'm outside the xmp tags!



I'm inside the xmp tags!




)
}

// Will render:
// I'm outside the xmp tags!
//

I'm inside the xmp tags!

```

### Usage

To load your code with this loader, simply add it to your existing JS loaders in your webpack config. It's also possible to use a tag other than `` by passing in a loader option.

```jsx
// webpack.config.js
...
rules: [
{
test: /\.js$/,
use: [
'babel-loader',
'xmp-escape-loader',
],
},
...
],

// with custom delimiter tag
...
rules: [
{
test: /\.js$/,
use: [
'babel-loader',
{
loader: 'xmp-escape-loader',
options: {
tag: '

'

}
},
],
},
...
],

// with custom escape function
...
rules: [
{
test: /\.js$/,
use: [
'babel-loader',
{
loader: 'xmp-escape-loader',
options: {
escape: string => escapeHtml(string).toLowerCase()
}
},
],
},
...
],
```

### How it works

This loader uses [block-loader](https://www.npmjs.com/package/block-loader) and [escape-html](https://www.npmjs.com/package/escape-html) under the hood to parse and format input text. This package is an abstracted implementation of the use case outlined in the block-loader readme, so lots of credit is due to [pomax](https://www.npmjs.com/~pomax)!