markopress 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/image/tag.d.ts +2 -1
- package/dist/image/tag.js +1 -1
- package/dist/markdown/loader.js +1 -1
- package/dist/markdown/renderer.js +1 -1
- package/package.json +1 -1
package/dist/image/tag.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface ResolveImageTagOptions {
|
|
|
9
9
|
placeholder?: 'blur' | 'none';
|
|
10
10
|
quality?: number;
|
|
11
11
|
appRoot?: string;
|
|
12
|
+
base?: string;
|
|
12
13
|
}
|
|
13
14
|
export interface ResolvedImageTagData {
|
|
14
15
|
src: string;
|
|
@@ -19,5 +20,5 @@ export interface ResolvedImageTagData {
|
|
|
19
20
|
blurDataURL?: string;
|
|
20
21
|
}
|
|
21
22
|
export declare function resolveImageTag(options: ResolveImageTagOptions): Promise<ResolvedImageTagData>;
|
|
22
|
-
export declare function resolveImageTagsInHtml(html: string, options?: Pick<ResolveImageTagOptions, 'appRoot'>): Promise<string>;
|
|
23
|
+
export declare function resolveImageTagsInHtml(html: string, options?: Pick<ResolveImageTagOptions, 'appRoot' | 'base'>): Promise<string>;
|
|
23
24
|
export {};
|
package/dist/image/tag.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"node:fs/promises";import e from"node:path";import{createHash as i}from"node:crypto";import{resolveAppRoot as r}from"../config/app-root.js";import{generateBlurPlaceholder as n,getImageDimensions as s,getImageFormat as o}from"./index.js";import{transformImage as a}from"./transform.js";const u=new Set(["jpeg","png","webp","avif"]),c=[320,480,640,768,960,1280,1536,1920],l=new Map;export async function resolveImageTag(t){const{src:u,width:g,height:m,layout:w="responsive",sizes:b,srcset:v,placeholder:y="none",quality:j
|
|
1
|
+
import t from"node:fs/promises";import e from"node:path";import{createHash as i}from"node:crypto";import{resolveAppRoot as r}from"../config/app-root.js";import{generateBlurPlaceholder as n,getImageDimensions as s,getImageFormat as o}from"./index.js";import{transformImage as a}from"./transform.js";const u=new Set(["jpeg","png","webp","avif"]),c=[320,480,640,768,960,1280,1536,1920],l=new Map;export async function resolveImageTag(t){const{src:u,width:g,height:m,layout:w="responsive",sizes:b,srcset:v,placeholder:y="none",quality:$,appRoot:j=r(),base:x="/"}=t,P=await async function(t,i,r){if(!t||t.startsWith("data:image/"))return null;try{const e=new URL(t);if("http:"===e.protocol||"https:"===e.protocol)return null}catch{}const n=function(t,e){const i=S(e);return i?t===i?"/":t.startsWith(i+"/")?t.slice(i.length):t:t}(t.split(/[?#]/,1)[0],r),s=e.join(i,"public");if(n.startsWith("/")){const t=n.replace(/^\/+/,""),i=e.join(s,t);if(await h(i))return{sourcePath:i,publicPath:t}}if(e.isAbsolute(n)&&await h(n))return{sourcePath:n,publicPath:e.basename(n)};const o=e.resolve(n);return await h(o)?{sourcePath:o,publicPath:e.basename(o)}:null}(u,j,x);if(!P)return{src:u,width:g,height:m,sizes:b??f(w,g),srcset:v};const W=await s(P.sourcePath),{width:z,height:R}=function(t,e,i,r){return i&&r?{width:i,height:r}:i?{width:i,height:Math.round(e/t*i)}:r?{width:Math.round(t/e*r),height:r}:{width:t,height:e}}(W.width,W.height,g,m),N=o(P.sourcePath),V={src:u,width:z,height:R,sizes:b??f(w,z),srcset:v};if("blur"===y&&d(N)&&(V.blurDataURL=await function(t){let e=l.get(t);return e||(e=n(t),l.set(t,e)),e}(P.sourcePath)),v||!d(N))return V;const k=function(t,e,i){const r=new Set;if("fixed"===t){const t=i??e;r.add(Math.min(t,e)),2*t<=e?r.add(2*t):r.add(e)}else{for(const t of c)t<e&&r.add(t);i&&r.add(Math.min(i,e)),r.add(e)}return[...r].filter(t=>Number.isFinite(t)&&t>0).sort((t,e)=>t-e)}(w,W.width,z);if(0===k.length)return V;const q=e.join(j,"public","_markopress","image",function(t){const r=e.dirname(t),n=i("sha1").update(t).digest("hex").slice(0,8);return e.join("."===r?"":r,n)}(P.publicPath)),D=function(t){return"jpeg"===t?"jpg":t}(N),L=[];for(const t of k)L.push(await a({src:P.sourcePath,width:t,quality:$,format:D,fit:"inside",outDir:q}));return V.src=p(j,L[L.length-1].src,x),V.srcset=L.map(t=>`${p(j,t.src,x)} ${t.width}w`).join(", "),V}export async function resolveImageTagsInHtml(t,e={}){const i=[...t.matchAll(/<image(?=[\s/>])[\s\S]*?(?:\/>|>)/g)];if(0===i.length)return t;let r="",n=0;for(const s of i){const i=s[0],o=s.index??0;r+=t.slice(n,o),r+=await g(i,e),n=o+i.length}return r+=t.slice(n),r}async function h(e){try{return(await t.stat(e)).isFile()}catch{return!1}}function f(t,e){return"fixed"===t&&e?e+"px":"fluid"===t?"100vw":"responsive"===t&&e?`(max-width: ${e}px) 100vw, ${e}px`:void 0}function d(t){return null!==t&&u.has(t)}function p(t,i,r){const n=e.join(t,"public");return function(t,e){const i=S(e);return i?!t.startsWith("/")||t.startsWith("//")||t===i||t.startsWith(i+"/")?t:`${i}${t}`:t}("/"+e.relative(n,i).split(e.sep).join("/"),r)}async function g(t,e){const i=function(t){const e=t.trimEnd().endsWith("/>"),i=t.replace(/^<image\b/,"").replace(e?/\/>\s*$/:/>\s*$/,""),r=[];let n=0;for(;n<i.length;){for(;n<i.length&&/\s/.test(i[n]);)n++;if(n>=i.length||"/"===i[n])break;const t=n;for(;n<i.length&&!/[\s=/]/.test(i[n]);)n++;const e=i.slice(t,n);if(!e)break;for(;n<i.length&&/\s/.test(i[n]);)n++;let s;if("="===i[n]){for(n++;n<i.length&&/\s/.test(i[n]);)n++;const t=m(i,n);s=t.value,n=t.end}r.push({name:e,rawValue:s})}return{attributes:r,selfClosing:e}}(t);if(!function(t){return[["src",j],["width",x],["height",x],["layout",P],["sizes",j],["srcset",j],["placeholder",W],["quality",x]].every(([e,i])=>{const r=w(t,e);return void 0===r||i(r)})}(i.attributes))return t;const r=y(w(i.attributes,"src"));if(!r)return t;const n=await resolveImageTag({src:r,width:$(w(i.attributes,"width")),height:$(w(i.attributes,"height")),layout:b(w(i.attributes,"layout")),sizes:y(w(i.attributes,"sizes")),srcset:y(w(i.attributes,"srcset")),placeholder:v(w(i.attributes,"placeholder")),quality:$(w(i.attributes,"quality")),appRoot:e.appRoot,base:e.base}),s=i.attributes.map(t=>({...t}));R(s,"src",N(n.src)),void 0!==n.width&&R(s,"width",n.width+""),void 0!==n.height&&R(s,"height",n.height+""),n.sizes&&R(s,"sizes",N(n.sizes)),n.srcset&&R(s,"srcset",N(n.srcset)),n.blurDataURL&&R(s,"blurDataURL",N(n.blurDataURL));const o=s.map(t=>function(t){return t.name?void 0===t.rawValue?t.name:`${t.name}=${t.rawValue}`:""}(t)).filter(Boolean).join(" ");return o?`<image ${o}${i.selfClosing?" />":">"}`:"<image"+(i.selfClosing?" />":">")}function m(t,e){const i=t[e];if('"'===i||"'"===i){let r=e+1;for(;r<t.length;)if("\\"!==t[r]){if(t[r]===i){r++;break}r++}else r+=2;return{value:t.slice(e,r),end:r}}if("{"===i){let i=0,r=null,n=e;for(;n<t.length;){const e=t[n];if(r){if("\\"===e){n+=2;continue}e===r&&(r=null),n++}else if('"'!==e&&"'"!==e&&"`"!==e){if("{"===e)i++;else if("}"===e&&(i--,0===i)){n++;break}n++}else r=e,n++}return{value:t.slice(e,n),end:n}}let r=e;for(;r<t.length&&!/\s/.test(t[r]);)r++;return{value:t.slice(e,r),end:r}}function w(t,e){return t.find(t=>t.name===e)?.rawValue}function b(t){const e=y(t);if("fixed"===e||"fluid"===e||"responsive"===e)return e}function v(t){const e=y(t);if("blur"===e||"none"===e)return e}function y(t){if(!t)return;const e=t.trim(),i=z(e);if(void 0!==i)return i;const r=e.match(/^\{\s*([\s\S]+)\s*\}$/);return r?z(r[1].trim()):void 0}function $(t){if(!t)return;const e=t.trim(),i=e.match(/^\{\s*([-+]?\d+(?:\.\d+)?)\s*\}$|^([-+]?\d+(?:\.\d+)?)$/),r=i?.[1]??i?.[2];if(!r){const t=y(e);if(!t||""===t.trim())return;const i=Number(t);return Number.isFinite(i)?i:void 0}const n=Number(r);return Number.isFinite(n)?n:void 0}function j(t){return void 0!==y(t)}function x(t){return void 0!==$(t)}function P(t){return void 0!==b(t)}function W(t){return void 0!==v(t)}function z(t){if(t.startsWith('"')&&t.endsWith('"'))try{return JSON.parse(t)}catch{return t.slice(1,-1)}if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1).replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"')}function R(t,e,i){const r=t.find(t=>t.name===e);r?r.rawValue=i:t.push({name:e,rawValue:i})}function N(t){return JSON.stringify(t)}function S(t){return t&&"/"!==t?t.replace(/\/$/,""):""}
|
package/dist/markdown/loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"gray-matter";import t from"markdown-it";import r from"markdown-it-anchor";import a from"markdown-it-attrs";import*as
|
|
1
|
+
import e from"gray-matter";import t from"markdown-it";import r from"markdown-it-anchor";import a from"markdown-it-attrs";import*as s from"markdown-it-emoji";import{createHighlighter as o}from"shiki";import{setupContainers as n,setupDetails as i}from"./containers.js";import{createEnhancedHighlighter as c}from"./code.js";import{preprocessIncludesWithRegions as l}from"./includes.js";import{preserveTagsPlugin as p}from"./preserve-tags.js";import{globalTagValidator as g}from"./tag-validator.js";import{basePathPlugin as u}from"./base-path-plugin.js";import{mdLinkPlugin as m}from"./md-link-plugin.js";import{resolveImageTagsInHtml as d}from"../image/tag.js";let f=null;const h=new Set,y=["javascript","typescript","js","ts","bash","markdown","md"],b={js:"javascript",ts:"typescript",py:"python",rs:"rust",sh:"bash",shell:"bash",yml:"yaml",cs:"csharp",cpp:"c++"};function w(e){return b[e]||e}async function k(){return f||(f=await o({themes:["github-light","github-dark"],langs:Array.from(y)}),y.forEach(e=>h.add(w(e)))),f}export async function preloadLanguages(e){f||await k();const t=[];for(const r of e){const e=w(r);h.has(e)||t.push((async()=>{try{const{bundledLanguages:t}=await import("shiki/langs");e in t&&(await f.loadLanguage(t[e]),h.add(e))}catch{}})())}await Promise.all(t)}export async function getMarkdownIt(e={},o={}){const l=await k(),d=c(l,{lineNumbers:e.lineNumbers??!0}),f=new t({html:!0,linkify:!0,typographer:!0,highlight:(e,t,r)=>{if(!t)return"";try{return d(e,t,r)}catch(e){return""}}});return f.use(r,{slugify:_,permalink:r.permalink.linkInsideHeader({symbol:"#",placement:"before"})}),f.use(a),f.use(s.full||s.bare),n(f),i(f),e.markoTags?.enabled&&f.use(p,{tagsDir:e.markoTags?.tagsDir||"tags/",onTagDetected:(e,t)=>{g.addDetectedTag(e,o.filePath||"unknown",t)}}),f.use(m),e.base&&f.use(u,e.base),f}export async function parseMarkdown(t,r={},a={},s){const{data:o,content:n,excerpt:i}=e(t,{excerpt:!0,excerpt_separator:"\x3c!-- more --\x3e"}),c=await l(n,{root:a.rootDir??process.cwd(),currentFile:a.filePath??""}),p=s||await async function(e,t){return getMarkdownIt(e,t)}(r,a),g=await d(p.render(c,a),{base:r.base??void 0}),u=a.extractToc?function(e){const t=[],r=e.replace(/```[\s\S]*?```/g,"").replace(/~~~[\s\S]*?~~~/g,"").replace(/^(\t| {4}).+$/gm,""),a=/^(#{1,6})\s+(.+)$/gm;let s;for(;null!==(s=a.exec(r));){const e=s[1].length,r=s[2].trim(),a=v(r),o=_(r);t.push({level:e,title:a,slug:o})}return t}(c):[];return{frontmatter:o,content:c,html:g,excerpt:i,headers:$(u)}}function v(e){return e.replace(/`([^`]+)`/g,"$1").replace(/\*\*\*\+([^*]+)\*\*\+/g,"$1").replace(/___+([^_]+)___+/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/__([^_]+)__/g,"$1").replace(/\*([^*]+)\*/g,"$1").replace(/_([^_]+)_/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]+\]/g,"$1").trim()}function $(e){const t=[],r=[];for(const a of e){const e={level:a.level,title:a.title,slug:a.slug,children:[]};for(;r.length>0&&r[r.length-1].level>=a.level;)r.pop();0===r.length?t.push(e):r[r.length-1].children.push(e),r.push(e)}return t}function _(e){return e.trim().replace(/([a-z])([A-Z])/g,"$1-$2").replace(/([0-9])([a-zA-Z])/g,"$1-$2").replace(/([a-zA-Z])([0-9])/g,"$1-$2").toLowerCase().replace(/\s+/g,"-").replace(/[^\w\u00A0-\uFFFF\-]+/g,"").replace(/^-+|-+$/g,"").replace(/-+/g,"-")}export function validateFrontmatter(e){const t=[];return void 0!==e.title&&"string"!=typeof e.title&&t.push("title must be a string"),void 0!==e.description&&"string"!=typeof e.description&&t.push("description must be a string"),void 0!==e.draft&&"boolean"!=typeof e.draft&&t.push("draft must be a boolean"),void 0!==e.date&&("string"==typeof e.date||e.date instanceof Date||t.push("date must be a string or Date")),void 0===e.tags||Array.isArray(e.tags)||t.push("tags must be an array"),void 0===e.categories||Array.isArray(e.categories)||t.push("categories must be an array"),{valid:0===t.length,errors:t}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"gray-matter";import r from"markdown-it";import{getMarkdownIt as t}from"./loader.js";import{resolveImageTagsInHtml as l}from"../image/tag.js";let n,a=null;export async function renderMarkdown(r,g){if(!a){const e={...g,markoTags:{enabled:!0,...g?.markoTags}};a=await t(e),n=e}const{data:s,content:i,excerpt:u}=e(r,{excerpt:!0,excerpt_separator:"\x3c!-- more --\x3e"});return{frontmatter:s,content:i,html:await l(a.render(i)),excerpt:u,headers:o(function(e){const r=[],t=e.replace(/```[\s\S]*?```/g,"").replace(/~~~[\s\S]*?~~~/g,"").replace(/^(\t| {4}).+$/gm,""),l=/^(#{1,6})\s+(.+)$/gm;let n;for(;null!==(n=l.exec(t));){const e=n[1].length,t=n[2].trim(),l=c(t),a=p(t);r.push({level:e,title:l,slug:a})}return r}(i))}}export function resetRendererCache(){a=null,n=void 0}export function getRendererInstance(){return a}function c(e){return e.replace(/`([^`]+)`/g,"$1").replace(/\*\*\*\+([^*]+)\*\*\+/g,"$1").replace(/___+([^_]+)___+/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/__([^_]+)__/g,"$1").replace(/\*([^*]+)\*/g,"$1").replace(/_([^_]+)_/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]+\]/g,"$1").trim()}function o(e){const r=[],t=[];for(const l of e){const e={level:l.level,title:l.title,slug:l.slug,children:[]};for(;t.length>0&&t[t.length-1].level>=l.level;)t.pop();0===t.length?r.push(e):t[t.length-1].children.push(e),t.push(e)}return r}function p(e){return e.trim().replace(/([a-z])([A-Z])/g,"$1-$2").replace(/([0-9])([a-zA-Z])/g,"$1-$2").replace(/([a-zA-Z])([0-9])/g,"$1-$2").toLowerCase().replace(/\s+/g,"-").replace(/[^\w\u00A0-\uFFFF\-]+/g,"").replace(/^-+|-+$/g,"").replace(/-+/g,"-")}
|
|
1
|
+
import e from"gray-matter";import r from"markdown-it";import{getMarkdownIt as t}from"./loader.js";import{resolveImageTagsInHtml as l}from"../image/tag.js";let n,a=null;export async function renderMarkdown(r,g){if(!a){const e={...g,markoTags:{enabled:!0,...g?.markoTags}};a=await t(e),n=e}const{data:s,content:i,excerpt:u}=e(r,{excerpt:!0,excerpt_separator:"\x3c!-- more --\x3e"});return{frontmatter:s,content:i,html:await l(a.render(i),{base:g?.base??void 0}),excerpt:u,headers:o(function(e){const r=[],t=e.replace(/```[\s\S]*?```/g,"").replace(/~~~[\s\S]*?~~~/g,"").replace(/^(\t| {4}).+$/gm,""),l=/^(#{1,6})\s+(.+)$/gm;let n;for(;null!==(n=l.exec(t));){const e=n[1].length,t=n[2].trim(),l=c(t),a=p(t);r.push({level:e,title:l,slug:a})}return r}(i))}}export function resetRendererCache(){a=null,n=void 0}export function getRendererInstance(){return a}function c(e){return e.replace(/`([^`]+)`/g,"$1").replace(/\*\*\*\+([^*]+)\*\*\+/g,"$1").replace(/___+([^_]+)___+/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1").replace(/__([^_]+)__/g,"$1").replace(/\*([^*]+)\*/g,"$1").replace(/_([^_]+)_/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]+\]/g,"$1").trim()}function o(e){const r=[],t=[];for(const l of e){const e={level:l.level,title:l.title,slug:l.slug,children:[]};for(;t.length>0&&t[t.length-1].level>=l.level;)t.pop();0===t.length?r.push(e):t[t.length-1].children.push(e),t.push(e)}return r}function p(e){return e.trim().replace(/([a-z])([A-Z])/g,"$1-$2").replace(/([0-9])([a-zA-Z])/g,"$1-$2").replace(/([a-zA-Z])([0-9])/g,"$1-$2").toLowerCase().replace(/\s+/g,"-").replace(/[^\w\u00A0-\uFFFF\-]+/g,"").replace(/^-+|-+$/g,"").replace(/-+/g,"-")}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markopress",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "A fast, modern static site generator built on Marko.js v6 - drop-in alternative to VitePress and Docusaurus with full content compatibility",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static-site-generator",
|