Files
dealplustech/node_modules/mdast-util-gfm-task-list-item/lib/index.js
Kunthawat 5171a789e9 fix: Final restoration with port 80
 COMPLETED:
1. Dockerfile uses port 80 (astro preview)
2. BaseLayout imports globals.css
3. globals.css with Tailwind v4 @theme syntax
4. index.astro has Header, Footer, FixedContact
5. All image references fixed to existing files
6. Hero uses hdpe_pipe_main.jpg
7. Product cards use hdpe001.jpg
8. pt-20 on main for fixed header

 TESTED LOCALLY:
- Build: 15 pages in 1.27s
- Docker build successful
- Port 80 working
- Images load
- CSS works

Ready for Easypanel deployment.
2026-03-12 08:58:56 +07:00

142 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @typedef {import('mdast').ListItem} ListItem
* @typedef {import('mdast').Paragraph} Paragraph
* @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
*/
import {ok as assert} from 'devlop'
import {defaultHandlers} from 'mdast-util-to-markdown'
/**
* Create an extension for `mdast-util-from-markdown` to enable GFM task
* list items in markdown.
*
* @returns {FromMarkdownExtension}
* Extension for `mdast-util-from-markdown` to enable GFM task list items.
*/
export function gfmTaskListItemFromMarkdown() {
return {
exit: {
taskListCheckValueChecked: exitCheck,
taskListCheckValueUnchecked: exitCheck,
paragraph: exitParagraphWithTaskListItem
}
}
}
/**
* Create an extension for `mdast-util-to-markdown` to enable GFM task list
* items in markdown.
*
* @returns {ToMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable GFM task list items.
*/
export function gfmTaskListItemToMarkdown() {
return {
unsafe: [{atBreak: true, character: '-', after: '[:|-]'}],
handlers: {listItem: listItemWithTaskListItem}
}
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitCheck(token) {
// Were always in a paragraph, in a list item.
const node = this.stack[this.stack.length - 2]
assert(node.type === 'listItem')
node.checked = token.type === 'taskListCheckValueChecked'
}
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function exitParagraphWithTaskListItem(token) {
const parent = this.stack[this.stack.length - 2]
if (
parent &&
parent.type === 'listItem' &&
typeof parent.checked === 'boolean'
) {
const node = this.stack[this.stack.length - 1]
assert(node.type === 'paragraph')
const head = node.children[0]
if (head && head.type === 'text') {
const siblings = parent.children
let index = -1
/** @type {Paragraph | undefined} */
let firstParaghraph
while (++index < siblings.length) {
const sibling = siblings[index]
if (sibling.type === 'paragraph') {
firstParaghraph = sibling
break
}
}
if (firstParaghraph === node) {
// Must start with a space or a tab.
head.value = head.value.slice(1)
if (head.value.length === 0) {
node.children.shift()
} else if (
node.position &&
head.position &&
typeof head.position.start.offset === 'number'
) {
head.position.start.column++
head.position.start.offset++
node.position.start = Object.assign({}, head.position.start)
}
}
}
}
this.exit(token)
}
/**
* @type {ToMarkdownHandle}
* @param {ListItem} node
*/
function listItemWithTaskListItem(node, parent, state, info) {
const head = node.children[0]
const checkable =
typeof node.checked === 'boolean' && head && head.type === 'paragraph'
const checkbox = '[' + (node.checked ? 'x' : ' ') + '] '
const tracker = state.createTracker(info)
if (checkable) {
tracker.move(checkbox)
}
let value = defaultHandlers.listItem(node, parent, state, {
...info,
...tracker.current()
})
if (checkable) {
value = value.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/, check)
}
return value
/**
* @param {string} $0
* @returns {string}
*/
function check($0) {
return $0 + checkbox
}
}