[{"data":1,"prerenderedAt":1080,"buildId":1081},["ShallowReactive",2],{"docs:\u002Fguide\u002Fpages":3},{"page":4,"section":17,"document":18,"credits":11,"prev":1075,"next":1077},{"id":5,"path":6,"file":7,"title":8,"sourceTitle":9,"description":10,"tagline":10,"eyebrow":11,"credits":11,"keywords":12,"icon":13,"layout":14,"sidebar":15,"toc":15,"kind":11,"group":11,"navigation":15,"order":16},"pages","\u002Fguide\u002Fpages","guide\u002Fpages.md","Pages","Pages and Markdown twins","handle wraps a whole app. HTML pages become Markdown for agents, and real .md files, assets and JSON routes pass through as they are.",null,[],"i-lucide-file-text","article",true,3,"guide",{"nodes":19,"toc":1065},[20,42,50,177,195,204,210,236,246,260,287,293,307,314,325,331,344,360,374,393,400,637,640,713,719,850,856,866,878,885,891,994,1000,1009,1018,1030,1036,1041,1047],[21,22,23,27,28,31,32,37,38,41],"p",{},[24,25,26],"code",{},"handle(request, next)"," goes in front of a whole app, where ",[24,29,30],{},"next"," is the app. People get the page as before. A request that picks Markdown gets the same page converted. See ",[33,34,36],"a",{"href":35},"\u002Fguide\u002Finstallation","Installation"," for how to wire ",[24,39,40],{},"handle"," into your app.",[43,44,49],"h2",{"id":45,"anchor":46},"what-happens-to-each-request",{"label":47,"icon":48},"Section titled \"What happens to each request\"","#","What happens to each request",[51,52,53,72],"table",{},[54,55,56],"thead",{},[57,58,59,63,69],"tr",{},[60,61,62],"th",{},"Request",[60,64,65,66,68],{},"What ",[24,67,40],{}," does",[60,70,71],{},"Answer",[73,74,75,90,109,124,142,156,166],"tbody",{},[57,76,77,81,87],{},[78,79,80],"td",{},"Any method but GET or HEAD",[78,82,83,84,86],{},"Calls ",[24,85,30],{}," with the request and returns its response untouched",[78,88,89],{},"The app's",[57,91,92,98,103],{},[78,93,94,95],{},"Picks HTML, such as a browser or plain ",[24,96,97],{},"curl",[78,99,83,100,102],{},[24,101,30],{}," with the request",[78,104,105,106],{},"The app's page, plus ",[24,107,108],{},"Vary: Accept",[57,110,111,116,121],{},[78,112,113],{},[24,114,115],{},"Accept: text\u002Fmarkdown",[78,117,83,118,120],{},[24,119,30],{}," with the same request, then converts the HTML",[78,122,123],{},"Markdown, same status",[57,125,126,135,140],{},[78,127,128,131,132],{},[24,129,130],{},"\u002Fdocs\u002Fguide.md"," or ",[24,133,134],{},"?format=md",[78,136,83,137,139],{},[24,138,30],{}," with the canonical URL, then converts the HTML",[78,141,123],{},[57,143,144,147,150],{},[78,145,146],{},"The app answers 2xx already in the picked form",[78,148,149],{},"Passes it",[78,151,152,153],{},"The app's, plus ",[24,154,155],{},"Vary",[57,157,158,161,163],{},[78,159,160],{},"The app answers something that is not HTML, such as an image or JSON",[78,162,149],{},[78,164,165],{},"The app's, untouched",[57,167,168,171,174],{},[78,169,170],{},"The app's page is a 404 or a 500 and the request picked Markdown",[78,172,173],{},"Converts it",[78,175,176],{},"The error page as Markdown, with its 404 or 500",[21,178,179,181,182,185,186,189,190,194],{},[24,180,40],{}," offers ",[24,183,184],{},"html"," first, then ",[24,187,188],{},"markdown"," when a converter is set. A layer with a renderer adds its form to the offers. See ",[33,191,193],{"href":192},"\u002Fguide\u002Flayers#render-a-form-from-your-own-source","Render a form from your own source",".",[21,196,197,199,200,203],{},[24,198,40],{}," never answers 406. ",[24,201,202],{},"Accept: application\u002Fjson"," on a page gets the HTML.",[43,205,209],{"id":206,"anchor":207},"twins-and-format",{"label":208,"icon":48},"Section titled \"Twins and ?format=\"","Twins and ?format=",[21,211,212,213,216,217,219,220,216,223,219,226,229,230,219,233,194],{},"A twin is the URL of a page plus a form's ",[24,214,215],{},"ext",". ",[24,218,130],{}," is the twin of ",[24,221,222],{},"\u002Fdocs\u002Fguide",[24,224,225],{},"\u002Findex.md",[24,227,228],{},"\u002F",", and ",[24,231,232],{},"\u002Fdocs\u002Findex.md",[24,234,235],{},"\u002Fdocs\u002F",[21,237,238,239,242,243,194],{},"The rest of the query string stays. ",[24,240,241],{},"\u002Fdocs\u002Fguide.md?x=1"," asks the app for ",[24,244,245],{},"\u002Fdocs\u002Fguide?x=1",[21,247,248,249,252,253,259],{},"Your app never sees the twin URL. It gets the canonical URL with ",[24,250,251],{},"Accept: text\u002Fmarkdown, text\u002Fhtml;q=0.9",". The picked type comes first so that a route calling ",[33,254,256],{"href":255},"\u002Fguide\u002Fapi-routes",[24,257,258],{},"respond"," answers in it. HTML comes second so that a page route still answers.",[21,261,262,265,266,268,269,272,273,275,276,278,279,282,283,286],{},[24,263,264],{},"?format="," takes a form's name or its ",[24,267,215],{}," without the dot. On a page, that is ",[24,270,271],{},"md",", ",[24,274,188],{},", or ",[24,277,184],{},". The match is exact, so ",[24,280,281],{},"?format=MD"," is not a format. A value that names no offered form is left in the URL for your app, so ",[24,284,285],{},"?format=json"," reaches a page route unchanged.",[43,288,292],{"id":289,"anchor":290},"real-md-files-and-assets",{"label":291,"icon":48},"Section titled \"Real .md files and assets\"","Real .md files and assets",[21,294,295,296,299,300,303,304,306],{},"A request for ",[24,297,298],{},"\u002FREADME.md"," first asks the app for ",[24,301,302],{},"\u002FREADME",". When that is not a 2xx HTML page, ",[24,305,40],{}," sends the original request to the app, so the file is served as it is.",[21,308,309,310,313],{},"As a result, the app runs twice for a real ",[24,311,312],{},".md"," file and once for everything else.",[21,315,316,317,320,321,324],{},"A response that is not HTML passes untouched, whatever the request picked. An image asked for with ",[24,318,319],{},"Accept: text\u002Fmarkdown, text\u002Fhtml, *\u002F*"," comes back as the same ",[24,322,323],{},"Response"," object.",[43,326,330],{"id":327,"anchor":328},"what-the-converter-keeps",{"label":329,"icon":48},"Section titled \"What the converter keeps\"","What the converter keeps",[21,332,333,334,272,337,229,340,343],{},"The converted response keeps the app's status and headers, except ",[24,335,336],{},"content-length",[24,338,339],{},"content-encoding",[24,341,342],{},"etag",", which described the HTML bytes.",[21,345,346,349,350,353,354,356,357,194],{},[24,347,348],{},"Content-Type"," becomes the picked type, ",[24,351,352],{},"text\u002Fmarkdown; charset=utf-8"," in most cases, and ",[24,355,155],{}," gets ",[24,358,359],{},"Accept",[21,361,362,365,366,370,371,194],{},[24,363,364],{},"import { whoasks } from \"whoasks\""," sets ",[33,367,369],{"href":368},"https:\u002F\u002Fgithub.com\u002Fharlan-zw\u002Fmdream","mdream"," as the converter. It calls ",[24,372,373],{},"htmlToMarkdown(html, { minimal: true, origin: url.origin, ...options })",[21,375,376,377,380,381,384,385,388,389,392],{},"With those defaults, links become absolute, the page's ",[24,378,379],{},"\u003Cnav>"," and ",[24,382,383],{},"\u003Cfooter>"," are dropped, tracking parameters such as ",[24,386,387],{},"utm_source"," are removed from links, and ",[24,390,391],{},"\u003Ctitle>"," and the meta description become front matter.",[21,394,395,396,399],{},"For an HTML page requested at ",[24,397,398],{},"https:\u002F\u002Fdocs.example.com\u002Fguide",":",[401,402,404],"pre",{"language":184,"class":403,"wrap":15},"shiki shiki-themes github-light-default github-dark-default dark:github-dark-default",[24,405,407,423,424,423,439,423,468,423,477,423,486,423,535,423,544,423,558,423,598,423,607,423,629],{"class":406},"language-html",[408,409,412,416,420],"span",{"class":410,"style":411},"line","display: inline",[408,413,415],{"style":414},"color:#1F2328;--shiki-dark:#E6EDF3","\u003C",[408,417,419],{"style":418},"color:#116329;--shiki-dark:#7EE787","head",[408,421,422],{"style":414},">","\n",[408,425,426,429,432,435,437],{"class":410,"style":411},[408,427,428],{"style":414},"  \u003C",[408,430,431],{"style":418},"title",[408,433,434],{"style":414},">Getting started\u003C\u002F",[408,436,431],{"style":418},[408,438,422],{"style":414},[408,440,441,443,446,450,453,457,460,462,465],{"class":410,"style":411},[408,442,428],{"style":414},[408,444,445],{"style":418},"meta",[408,447,449],{"style":448},"color:#0550AE;--shiki-dark:#79C0FF"," name",[408,451,452],{"style":414},"=",[408,454,456],{"style":455},"color:#0A3069;--shiki-dark:#A5D6FF","\"description\"",[408,458,459],{"style":448}," content",[408,461,452],{"style":414},[408,463,464],{"style":455},"\"Install the package and answer your first request.\"",[408,466,467],{"style":414}," \u002F>",[408,469,470,473,475],{"class":410,"style":411},[408,471,472],{"style":414},"\u003C\u002F",[408,474,419],{"style":418},[408,476,422],{"style":414},[408,478,479,481,484],{"class":410,"style":411},[408,480,415],{"style":414},[408,482,483],{"style":418},"body",[408,485,422],{"style":414},[408,487,488,490,493,496,498,501,503,506,509,511,514,516,518,520,523,526,528,531,533],{"class":410,"style":411},[408,489,428],{"style":414},[408,491,492],{"style":418},"nav",[408,494,495],{"style":414},">\u003C",[408,497,33],{"style":418},[408,499,500],{"style":448}," href",[408,502,452],{"style":414},[408,504,505],{"style":455},"\"\u002F\"",[408,507,508],{"style":414},">Home\u003C\u002F",[408,510,33],{"style":418},[408,512,513],{"style":414},"> \u003C",[408,515,33],{"style":418},[408,517,500],{"style":448},[408,519,452],{"style":414},[408,521,522],{"style":455},"\"\u002Fdocs\"",[408,524,525],{"style":414},">Docs\u003C\u002F",[408,527,33],{"style":418},[408,529,530],{"style":414},">\u003C\u002F",[408,532,492],{"style":418},[408,534,422],{"style":414},[408,536,537,539,542],{"class":410,"style":411},[408,538,428],{"style":414},[408,540,541],{"style":418},"main",[408,543,422],{"style":414},[408,545,546,549,552,554,556],{"class":410,"style":411},[408,547,548],{"style":414},"    \u003C",[408,550,551],{"style":418},"h1",[408,553,434],{"style":414},[408,555,551],{"style":418},[408,557,422],{"style":414},[408,559,560,562,564,567,569,572,574,577,579,581,583,586,589,591,594,596],{"class":410,"style":411},[408,561,548],{"style":414},[408,563,21],{"style":418},[408,565,566],{"style":414},">Install \u003C",[408,568,24],{"style":418},[408,570,571],{"style":414},">whoasks\u003C\u002F",[408,573,24],{"style":418},[408,575,576],{"style":414},"> and read \u003C",[408,578,33],{"style":418},[408,580,500],{"style":448},[408,582,452],{"style":414},[408,584,585],{"style":455},"\"\u002Fdocs\u002Fapi\"",[408,587,588],{"style":414},">the API reference\u003C\u002F",[408,590,33],{"style":418},[408,592,593],{"style":414},">.\u003C\u002F",[408,595,21],{"style":418},[408,597,422],{"style":414},[408,599,600,603,605],{"class":410,"style":411},[408,601,602],{"style":414},"  \u003C\u002F",[408,604,541],{"style":418},[408,606,422],{"style":414},[408,608,609,611,614,616,618,621,623,625,627],{"class":410,"style":411},[408,610,428],{"style":414},[408,612,613],{"style":418},"footer",[408,615,495],{"style":414},[408,617,21],{"style":418},[408,619,620],{"style":414},">Copyright 2026 Example\u003C\u002F",[408,622,21],{"style":418},[408,624,530],{"style":414},[408,626,613],{"style":418},[408,628,422],{"style":414},[408,630,631,633,635],{"class":410,"style":411},[408,632,472],{"style":414},[408,634,483],{"style":418},[408,636,422],{"style":414},[21,638,639],{},"The converter outputs:",[401,641,642],{"language":271,"class":403,"wrap":15},[24,643,645,423,650,423,660,423,666,423,675,423,679,423,681,423,687,423,689],{"class":644},"language-md",[408,646,647],{"class":410,"style":411},[408,648,649],{"style":414},"---",[408,651,652,654,657],{"class":410,"style":411},[408,653,431],{"style":418},[408,655,656],{"style":414},": ",[408,658,659],{"style":455},"\"Getting started\"",[408,661,662,664],{"class":410,"style":411},[408,663,445],{"style":418},[408,665,399],{"style":414},[408,667,668,671,673],{"class":410,"style":411},[408,669,670],{"style":418},"  description",[408,672,656],{"style":414},[408,674,464],{"style":455},[408,676,677],{"class":410,"style":411},[408,678,649],{"style":414},[408,680],{"class":410,"style":411},[408,682,683],{"class":410,"style":411},[408,684,686],{"style":685},"color:#0550AE;--shiki-light-font-weight:bold;--shiki-dark:#79C0FF;--shiki-dark-font-weight:bold","# Getting started",[408,688],{"class":410,"style":411},[408,690,691,694,697,700,703,706,710],{"class":410,"style":411},[408,692,693],{"style":414},"Install ",[408,695,696],{"style":448},"`whoasks`",[408,698,699],{"style":414}," and read [",[408,701,702],{"style":455},"the API reference",[408,704,705],{"style":414},"](",[408,707,709],{"style":708},"color:#1F2328;--shiki-light-text-decoration:underline;--shiki-dark:#E6EDF3;--shiki-dark-text-decoration:underline","https:\u002F\u002Fdocs.example.com\u002Fdocs\u002Fapi",[408,711,712],{"style":414},").",[43,714,718],{"id":715,"anchor":716},"change-the-converter",{"label":717,"icon":48},"Section titled \"Change the converter\"","Change the converter",[401,720,723],{"language":721,"filename":722,"class":403,"wrap":15},"ts","site.ts",[24,724,726,423,750,423,752,423,758,423,778,423,780,423,785,423,825,423,832,423,834,423,839],{"class":725},"language-ts",[408,727,728,732,735,738,741,744,747],{"class":410,"style":411},[408,729,731],{"style":730},"color:#CF222E;--shiki-dark:#FF7B72","import",[408,733,734],{"style":414}," { whoasks, mdream, ",[408,736,737],{"style":730},"type",[408,739,740],{"style":414}," Convert } ",[408,742,743],{"style":730},"from",[408,745,746],{"style":455}," \"whoasks\"",[408,748,749],{"style":414},";",[408,751],{"class":410,"style":411},[408,753,754],{"class":410,"style":411},[408,755,757],{"style":756},"color:#6E7781;--shiki-dark:#8B949E","\u002F\u002F Change mdream's options.",[408,759,760,764,767,769,772,775],{"class":410,"style":411},[408,761,763],{"style":762},"color:#8250DF;--shiki-dark:#D2A8FF","whoasks",[408,765,766],{"style":414},"({ convert: ",[408,768,369],{"style":762},[408,770,771],{"style":414},"({ frontmatter: ",[408,773,774],{"style":448},"false",[408,776,777],{"style":414}," }) });",[408,779],{"class":410,"style":411},[408,781,782],{"class":410,"style":411},[408,783,784],{"style":756},"\u002F\u002F Use your own. `toMarkdown` stands for your function.",[408,786,787,790,793,795,799,802,805,807,810,813,816,819,822],{"class":410,"style":411},[408,788,789],{"style":730},"const",[408,791,792],{"style":762}," convert",[408,794,399],{"style":730},[408,796,798],{"style":797},"color:#953800;--shiki-dark:#FFA657"," Convert",[408,800,801],{"style":730}," =",[408,803,804],{"style":414}," (",[408,806,184],{"style":797},[408,808,809],{"style":414},", { ",[408,811,812],{"style":797},"url",[408,814,815],{"style":414}," }) ",[408,817,818],{"style":730},"=>",[408,820,821],{"style":762}," toMarkdown",[408,823,824],{"style":414},"(html, url.origin);",[408,826,827,829],{"class":410,"style":411},[408,828,763],{"style":762},[408,830,831],{"style":414},"({ convert });",[408,833],{"class":410,"style":411},[408,835,836],{"class":410,"style":411},[408,837,838],{"style":756},"\u002F\u002F Turn conversion off.",[408,840,841,843,845,847],{"class":410,"style":411},[408,842,763],{"style":762},[408,844,766],{"style":414},[408,846,774],{"style":448},[408,848,849],{"style":414}," });",[21,851,852,855],{},[24,853,854],{},"mdream({ frontmatter: false })"," drops the front matter.",[21,857,858,859,862,863,865],{},"A converter gets the HTML and ",[24,860,861],{},"{ request, url }",", where ",[24,864,812],{}," is the canonical URL. It returns a string or a promise of one.",[21,867,868,869,272,872,874,875,877],{},"With ",[24,870,871],{},"convert: false",[24,873,40],{}," no longer offers Markdown. ",[24,876,130],{}," then gets the HTML page.",[21,879,880,881,884],{},"The last layer that sets ",[24,882,883],{},"convert"," wins, so your layer replaces the mdream default.",[43,886,890],{"id":887,"anchor":888},"without-mdream",{"label":889,"icon":48},"Section titled \"Without mdream\"","Without mdream",[401,892,893],{"language":721,"filename":722,"class":403,"wrap":15},[24,894,895,423,909,423,911,423,946,423,948,423,963,423,989],{"class":725},[408,896,897,899,902,904,907],{"class":410,"style":411},[408,898,731],{"style":730},[408,900,901],{"style":414}," { whoasks } ",[408,903,743],{"style":730},[408,905,906],{"style":455}," \"whoasks\u002Fcore\"",[408,908,749],{"style":414},[408,910],{"class":410,"style":411},[408,912,913,915,918,920,923,926,929,932,934,937,940,943],{"class":410,"style":411},[408,914,789],{"style":730},[408,916,917],{"style":448}," source",[408,919,801],{"style":730},[408,921,922],{"style":730}," new",[408,924,925],{"style":762}," Map",[408,927,928],{"style":414},"([[",[408,930,931],{"style":455},"\"\u002Fdocs\u002Fguide\"",[408,933,272],{"style":414},[408,935,936],{"style":455},"\"# Guide",[408,938,939],{"style":730},"\\n",[408,941,942],{"style":455},"\"",[408,944,945],{"style":414},"]]);",[408,947],{"class":410,"style":411},[408,949,950,952,955,957,960],{"class":410,"style":411},[408,951,789],{"style":730},[408,953,954],{"style":448}," site",[408,956,801],{"style":730},[408,958,959],{"style":762}," whoasks",[408,961,962],{"style":414},"({",[408,964,965,968,970,973,976,978,980,983,986],{"class":410,"style":411},[408,966,967],{"style":414},"  render: { ",[408,969,188],{"style":762},[408,971,972],{"style":414},": ({ ",[408,974,975],{"style":797},"ask",[408,977,815],{"style":414},[408,979,818],{"style":730},[408,981,982],{"style":414}," source.",[408,984,985],{"style":762},"get",[408,987,988],{"style":414},"(ask.url.pathname) },",[408,990,991],{"class":410,"style":411},[408,992,993],{"style":414},"});",[21,995,996,999],{},[24,997,998],{},"whoasks\u002Fcore"," has no imports and no converter.",[21,1001,1002,1003,1005,1006,1008],{},"With no converter and no renderer, ",[24,1004,40],{}," offers only HTML, so ",[24,1007,115],{}," gets the HTML page.",[21,1010,1011,1012,356,1014,1017],{},"With the renderer above, ",[24,1013,130],{},[24,1015,1016],{},"# Guide",". A page the renderer does not know gets the HTML page, because nothing can make its Markdown.",[21,1019,1020,1021,1024,1025,1027,1028,194],{},"To add mdream back, pass ",[24,1022,1023],{},"{ convert: mdream() }"," with ",[24,1026,369],{}," imported from ",[24,1029,763],{},[43,1031,1035],{"id":1032,"anchor":1033},"pages-that-already-have-markdown",{"label":1034,"icon":48},"Section titled \"Pages that already have Markdown\"","Pages that already have Markdown",[21,1037,1038,1039,194],{},"A page written in Markdown does not need conversion. A renderer returns the source, and the converter handles the pages it does not know. See ",[33,1040,193],{"href":192},[43,1042,1046],{"id":1043,"anchor":1044},"caching",{"label":1045,"icon":48},"Section titled \"Caching\"","Caching",[21,1048,1049,1050,1052,1053,1055,1056,1058,1059,1061,1062,194],{},"Every HTML page that passes through ",[24,1051,40],{}," and every converted page carries ",[24,1054,108],{},", so a cache keeps the HTML and the Markdown apart. An existing ",[24,1057,155],{}," header is kept, and ",[24,1060,359],{}," is not added twice. See ",[33,1063,155],{"href":1064},"\u002Fguide\u002Fnegotiation#vary",[1066,1068,1069,1070,1071,1072,1073,1074],{"id":45,"depth":1067,"text":49},2,{"id":206,"depth":1067,"text":209},{"id":289,"depth":1067,"text":292},{"id":327,"depth":1067,"text":330},{"id":715,"depth":1067,"text":718},{"id":887,"depth":1067,"text":890},{"id":1032,"depth":1067,"text":1035},{"id":1043,"depth":1067,"text":1046},{"path":35,"title":36,"description":1076},"Install whoasks, put it in front of an h3, Nitro, Hono or Cloudflare Workers app, and check with curl that Markdown comes back.",{"path":255,"title":1078,"description":1079},"API routes","respond answers one route in the form the request picked, from one value or function per form, with your status and headers.",1796579201371,"78c9ee36-381e-45a5-bdf8-02819f0a7eb0"]