Skip to content
Permalink
Browse files

Fix: Trim source snippets auto-generated from element references

Fix #2211
Close #2407
  • Loading branch information...
antross authored and molant committed May 8, 2019
1 parent f7c8314 commit b988b212d8e08b1c4e5b5a005d053966d2b5cfe1
Showing with 3 additions and 2 deletions.
  1. +2 −1 packages/hint/src/lib/hint-context.ts
  2. +1 −1 packages/utils/src/report/get-html-code-snippet.ts
@@ -17,6 +17,7 @@ import {
} from './types';
import { ProblemLocation, Severity } from '@hint/utils/dist/src/types/problems';
import { Category } from '@hint/utils/dist/src/types/category';
import { getHTMLCodeSnippet } from '@hint/utils/dist/src/report/get-html-code-snippet';

export type ReportOptions = {
/** The source code to display (defaults to the `outerHTML` of `element`). */
@@ -124,7 +125,7 @@ export class HintContext<E extends Events = Events> {
if (element) {
// When element is provided, position is an offset in the content.
position = this.findProblemLocation(element, position);
sourceCode = element.outerHTML.replace(/[\t]/g, ' ');
sourceCode = getHTMLCodeSnippet(element);
}

/*
@@ -18,7 +18,7 @@ const getOpening = (html: string) => {
* @param {number} threshold - Max number of charaters in the result.
*/
export const getHTMLCodeSnippet = (element: HTMLElement, threshold = 100) => {
const outerHTML = element.outerHTML;
const outerHTML = element.outerHTML.replace(/[\t]/g, ' ');

if (outerHTML.length <= threshold) {
return outerHTML;

0 comments on commit b988b21

Please sign in to comment.
You can’t perform that action at this time.