diff --git a/docs/Quoted.md b/docs/Quoted.md index 5d23c41..0737624 100644 --- a/docs/Quoted.md +++ b/docs/Quoted.md @@ -16,7 +16,12 @@ Value: `'quoted'` ### `value` Type: `String`
-The value of the string between the quote characters. +The value of the string between the quote characters, *including* quotes. + +### `contents` +Type: `String`
+ +The value of the string between the quote characters, *without* quotes. ## Example Values diff --git a/lib/index.d.ts b/lib/index.d.ts index 97488dd..686ff6d 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -185,6 +185,7 @@ export interface Quoted extends NodeBase { parent: Container; quote: string; value: string; + contents: string; } export interface UnicodeRange extends NodeBase { diff --git a/lib/nodes/Quoted.js b/lib/nodes/Quoted.js index ead39f2..dbee524 100644 --- a/lib/nodes/Quoted.js +++ b/lib/nodes/Quoted.js @@ -8,6 +8,8 @@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of this Source Code Form. */ +const { unquote } = require('quote-unquote'); + const { registerWalker } = require('../walker'); const Node = require('./Node'); @@ -16,6 +18,7 @@ class Quoted extends Node { constructor(options) { super(options); this.type = 'quoted'; + this.contents = unquote(options.value); [this.quote] = options.value; } diff --git a/package-lock.json b/package-lock.json index 015f8d5..abcace1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4419,6 +4419,11 @@ "integrity": "sha1-nsYfeQSYdXB9aUFFlv2Qek1xHnM=", "dev": true }, + "quote-unquote": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/quote-unquote/-/quote-unquote-1.0.0.tgz", + "integrity": "sha1-Z6mncUjv/q+BpNQoQEpxC6qsigs=" + }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", diff --git a/package.json b/package.json index abc1f87..40b25aa 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ ], "dependencies": { "color-name": "^1.1.4", - "is-url-superb": "^4.0.0" + "is-url-superb": "^4.0.0", + "quote-unquote": "^1.0.0" }, "devDependencies": { "ava": "^3.12.1", diff --git a/test/snapshots/func.test.js.md b/test/snapshots/func.test.js.md index bf70fa5..b36f57f 100644 --- a/test/snapshots/func.test.js.md +++ b/test/snapshots/func.test.js.md @@ -3127,6 +3127,7 @@ Generated by [AVA](https://avajs.dev). name: 'url', nodes: [ Quoted { + contents: '/gfx/img/bg.jpg', parent: [Circular], quote: '"', raws: { @@ -3206,6 +3207,7 @@ Generated by [AVA](https://avajs.dev). name: 'url', nodes: [ Quoted { + contents: 'http://domain.com/gfx/img/bg.jpg', parent: [Circular], quote: '"', raws: { @@ -3285,6 +3287,7 @@ Generated by [AVA](https://avajs.dev). name: 'url', nodes: [ Quoted { + contents: '/gfx/img/bg.jpg', parent: [Circular], quote: '\'', raws: { @@ -3364,6 +3367,7 @@ Generated by [AVA](https://avajs.dev). name: 'url', nodes: [ Quoted { + contents: 'http://domain.com/gfx/img/bg.jpg', parent: [Circular], quote: '\'', raws: { @@ -3678,6 +3682,7 @@ Generated by [AVA](https://avajs.dev). name: 'url', nodes: [ Quoted { + contents: '/gfx/img/bg.jpg', parent: [Circular], quote: '"', raws: { @@ -3790,6 +3795,7 @@ Generated by [AVA](https://avajs.dev). name: 'url', nodes: [ Quoted { + contents: 'http://domain.com/gfx/img/bg.jpg', parent: [Circular], quote: '"', raws: { diff --git a/test/snapshots/func.test.js.snap b/test/snapshots/func.test.js.snap index 83cff8f..a7dbe5f 100644 Binary files a/test/snapshots/func.test.js.snap and b/test/snapshots/func.test.js.snap differ diff --git a/test/snapshots/numeric.test.js.snap b/test/snapshots/numeric.test.js.snap index 266d232..a8e4fd5 100644 Binary files a/test/snapshots/numeric.test.js.snap and b/test/snapshots/numeric.test.js.snap differ diff --git a/test/snapshots/punctuation.test.js.snap b/test/snapshots/punctuation.test.js.snap index 32bf0bb..bdb4033 100644 Binary files a/test/snapshots/punctuation.test.js.snap and b/test/snapshots/punctuation.test.js.snap differ diff --git a/test/snapshots/word.test.js.md b/test/snapshots/word.test.js.md index ab13b0c..6e97bdc 100644 --- a/test/snapshots/word.test.js.md +++ b/test/snapshots/word.test.js.md @@ -1108,6 +1108,7 @@ Generated by [AVA](https://avajs.dev). [Symbol(isClean)]: false, }, Quoted { + contents: 'Open Sans', quote: '\'', raws: { after: '', @@ -1225,6 +1226,7 @@ Generated by [AVA](https://avajs.dev). [Symbol(isClean)]: false, }, Quoted { + contents: 'Helvetica Neue', quote: '"', raws: { after: '', diff --git a/test/snapshots/word.test.js.snap b/test/snapshots/word.test.js.snap index 5dfe8bf..9e34b1b 100644 Binary files a/test/snapshots/word.test.js.snap and b/test/snapshots/word.test.js.snap differ