UNPKG

marked-code-format

Version:

A marked extension for formatting code blocks using Prettier

2 lines (1 loc) 2.49 kB
(function(s,a){typeof exports=="object"&&typeof module<"u"?module.exports=a(require("attributes-parser"),require("prettier")):typeof define=="function"&&define.amd?define(["attributes-parser","prettier"],a):(s=typeof globalThis<"u"?globalThis:s||self,s.markedCodeFormat=a(s.parseAttrs,s.prettier))})(this,function(s,a){"use strict";function m(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const o=m(a),u={javascript:"babel",js:"babel",node:"babel",jsx:"babel",javascriptreact:"babel",react:"babel",typescript:"babel-ts",ts:"babel-ts",tsx:"babel-ts",flow:"babel-flow",css:"css",scss:"scss",less:"less",handlebars:"glimmer",json:"json",jsonc:"json",geojson:"json",jsonl:"json",topojson:"json",json5:"json5","json.stringify":"json-stringify",graphql:"graphql",pandoc:"markdown",markdown:"markdown",md:"markdown",mdx:"mdx",html:"html",xhtml:"html",vue:"vue",angular:"angular",lwc:"lwc",yaml:"yaml",yml:"yaml",ansible:"yaml","home-assistant":"yaml"},b={php:"php",inc:"php",pug:"pug",jade:"pug",ruby:"ruby",jruby:"ruby",macruby:"ruby",rb:"ruby",rbx:"ruby",xml:"xml",rss:"xml",xsd:"xml",wsdl:"xml",apex:"apex-anonymous",astro:"astro",elm:"elm",erb:"erb",rhtml:"erb","html+ruby":"erb",glsl:"glsl-parser",gohtml:"go-template",gotmpl:"go-template",java:"java",jsonata:"JSONata",kotlin:"kotlin",kt:"kotlin",ktm:"kotlin",kts:"kotlin",motoko:"motoko-tt-parse",mo:"motoko-tt-parse",nginx:"nginx",prisma:"prisma-parse",properties:"dot-properties",ini:"dot-properties",dosini:"dot-properties",rust:"jinx-rust",rs:"jinx-rust",sql:"sql",solidity:"solidity-parse",sol:"solidity-parse",svelte:"svelte",toml:"toml"},l=/\s*prettier(?:=(?:"[^"]*"|'[^']*'|[^"'\s]*))?$|prettier(?:=(?:"[^"]*"|'[^']*'|[^"'\s]*))?\s*/g;function d(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function y(t={}){return{async:!0,async walkTokens(e){var p,c;if(e.type!=="code"||!e.lang)return;const{prettier:r}=s(e.lang);if(!r)return;const n={...u,...b},f=Object.keys(n),i=e.lang.split(" ")[0];if(!f.includes(i.toLowerCase()))return;const g=typeof process<"u"?await o.resolveConfig(process.cwd()):{};try{e.raw=(p=e.raw)==null?void 0:p.replace(l,""),e.lang=(c=e.lang)==null?void 0:c.replace(l,""),e.text=await o.format(e.text,{parser:n[String(i)],...g,...t,...d(r)?r:{}})}catch(j){console.error(j)}}}}return y});