[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$KiqIp5Qu8t":3,"blog-\u002Fblog\u002Frendering-dynamic-markdown-in-nuxt-3":52,"blogToc-\u002Fblog\u002Frendering-dynamic-markdown-in-nuxt-3":499,"blog-surrounding-\u002Fblog\u002Frendering-dynamic-markdown-in-nuxt-3":782,"blog-similar-posts-\u002Fblog\u002Frendering-dynamic-markdown-in-nuxt-3":791},{"id":4,"extension":5,"items":6,"meta":49,"stem":50,"__hash__":51},"menu\u002Fmenu.json","json",[7,12,16,20,24,28,32,36,41,45],{"i18nId":8,"to":9,"ariaLabel":10,"mainNavigation":11},"components.menu.home","\u002F","Home",true,{"i18nId":13,"to":14,"ariaLabel":15,"mainNavigation":11},"components.menu.about","\u002Fhire-me","About",{"i18nId":17,"to":18,"ariaLabel":19,"mainNavigation":11},"components.menu.testimonials","\u002Ftestimonials","Testimonials",{"i18nId":21,"to":22,"ariaLabel":23},"components.menu.contact","\u002Fcontact","Contact",{"i18nId":25,"to":26,"ariaLabel":27,"mainNavigation":11},"components.menu.blog","\u002Fblog","Blog",{"i18nId":29,"to":30,"ariaLabel":31,"mainNavigation":11},"components.menu.tips","\u002Fvue-tips","Vue Tips",{"i18nId":33,"to":34,"ariaLabel":35,"mainNavigation":11},"components.menu.projects","\u002Fprojects","Projects",{"i18nId":37,"to":38,"ariaLabel":39,"mainNavigation":40},"components.menu.stats","\u002Fstats","stats",false,{"i18nId":42,"to":43,"ariaLabel":44,"mainNavigation":40},"components.menu.businessCard","\u002Fbusiness-card","Business Card",{"i18nId":46,"to":47,"ariaLabel":48,"mainNavigation":40},"components.menu.publications","\u002Fpublications","Publications",{},"menu","njLT1QoRt2Dv8QWoVmH8xdTAiDywSj0bxBQdmoyWUE0",{"id":53,"title":54,"body":55,"categories":479,"cover":484,"date":485,"description":486,"extension":379,"lastUpdated":487,"meta":488,"navigation":11,"ogImage":487,"path":489,"readingTime":490,"robots":487,"schemaOrg":487,"seo":495,"sitemap":496,"stem":497,"tags":487,"__hash__":498},"blog\u002Fblog\u002Frendering-dynamic-markdown-in-nuxt-3\u002Findex.md","Rendering Dynamic Markdown in Nuxt 3+",{"type":56,"value":57,"toc":473},"minimark",[58,62,67,70,78,82,99,110,113,143,153,160,406,418,431,435,438,442,446,452,461,469],[59,60,61],"p",{},"In my current freelance project, I had to render dynamic Markdown content in a Nuxt 3+ application. The Markdown content was written by redactors in a CMS, provided via an API, and needed to be rendered on the client-side. In this article, I'll explain how we solved the problem of rendering dynamic Markdown content in a Nuxt 3+ application.",[63,64,66],"h2",{"id":65},"the-problem","The Problem",[59,68,69],{},"The Markdown content was provided by the CMS via an API and needed to be rendered on the client-side. The content was dynamic and could change at any time, so we couldn't hard-code it into the application. We needed a way to fetch the Markdown content from the API and render it as HTML in the Nuxt 3+ application.",[59,71,72,73,77],{},"Previously, the redactors wrote that content in HTML, and we used the ",[74,75,76],"code",{},"v-html"," directive to render it. However, we wanted to switch to Markdown to make it easier for the redactors to write and format the content. Additionally, this allowed us to easily reuse our existing Vue components.",[63,79,81],{"id":80},"the-solution","The Solution",[83,84,85],"note",{},[59,86,87,88,98],{},"If you are only working with static Markdown files, you can use the ",[89,90,94,97],"a",{"href":91,"rel":92},"https:\u002F\u002Fcontent.nuxt.com\u002F",[93],"nofollow",[74,95,96],{},"@nuxt\u002Fcontent"," module"," to render Markdown content in your Nuxt 3+ application.",[59,100,101,102,109],{},"Luckily, Nuxt 3+ provides a solution for rendering Markdown content using the ",[89,103,106,97],{"href":104,"rel":105},"https:\u002F\u002Fgithub.com\u002Fnuxt-modules\u002Fmdc",[93],[74,107,108],{},"@nuxtjs\u002Fmdc",". This module allows you to render Markdown content as HTML in your Nuxt 3+ application.",[59,111,112],{},"You can add it to your project using the following command:",[114,115,120],"pre",{"className":116,"code":117,"language":118,"meta":119,"style":119},"language-bash shiki shiki-themes github-light poimandres poimandres","npx nuxi@latest module add mdc\n","bash","",[74,121,122],{"__ignoreMap":119},[123,124,127,131,135,137,140],"span",{"class":125,"line":126},"line",1,[123,128,130],{"class":129},"sgaD9","npx",[123,132,134],{"class":133},"sMmyg"," nuxi@latest",[123,136,97],{"class":133},[123,138,139],{"class":133}," add",[123,141,142],{"class":133}," mdc\n",[59,144,145,146,148,149,152],{},"This command will install the ",[74,147,108],{}," module and add it to the modules section of your ",[74,150,151],{},"nuxt.config.ts"," file.",[59,154,155,156,159],{},"Now you can use the ",[74,157,158],{},"\u003CMDC>"," component to render Markdown content in your Vue components. Here's an example of how you can use it:",[114,161,168],{"className":162,"code":163,"filename":164,"highlights":165,"language":167,"meta":119,"style":119},"language-vue shiki shiki-themes github-light poimandres poimandres","\u003Cscript setup lang=\"ts\">\nconst md = ``# h1\n\n## h2\n\nThis is a paragraph\n\nThis is a [link](https:\u002F\u002Fmokkapps.de)\n\n::my-button\nClick me\n::`\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CMDC :value=\"md\" tag=\"article\" \u002F>\n\u003C\u002Ftemplate>\n","Component.vue",[166],16,"vue",[74,169,170,204,227,233,242,247,262,267,295,300,315,324,332,342,347,357,397],{"__ignoreMap":119},[123,171,172,176,180,184,187,191,195,199,201],{"class":125,"line":126},[123,173,175],{"class":174},"sMzB8","\u003C",[123,177,179],{"class":178},"s8PnL","script",[123,181,183],{"class":182},"sppiw"," setup",[123,185,186],{"class":182}," lang",[123,188,190],{"class":189},"sygvE","=",[123,192,194],{"class":193},"srEIG","\"",[123,196,198],{"class":197},"skTdI","ts",[123,200,194],{"class":193},[123,202,203],{"class":174},">\n",[123,205,207,211,215,218,221,224],{"class":125,"line":206},2,[123,208,210],{"class":209},"slWGy","const",[123,212,214],{"class":213},"sGRIV"," md",[123,216,217],{"class":209}," =",[123,219,220],{"class":193}," ``",[123,222,223],{"class":189},"# ",[123,225,226],{"class":174},"h1\n",[123,228,230],{"class":125,"line":229},3,[123,231,232],{"emptyLinePlaceholder":11},"\n",[123,234,236,239],{"class":125,"line":235},4,[123,237,238],{"class":189},"## ",[123,240,241],{"class":174},"h2\n",[123,243,245],{"class":125,"line":244},5,[123,246,232],{"emptyLinePlaceholder":11},[123,248,250,253,256,259],{"class":125,"line":249},6,[123,251,252],{"class":174},"This",[123,254,255],{"class":174}," is",[123,257,258],{"class":174}," a",[123,260,261],{"class":174}," paragraph\n",[123,263,265],{"class":125,"line":264},7,[123,266,232],{"emptyLinePlaceholder":11},[123,268,270,272,274,276,279,282,285,288,291],{"class":125,"line":269},8,[123,271,252],{"class":174},[123,273,255],{"class":174},[123,275,258],{"class":174},[123,277,278],{"class":189}," [",[123,280,281],{"class":174},"link",[123,283,284],{"class":189},"](",[123,286,287],{"class":174},"https",[123,289,290],{"class":189},":",[123,292,294],{"class":293},"s1MN7","\u002F\u002Fmokkapps.de)\n",[123,296,298],{"class":125,"line":297},9,[123,299,232],{"emptyLinePlaceholder":11},[123,301,303,306,309,312],{"class":125,"line":302},10,[123,304,305],{"class":189},"::",[123,307,308],{"class":174},"my",[123,310,311],{"class":209},"-",[123,313,314],{"class":174},"button\n",[123,316,318,321],{"class":125,"line":317},11,[123,319,320],{"class":174},"Click",[123,322,323],{"class":174}," me\n",[123,325,327,329],{"class":125,"line":326},12,[123,328,305],{"class":189},[123,330,331],{"class":193},"`\n",[123,333,335,338,340],{"class":125,"line":334},13,[123,336,337],{"class":174},"\u003C\u002F",[123,339,179],{"class":178},[123,341,203],{"class":174},[123,343,345],{"class":125,"line":344},14,[123,346,232],{"emptyLinePlaceholder":11},[123,348,350,352,355],{"class":125,"line":349},15,[123,351,175],{"class":174},[123,353,354],{"class":178},"template",[123,356,203],{"class":174},[123,358,361,364,367,370,373,375,377,380,382,385,387,389,392,394],{"class":359,"line":166},[125,360],"highlight",[123,362,363],{"class":174},"  \u003C",[123,365,366],{"class":178},"MDC",[123,368,369],{"class":189}," :",[123,371,372],{"class":182},"value",[123,374,190],{"class":189},[123,376,194],{"class":193},[123,378,379],{"class":174},"md",[123,381,194],{"class":193},[123,383,384],{"class":182}," tag",[123,386,190],{"class":189},[123,388,194],{"class":193},[123,390,391],{"class":197},"article",[123,393,194],{"class":193},[123,395,396],{"class":174}," \u002F>\n",[123,398,400,402,404],{"class":125,"line":399},17,[123,401,337],{"class":174},[123,403,354],{"class":178},[123,405,203],{"class":174},[59,407,408,409,413,414,417],{},"That's it! The Markdown content will be rendered as HTML in your Nuxt app. Using the ",[89,410,366],{"href":411,"rel":412},"https:\u002F\u002Fcontent.nuxt.com\u002Fusage\u002Fmarkdown",[93]," syntax, you can also include custom Vue components in your Markdown content. In my example, I referenced the ",[74,415,416],{},"my-button"," component, which will be rendered as a button in the Markdown content.",[83,419,420],{},[59,421,422,423,426,427,430],{},"You have to globally register your Vue components if you want to use them in the Markdown content. You can do this by placing them in a ",[74,424,425],{},"~\u002Fcomponents\u002Fglobal"," directory or by using a ",[74,428,429],{},".global.vue"," suffix in the filename.",[63,432,434],{"id":433},"stackblitz-demo","Stackblitz Demo",[59,436,437],{},"Try it yourself in the following Stackblitz demo:",[439,440],"stackblitz",{"project-id":441},"nuxt-markdown-to-vue-converter",[63,443,445],{"id":444},"conclusion","Conclusion",[59,447,448,449,451],{},"Rendering dynamic Markdown content in a Nuxt 3+ application is easy using the ",[74,450,108],{}," module. By using Markdown, you can make it easier for redactors to write and format content and reuse your existing Vue components.",[59,453,454,455,460],{},"If you liked this article, follow me on ",[89,456,459],{"href":457,"rel":458},"https:\u002F\u002Fx.com\u002Fmokkapps",[93],"X"," to get notified about my new blog posts and more content.",[59,462,463,464,290],{},"Alternatively (or additionally), you can ",[89,465,468],{"href":466,"rel":467},"https:\u002F\u002Fweekly-vue.news",[93],"subscribe to my weekly Vue & Nuxt newsletter",[470,471,472],"style",{},"html pre.shiki code .sgaD9, html code.shiki .sgaD9{--shiki-light:#6F42C1;--shiki-default:#91B4D5;--shiki-dark:#91B4D5}html pre.shiki code .sMmyg, html code.shiki .sMmyg{--shiki-light:#032F62;--shiki-default:#ADD7FF;--shiki-dark:#ADD7FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sMzB8, html code.shiki .sMzB8{--shiki-light:#24292E;--shiki-default:#E4F0FB;--shiki-dark:#E4F0FB}html pre.shiki code .s8PnL, html code.shiki .s8PnL{--shiki-light:#22863A;--shiki-default:#5DE4C7;--shiki-dark:#5DE4C7}html pre.shiki code .sppiw, html code.shiki .sppiw{--shiki-light:#6F42C1;--shiki-light-font-style:inherit;--shiki-default:#91B4D5;--shiki-default-font-style:italic;--shiki-dark:#91B4D5;--shiki-dark-font-style:italic}html pre.shiki code .sygvE, html code.shiki .sygvE{--shiki-light:#24292E;--shiki-default:#A6ACCD;--shiki-dark:#A6ACCD}html pre.shiki code .srEIG, html code.shiki .srEIG{--shiki-light:#032F62;--shiki-default:#A6ACCD;--shiki-dark:#A6ACCD}html pre.shiki code .skTdI, html code.shiki .skTdI{--shiki-light:#032F62;--shiki-default:#5DE4C7;--shiki-dark:#5DE4C7}html pre.shiki code .slWGy, html code.shiki .slWGy{--shiki-light:#D73A49;--shiki-default:#91B4D5;--shiki-dark:#91B4D5}html pre.shiki code .sGRIV, html code.shiki .sGRIV{--shiki-light:#005CC5;--shiki-default:#E4F0FB;--shiki-dark:#E4F0FB}html pre.shiki code .s1MN7, html code.shiki .s1MN7{--shiki-light:#6A737D;--shiki-light-font-style:inherit;--shiki-default:#767C9DB0;--shiki-default-font-style:italic;--shiki-dark:#767C9DB0;--shiki-dark-font-style:italic}",{"title":119,"searchDepth":206,"depth":206,"links":474},[475,476,477,478],{"id":65,"depth":206,"text":66},{"id":80,"depth":206,"text":81},{"id":433,"depth":206,"text":434},{"id":444,"depth":206,"text":445},[480,481,482,483],"development","frontend","vue-js","nuxt-js","blog\u002Frendering-dynamic-markdown-in-nuxt-3\u002Fog.png","2024-10-14","Learn how to dynamically render markdown content in a Nuxt 3+ application using the @nuxtjs\u002Fmdc module.",null,{},"\u002Fblog\u002Frendering-dynamic-markdown-in-nuxt-3",{"text":491,"minutes":492,"time":493,"words":494},"3 min read",2.235,134100,447,{"title":54,"description":486},{"loc":489,"lastmod":485},"blog\u002Frendering-dynamic-markdown-in-nuxt-3\u002Findex","lSLZRpeDUh4rz45yuIpD7b00vVUDYeWAfm59r9IZCTs",{"id":500,"title":54,"body":501,"cover":484,"description":486,"extension":379,"meta":776,"navigation":11,"path":489,"robots":487,"seo":779,"sitemap":780,"stem":497,"__hash__":781},"content\u002Fblog\u002Frendering-dynamic-markdown-in-nuxt-3\u002Findex.md",{"type":56,"value":502,"toc":770},[503,505,507,509,513,515,524,531,533,549,555,559,731,738,746,748,750,752,754,758,763,768],[59,504,61],{},[63,506,66],{"id":65},[59,508,69],{},[59,510,72,511,77],{},[74,512,76],{},[63,514,81],{"id":80},[83,516,517],{},[59,518,87,519,98],{},[89,520,522,97],{"href":91,"rel":521},[93],[74,523,96],{},[59,525,101,526,109],{},[89,527,529,97],{"href":104,"rel":528},[93],[74,530,108],{},[59,532,112],{},[114,534,535],{"className":116,"code":117,"language":118,"meta":119,"style":119},[74,536,537],{"__ignoreMap":119},[123,538,539,541,543,545,547],{"class":125,"line":126},[123,540,130],{"class":129},[123,542,134],{"class":133},[123,544,97],{"class":133},[123,546,139],{"class":133},[123,548,142],{"class":133},[59,550,145,551,148,553,152],{},[74,552,108],{},[74,554,151],{},[59,556,155,557,159],{},[74,558,158],{},[114,560,562],{"className":162,"code":163,"filename":164,"highlights":561,"language":167,"meta":119,"style":119},[166],[74,563,564,584,598,602,608,612,622,626,646,650,660,666,672,680,684,692,723],{"__ignoreMap":119},[123,565,566,568,570,572,574,576,578,580,582],{"class":125,"line":126},[123,567,175],{"class":174},[123,569,179],{"class":178},[123,571,183],{"class":182},[123,573,186],{"class":182},[123,575,190],{"class":189},[123,577,194],{"class":193},[123,579,198],{"class":197},[123,581,194],{"class":193},[123,583,203],{"class":174},[123,585,586,588,590,592,594,596],{"class":125,"line":206},[123,587,210],{"class":209},[123,589,214],{"class":213},[123,591,217],{"class":209},[123,593,220],{"class":193},[123,595,223],{"class":189},[123,597,226],{"class":174},[123,599,600],{"class":125,"line":229},[123,601,232],{"emptyLinePlaceholder":11},[123,603,604,606],{"class":125,"line":235},[123,605,238],{"class":189},[123,607,241],{"class":174},[123,609,610],{"class":125,"line":244},[123,611,232],{"emptyLinePlaceholder":11},[123,613,614,616,618,620],{"class":125,"line":249},[123,615,252],{"class":174},[123,617,255],{"class":174},[123,619,258],{"class":174},[123,621,261],{"class":174},[123,623,624],{"class":125,"line":264},[123,625,232],{"emptyLinePlaceholder":11},[123,627,628,630,632,634,636,638,640,642,644],{"class":125,"line":269},[123,629,252],{"class":174},[123,631,255],{"class":174},[123,633,258],{"class":174},[123,635,278],{"class":189},[123,637,281],{"class":174},[123,639,284],{"class":189},[123,641,287],{"class":174},[123,643,290],{"class":189},[123,645,294],{"class":293},[123,647,648],{"class":125,"line":297},[123,649,232],{"emptyLinePlaceholder":11},[123,651,652,654,656,658],{"class":125,"line":302},[123,653,305],{"class":189},[123,655,308],{"class":174},[123,657,311],{"class":209},[123,659,314],{"class":174},[123,661,662,664],{"class":125,"line":317},[123,663,320],{"class":174},[123,665,323],{"class":174},[123,667,668,670],{"class":125,"line":326},[123,669,305],{"class":189},[123,671,331],{"class":193},[123,673,674,676,678],{"class":125,"line":334},[123,675,337],{"class":174},[123,677,179],{"class":178},[123,679,203],{"class":174},[123,681,682],{"class":125,"line":344},[123,683,232],{"emptyLinePlaceholder":11},[123,685,686,688,690],{"class":125,"line":349},[123,687,175],{"class":174},[123,689,354],{"class":178},[123,691,203],{"class":174},[123,693,695,697,699,701,703,705,707,709,711,713,715,717,719,721],{"class":694,"line":166},[125,360],[123,696,363],{"class":174},[123,698,366],{"class":178},[123,700,369],{"class":189},[123,702,372],{"class":182},[123,704,190],{"class":189},[123,706,194],{"class":193},[123,708,379],{"class":174},[123,710,194],{"class":193},[123,712,384],{"class":182},[123,714,190],{"class":189},[123,716,194],{"class":193},[123,718,391],{"class":197},[123,720,194],{"class":193},[123,722,396],{"class":174},[123,724,725,727,729],{"class":125,"line":399},[123,726,337],{"class":174},[123,728,354],{"class":178},[123,730,203],{"class":174},[59,732,408,733,413,736,417],{},[89,734,366],{"href":411,"rel":735},[93],[74,737,416],{},[83,739,740],{},[59,741,422,742,426,744,430],{},[74,743,425],{},[74,745,429],{},[63,747,434],{"id":433},[59,749,437],{},[439,751],{"project-id":441},[63,753,445],{"id":444},[59,755,448,756,451],{},[74,757,108],{},[59,759,454,760,460],{},[89,761,459],{"href":457,"rel":762},[93],[59,764,463,765,290],{},[89,766,468],{"href":466,"rel":767},[93],[470,769,472],{},{"title":119,"searchDepth":206,"depth":206,"links":771},[772,773,774,775],{"id":65,"depth":206,"text":66},{"id":80,"depth":206,"text":81},{"id":433,"depth":206,"text":434},{"id":444,"depth":206,"text":445},{"categories":777,"date":485,"readingTime":778},[480,481,482,483],{"text":491,"minutes":492,"time":493,"words":494},{"title":54,"description":486},{"loc":489,"lastmod":485},"JaMTkdvrJ412kq2FXSOxJ6HDVmxzi5cwmkLSTc_vo0s",[783,787],{"title":784,"path":785,"stem":786,"children":-1},"When to Use useState in Nuxt","\u002Fblog\u002Fwhen-to-use-use-state-in-nuxt","blog\u002Fwhen-to-use-use-state-in-nuxt\u002Findex",{"title":788,"path":789,"stem":790,"children":-1},"Analyze Memory Leaks in Your Nuxt App","\u002Fblog\u002Fanalyze-memory-leaks-in-your-nuxt-app","blog\u002Fanalyze-memory-leaks-in-your-nuxt-app\u002Findex",[792,797,800,805],{"cover":793,"date":794,"slug":795,"title":796,"to":795},"blog\u002Fa-comprehensive-guide-to-data-fetching-in-nuxt-3\u002Fog.png","2023-06-20","\u002Fblog\u002Fa-comprehensive-guide-to-data-fetching-in-nuxt-3","A Comprehensive Guide to Data Fetching in Nuxt 3",{"cover":798,"date":799,"slug":789,"title":788,"to":789},"blog\u002Fanalyze-memory-leaks-in-your-nuxt-app\u002Fog.png","2024-07-27",{"cover":801,"date":802,"slug":803,"title":804,"to":803},"blog\u002Fbuilding-a-polite-newsletter-popup-with-nuxt-3\u002FBlog_Post__Polite_Popup_Nuxt_3_k8ch1w.jpg","2022-10-18","\u002Fblog\u002Fbuilding-a-polite-newsletter-popup-with-nuxt-3","Building a Polite Newsletter Popup With Nuxt 3",{"cover":806,"date":807,"slug":808,"title":809,"to":808},"blog\u002Fcreate-a-table-of-contents-with-active-states-in-nuxt-3\u002FBlog_Post__ToC_Nuxt_Content_dlbmpz.jpg","2022-12-07","\u002Fblog\u002Fcreate-a-table-of-contents-with-active-states-in-nuxt-3","Create a Table of Contents With Active States in Nuxt 3"]