-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to move implementations to
lib/
- Loading branch information
Showing
136 changed files
with
3,227 additions
and
3,134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @typedef {import('hast').Nodes} Nodes | ||
*/ | ||
|
||
// To do: next major: remove return result. | ||
/** | ||
* Set the plain-text value of a hast node. | ||
* This is like the DOMs `Node#textContent` setter. | ||
* The given node is returned. | ||
* | ||
* @template {Nodes} Thing | ||
* Node kind. | ||
* @param {Thing} node | ||
* Node to change. | ||
* @param {string | null | undefined} [value=''] | ||
* Value to use (default: `''`) | ||
* @returns {Thing} | ||
* Given node. | ||
*/ | ||
export function fromString(node, value) { | ||
const normalized = value === undefined || value === null ? '' : String(value) | ||
|
||
if ('children' in node) { | ||
node.children = [] | ||
|
||
if (value) { | ||
node.children.push({type: 'text', value: normalized}) | ||
} | ||
} else if (node.type !== 'doctype') { | ||
node.value = normalized | ||
} | ||
|
||
return node | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @typedef {import('hast').Nodes} Nodes | ||
*/ | ||
|
||
const list = new Set(['pingback', 'prefetch', 'stylesheet']) | ||
|
||
/** | ||
* Checks whether a node is a “body OK” link. | ||
* | ||
* @param {Nodes} node | ||
* Node to check. | ||
* @returns {boolean} | ||
* Whether `node` is a “body OK” link. | ||
*/ | ||
export function isBodyOkLink(node) { | ||
if (node.type !== 'element' || node.tagName !== 'link') { | ||
return false | ||
} | ||
|
||
if (node.properties.itemProp) { | ||
return true | ||
} | ||
|
||
const rel = node.properties.rel | ||
let index = -1 | ||
|
||
if (!Array.isArray(rel) || rel.length === 0) { | ||
return false | ||
} | ||
|
||
while (++index < rel.length) { | ||
if (!list.has(String(rel[index]))) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const re = /^\[if[ \t\f\n\r]+[^\]]+]|<!\[endif]$/ | ||
|
||
/** | ||
* @typedef {import('hast').Nodes} Nodes | ||
*/ | ||
|
||
/** | ||
* Check if a node is a conditional comment. | ||
* | ||
* @param {Nodes} node | ||
* Node to check. | ||
* @returns {boolean} | ||
* Whether `node` is a conditional comment. | ||
*/ | ||
export function isConditionalComment(node) { | ||
return node.type === 'comment' && re.test(node.value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @typedef {import('hast').Nodes} Nodes | ||
*/ | ||
|
||
import {collapseWhiteSpace} from 'collapse-white-space' | ||
|
||
/** | ||
* Check whether a hast node is a `<link>` that references CSS. | ||
* | ||
* @param {Nodes} node | ||
* Node to check. | ||
* @returns {boolean} | ||
* Whether `node` is a CSS link. | ||
*/ | ||
export function isCssLink(node) { | ||
if (node.type !== 'element' || node.tagName !== 'link') { | ||
return false | ||
} | ||
|
||
const rel = node.properties.rel | ||
|
||
if (!rel || !Array.isArray(rel) || !rel.includes('stylesheet')) { | ||
return false | ||
} | ||
|
||
const value = collapseWhiteSpace(String(node.properties.type || ''), { | ||
style: 'html', | ||
trim: true | ||
}).toLowerCase() | ||
|
||
return value === '' || value === 'text/css' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @typedef {import('hast').Nodes} Nodes | ||
*/ | ||
|
||
import {collapseWhiteSpace} from 'collapse-white-space' | ||
|
||
/** | ||
* Check whether a hast node is a `<style>` that contains CSS. | ||
* | ||
* @param {Nodes} node | ||
* Node to check. | ||
* @returns {boolean} | ||
* Whether `node` is a CSS style element. | ||
*/ | ||
export function isCssStyle(node) { | ||
if (node.type !== 'element' || node.tagName !== 'style') { | ||
return false | ||
} | ||
|
||
const value = collapseWhiteSpace(String(node.properties.type || ''), { | ||
style: 'html', | ||
trim: true | ||
}).toLowerCase() | ||
|
||
return value === '' || value === 'text/css' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.