Skip to content

Commit

Permalink
fix: return non-html quicker
Browse files Browse the repository at this point in the history
  • Loading branch information
j4w8n committed Oct 7, 2024
1 parent be15c7f commit 305327e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/closify.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hasHtml } from "./utils.js"
import { isHtml } from "./utils.js"

const void_elements = [
'area', 'base', 'br', 'col', 'embed', 'hr',
Expand All @@ -16,7 +16,7 @@ const void_elements = [
*/
export const closify = (html, html_check = true) => {
if (html_check)
if (!hasHtml(html)) return html
if (!isHtml(html)) return html

return html.replace(/<([a-zA-Z\-0-9]+)[^>]*>/g, (match, name) => {
if (void_elements.indexOf(name) > -1) {
Expand Down
8 changes: 4 additions & 4 deletions src/prettify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { closify } from './closify.js'
import { minify } from './minify.js'
import { hasHtml, validateConfig } from './utils.js'
import { isHtml, validateConfig } from './utils.js'
import { CONFIG } from './constants.js'

/**
Expand Down Expand Up @@ -141,12 +141,12 @@ const process = (html, step) => {
* @returns {string} A well-formed HTML string.
*/
export const prettify = (html, config) => {
/* Return content as-is if it does not contain any HTML elements. */
if (!isHtml(html)) return html

const validated_config = config ? validateConfig(config) : CONFIG
strict = validated_config.strict

/* Return content as-is if it does not contain any HTML elements. */
if (!hasHtml(html)) return html

html = preprocess(html)
html = process(html, validated_config.tab_size)

Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CONFIG } from './constants.js'
* @param {string} content Content to evaluate.
* @returns {boolean} A boolean.
*/
export const hasHtml = (content) => {
export const isHtml = (content) => {
const regex = /<(?<Element>[A-Za-z]+\b)[^>]*(?:.|\n)*?<\/{1}\k<Element>>/
return regex.test(content)
}
Expand Down

0 comments on commit 305327e

Please sign in to comment.