1.0.2 • Published 2 years ago

@html-validate/plugin-utils v1.0.2

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
2 years ago

@html-validate/plugin-utils`

Plugin utilities and helpers for writing plugins to HTML-Validate

API

import { Source } from "html-validate";

export interface Position {
  column: number;
  line: number;
}

export function positionFromOffset(text: string, offset: number): [line: number, column: number];

export function positionToOffset(position: Position, data: string): number;

export class TemplateExtractor {
  static fromString(source: string, filename?: string): TemplateExtractor;
  extractObjectProperty(key: string): Source[];
}

Usage

TemplateExtractor

Extracts HTML-snippets from Javascript based files.

/* javascript with HTML in the "template" property */
const sourceCode = `
  export default {
    template: "<p>lorem ipsum</i>",
  }
`;

/* extract HTML snippets */
const templateExtractor = TemplateExtractor.fromString(sourceCode);
const snippets = templateExtractor.extractObjectProperty("template");

Typically used in a transformation plugin to but it could also be validated directly:

for (const snippet of snippets) {
  const result = htmlvalidate.validateSource(snippet);
  console.log(result);
}
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago