Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
isOrCanBeConvertedToShorthand,
isIgnoreDirective,
doesEmbedStartAt,
getUnencodedText
getUnencodedText,
} from './node-helpers';
import {
isLine,
Expand Down Expand Up @@ -185,7 +185,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
if (isEmpty) {
body = '';
} else if (!isSupportedLanguage) {
body = printRaw(node);
body = printRaw(node, options.originalText);
} else if (isInlineElement(node) || isPreTagContent(path)) {
body = printIndentedPreservingWhitespace(path, print);
} else {
Expand Down
24 changes: 16 additions & 8 deletions src/print/node-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import {
AttributeNode,
MustacheTagNode,
AttributeShorthandNode,
HeadNode,
InlineComponentNode,
SlotNode,
TitleNode,
WindowNode,
} from './nodes';
import { inlineElements, TagName } from '../lib/elements';
import { FastPath } from 'prettier';
Expand Down Expand Up @@ -109,14 +114,17 @@ export function isIgnoreDirective(node: Node | undefined | null): boolean {
return !!node && node.type === 'Comment' && node.data.trim() === 'prettier-ignore';
}

export function printRaw(node: Node): string {
const children: Node[] | undefined = (node as ElementNode).children;

if (children) {
return children.map(printRaw).join('');
} else {
return (node as TextNode).raw || '';
export function printRaw(
node: ElementNode | InlineComponentNode | SlotNode | WindowNode | HeadNode | TitleNode,
originalText: string,
): string {
if (node.children.length === 0) {
return '';
}

const firstChild = node.children[0];
const lastChild = node.children[node.children.length - 1];
return originalText.substring(firstChild.start, lastChild.end);
}

function isTextNode(node: Node): node is TextNode {
Expand Down Expand Up @@ -148,7 +156,7 @@ export function getAttributeTextValue(attributeName: string, node: Node): string
}

function getLangAttribute(node: Node): string | null {
const value = getAttributeTextValue('lang', node);
const value = getAttributeTextValue('lang', node) || getAttributeTextValue('type', node);

if (value != null) {
return value.replace(/^text\//, '');
Expand Down
9 changes: 9 additions & 0 deletions test/printer/samples/unsupported-language.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@

div
p Hey
<p>ok</p>
</template>

<template type="text/pug">
h1 My Title

div
p Hey
<p>ok</p>
</template>