diff --git a/src/language-html/printer-html.js b/src/language-html/printer-html.js index 319dc5260626..34c70c63e8db 100644 --- a/src/language-html/printer-html.js +++ b/src/language-html/printer-html.js @@ -101,6 +101,18 @@ function embed(path, print, textToDoc, options) { break; } + // lit-html: html`` + if ( + /^PRETTIER_PLACEHOLDER_\d+$/.test( + options.originalText.slice( + node.valueSpan.start.offset, + node.valueSpan.end.offset + ) + ) + ) { + return concat([node.rawName, "=", node.value]); + } + const embeddedAttributeValueDoc = printEmbeddedAttributeValue( node, (code, opts) => diff --git a/src/language-js/embed.js b/src/language-js/embed.js index fa8c337d11e4..975cdb1cf182 100644 --- a/src/language-js/embed.js +++ b/src/language-js/embed.js @@ -567,10 +567,9 @@ function isHtml(path) { function printHtmlTemplateLiteral(path, print, textToDoc, parser) { const node = path.getValue(); - const placeholderPattern = - "prettierhtmlplaceholder(\\d+)redlohecalplmthreitterp"; + const placeholderPattern = "PRETTIER_PLACEHOLDER_(\\d+)"; const placeholders = node.expressions.map( - (_, i) => `prettierhtmlplaceholder${i}redlohecalplmthreitterp` + (_, i) => `PRETTIER_PLACEHOLDER_${i}` ); const text = node.quasis diff --git a/tests/multiparser_js_html/__snapshots__/jsfmt.spec.js.snap b/tests/multiparser_js_html/__snapshots__/jsfmt.spec.js.snap index 1bf9d50f0800..6895cf1abc6a 100644 --- a/tests/multiparser_js_html/__snapshots__/jsfmt.spec.js.snap +++ b/tests/multiparser_js_html/__snapshots__/jsfmt.spec.js.snap @@ -47,6 +47,8 @@ const someHtml1 = html\`
hello \${world}
\`; const someHtml2 = /* HTML */ \`
hello \${world}
\`; html\`\` + +html\`\`; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import { LitElement, html } from "@polymer/lit-element"; @@ -86,4 +88,8 @@ const someHtml2 = /* HTML */ \` html\`\`; +html\` + +\`; + `; diff --git a/tests/multiparser_js_html/lit-html.js b/tests/multiparser_js_html/lit-html.js index 2b0ab038be3c..764557704da1 100644 --- a/tests/multiparser_js_html/lit-html.js +++ b/tests/multiparser_js_html/lit-html.js @@ -44,3 +44,5 @@ const someHtml1 = html`
hello ${world}
`; const someHtml2 = /* HTML */ `
hello ${world}
`; html`` + +html``;