You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
169 KiB
Plaintext

{"version":3,"file":"plugin.js","sources":["src/lib/elements.ts","src/lib/extractAttributes.ts","src/lib/snipTagContent.ts","src/lib/getText.ts","src/options.ts","src/print/helpers.ts","src/print/doc-helpers.ts","src/print/node-helpers.ts","src/print/index.ts","src/embed.ts","src/index.ts"],"sourcesContent":["export type TagName = keyof HTMLElementTagNameMap | 'svg';\r\n\r\n// @see http://xahlee.info/js/html5_non-closing_tag.html\r\nexport const selfClosingTags = [\r\n 'area',\r\n 'base',\r\n 'br',\r\n 'col',\r\n 'embed',\r\n 'hr',\r\n 'img',\r\n 'input',\r\n 'link',\r\n 'meta',\r\n 'param',\r\n 'source',\r\n 'track',\r\n 'wbr',\r\n];\r\n\r\n// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements#Elements\r\nexport const blockElements: TagName[] = [\r\n 'address',\r\n 'article',\r\n 'aside',\r\n 'blockquote',\r\n 'details',\r\n 'dialog',\r\n 'dd',\r\n 'div',\r\n 'dl',\r\n 'dt',\r\n 'fieldset',\r\n 'figcaption',\r\n 'figure',\r\n 'footer',\r\n 'form',\r\n 'h1',\r\n 'h2',\r\n 'h3',\r\n 'h4',\r\n 'h5',\r\n 'h6',\r\n 'header',\r\n 'hgroup',\r\n 'hr',\r\n 'li',\r\n 'main',\r\n 'nav',\r\n 'ol',\r\n 'p',\r\n 'pre',\r\n 'section',\r\n 'table',\r\n 'ul',\r\n];\r\n\r\n/**\r\n * HTML attributes that we may safely reformat (trim whitespace, add or remove newlines)\r\n */\r\nexport const formattableAttributes: string[] = [\r\n // None at the moment\r\n // Prettier HTML does not format attributes at all\r\n // and to be consistent we leave this array empty for now\r\n];\r\n","import { AttributeNode, TextNode } from '../print/nodes';\r\n\r\nexport function extractAttributes(html: string): AttributeNode[] {\r\n const extractAttributesRegex = /<[a-z]+[\\s\\n]*([\\s\\S]*?)>/im;\r\n const attributeRegex = /([^\\s=]+)(?:=(?:(?:(\"|')([\\s\\S]*?)\\2)|(?:(\\S+?)(?:\\s|>|$))))?/gim;\r\n\r\n const [, attributesString] = html.match(extractAttributesRegex)!;\r\n\r\n const attrs: AttributeNode[] = [];\r\n\r\n let match: RegExpMatchArray | null;\r\n while ((match = attributeRegex.exec(attributesString))) {\r\n const [all, name, quotes, valueQuoted, valueUnquoted] = match;\r\n const value = valueQuoted || valueUnquoted;\r\n const attrStart = match.index!;\r\n\r\n let valueNode: AttributeNode['value'];\r\n if (!value) {\r\n valueNode = true;\r\n } else {\r\n let valueStart = attrStart + name.length;\r\n if (quotes) {\r\n valueStart += 2;\r\n }\r\n\r\n valueNode = [\r\n {\r\n type: 'Text',\r\n data: value,\r\n start: valueStart,\r\n end: valueStart + value.length,\r\n } as TextNode,\r\n ];\r\n }\r\n\r\n attrs.push({\r\n type: 'Attribute',\r\n name,\r\n value: valueNode,\r\n start: attrStart,\r\n end: attrStart + all.length,\r\n });\r\n }\r\n\r\n return attrs;\r\n}\r\n","export const snippedTagContentAttribute = '✂prettier:content✂';\r\n\r\nexport function snipScriptAndStyleTagContent(source: string): string {\r\n let scriptMatchSpans = getMatchIndexes('script');\r\n let styleMatchSpans = getMatchIndexes('style');\r\n\r\n return snipTagContent(\r\n snipTagContent(source, 'script', '{}', styleMatchSpans),\r\n 'style',\r\n '',\r\n scriptMatchSpans,\r\n );\r\n\r\n function getMatchIndexes(tagName: string) {\r\n const regex = getRegexp(tagName);\r\n const indexes: [number, number][] = [];\r\n let match = null;\r\n while ((match = regex.exec(source)) != null) {\r\n if (source.slice(match.index, match.index + 4) !== '<!--') {\r\n indexes.push([match.index, regex.lastIndex]);\r\n }\r\n }\r\n return indexes;\r\n }\r\n\r\n function snipTagCont