"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["84429"],{3939:function(e,t,n){n.r(t),n.d(t,{metadata:()=>s,contentTitle:()=>h,default:()=>p,assets:()=>u,toc:()=>g,frontMatter:()=>d});var s=JSON.parse('{"type":"mdx","permalink":"/tests/pages/code-block-tests","source":"@site/_dogfooding/_pages tests/code-block-tests.mdx","title":"Code block tests","description":"This test page is quite outdated: MDX v2 lowercase tags are not substituted anymore in the same way as they were in v1.","frontMatter":{},"lastUpdatedBy":"S\xe9bastien Lorber","lastUpdatedAt":1735224247000,"editUrl":"https://github.com/facebook/docusaurus/edit/main/website/_dogfooding/_pages tests/code-block-tests.mdx","unlisted":false}'),l=n("85893"),r=n("80980"),o=n("45960"),i=n("11678"),c=n("46291"),a=n("67860");let d={},h="Code block tests",u={},g=[{value:"Code block prism language tests",id:"code-block-prism-language-tests",level:2},{value:"pre",id:"pre",level:2},{value:"pre > string",id:"pre--string",level:3},{value:"pre > string[]",id:"pre--string-1",level:3},{value:"pre > element",id:"pre--element",level:3},{value:"pre > element[]",id:"pre--element-1",level:3},{value:"pre > code > element",id:"pre--code--element",level:3},{value:"code",id:"code",level:2},{value:"code > string",id:"code--string",level:3},{value:"code > string[]",id:"code--string-1",level:3},{value:"code > element",id:"code--element",level:3},{value:"code > element[]",id:"code--element-1",level:3},{value:"CodeBlock",id:"codeblock",level:2},{value:"CodeBlock > string",id:"codeblock--string",level:3},{value:"CodeBlock > string[]",id:"codeblock--string-1",level:3},{value:"CodeBlock > element",id:"codeblock--element",level:3},{value:"CodeBlock > element[]",id:"codeblock--element-1",level:3},{value:"Code blocks with line numbering tests",id:"code-blocks-with-line-numbering-tests",level:2},{value:"Code block wrapping tests",id:"code-block-wrapping-tests",level:2},{value:"Magic comments tests",id:"magic-comments-tests",level:2},{value:"HTML - script + style highlighting",id:"html---script--style-highlighting",level:2},{value:"Empty code blocks edge cases",id:"empty-code-blocks-edge-cases",level:2}];function m(e){let t={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",hr:"hr",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(t.header,{children:(0,l.jsx)(t.h1,{id:"code-block-tests",children:"Code block tests"})}),"\n",(0,l.jsx)(t.admonition,{title:"legacy test page - MDX v1",type:"danger",children:(0,l.jsx)(t.p,{children:"This test page is quite outdated: MDX v2 lowercase tags are not substituted anymore in the same way as they were in v1."})}),"\n",(0,l.jsx)(t.hr,{}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-java",children:'class HelloWorld {\n public static void main(String args[]) {\n System.out.println("Hello, World");\n }\n}\n'})}),"\n",(0,l.jsx)(t.p,{children:"See:"}),"\n",(0,l.jsxs)(t.ul,{children:["\n",(0,l.jsx)(t.li,{children:(0,l.jsx)(t.a,{href:"https://github.com/facebook/docusaurus/pull/1584",children:"https://github.com/facebook/docusaurus/pull/1584"})}),"\n",(0,l.jsx)(t.li,{children:(0,l.jsx)(t.a,{href:"https://github.com/facebook/docusaurus/pull/3749",children:"https://github.com/facebook/docusaurus/pull/3749"})}),"\n",(0,l.jsx)(t.li,{children:(0,l.jsx)(t.a,{href:"https://github.com/facebook/docusaurus/pull/6177",children:"https://github.com/facebook/docusaurus/pull/6177"})}),"\n"]}),"\n",(0,l.jsx)(t.h2,{id:"code-block-prism-language-tests",children:"Code block prism language tests"}),"\n",(0,l.jsxs)(t.p,{children:["Code block with/without the good prism language case(lower or upper) in ",(0,l.jsx)(t.code,{children:"additionalLanguages[]"})]}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-php",metastring:'title="php"',children:'\n'})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-PHP",metastring:'title="PHP"',children:'\n'})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-pHp",metastring:'title="pHp"',children:'\n'})}),"\n",(0,l.jsx)(t.p,{children:"See:"}),"\n",(0,l.jsxs)(t.ul,{children:["\n",(0,l.jsx)(t.li,{children:(0,l.jsx)(t.a,{href:"https://github.com/facebook/docusaurus/pull/9183",children:"https://github.com/facebook/docusaurus/pull/9183"})}),"\n"]}),"\n",(0,l.jsx)(t.h2,{id:"pre",children:(0,l.jsx)(t.code,{children:"pre"})}),"\n",(0,l.jsx)(t.h3,{id:"pre--string",children:(0,l.jsx)(t.code,{children:"pre > string"})}),"\n",(0,l.jsxs)(t.p,{children:["Multi-line text inside ",(0,l.jsx)(t.code,{children:"pre"})," will turn into one-liner, but it's okay (",(0,l.jsx)(t.a,{href:"https://github.com/mdx-js/mdx/issues/1095",children:"https://github.com/mdx-js/mdx/issues/1095"}),")"]}),"\n",(0,l.jsx)("pre",{children:"1 2 3"}),"\n","\n",(0,l.jsx)("pre",{children:(0,l.jsx)(t.p,{children:"1\n2\n3"})}),"\n",(0,l.jsx)(t.h3,{id:"pre--string-1",children:(0,l.jsx)(t.code,{children:"pre > string[]"})}),"\n",(0,l.jsx)("pre",{children:(0,l.jsxs)(t.p,{children:["1","\n","2","\n","3","\n"]})}),"\n",(0,l.jsx)(t.h3,{id:"pre--element",children:(0,l.jsx)(t.code,{children:"pre > element"})}),"\n",(0,l.jsx)("pre",{children:(0,l.jsx)(i.Z,{children:"Lol bro"})}),"\n",(0,l.jsx)(t.h3,{id:"pre--element-1",children:(0,l.jsx)(t.code,{children:"pre > element[]"})}),"\n",(0,l.jsxs)("pre",{children:[(0,l.jsx)("a",{href:"/",children:"Front page"}),"\n",(0,l.jsxs)(t.p,{children:[(0,l.jsx)("strong",{children:"Input: "}),'a = "abcd", b = "cdabcdab"',"\n","\n",(0,l.jsx)("strong",{children:"Output: "}),"3","\n","\n",(0,l.jsx)("strong",{children:"Explanation: "}),'a after three repetitions become "ab\n',(0,l.jsx)("strong",{children:"cdabcdab"}),'cd", at which time b is a substring.',"\n"]})]}),"\n",(0,l.jsx)(t.h3,{id:"pre--code--element",children:(0,l.jsx)(t.code,{children:"pre > code > element"})}),"\n",(0,l.jsx)("pre",{children:(0,l.jsx)("code",{children:(0,l.jsx)("b",{children:"Hey bro"})})}),"\n",(0,l.jsx)(t.h2,{id:"code",children:(0,l.jsx)(t.code,{children:"code"})}),"\n",(0,l.jsx)(t.h3,{id:"code--string",children:(0,l.jsx)(t.code,{children:"code > string"})}),"\n",(0,l.jsx)("code",{children:"1 2 3"}),"\n",(0,l.jsx)("code",{children:`link: title: front page path: /docs/`}),"\n",(0,l.jsx)(t.h3,{id:"code--string-1",children:(0,l.jsx)(t.code,{children:"code > string[]"})}),"\n",(0,l.jsx)("code",{children:(0,l.jsxs)(t.p,{children:["link:"," \n","\n"," ","title: front page","\n","\n"," ","path: /docs/","\n"]})}),"\n",(0,l.jsx)(t.h3,{id:"code--element",children:(0,l.jsx)(t.code,{children:"code > element"})}),"\n",(0,l.jsx)("code",{children:(0,l.jsx)(i.Z,{children:"Lol bro"})}),"\n",(0,l.jsx)(t.h3,{id:"code--element-1",children:(0,l.jsx)(t.code,{children:"code > element[]"})}),"\n",(0,l.jsxs)("code",{children:[(0,l.jsx)("a",{href:"/",children:"Front page"}),(0,l.jsx)("br",{}),(0,l.jsxs)(t.p,{children:[(0,l.jsx)("strong",{children:"Input: "}),'a = "abcd", b = "cdabcdab"']}),(0,l.jsx)("br",{}),(0,l.jsxs)(t.p,{children:[(0,l.jsx)("strong",{children:"Output: "}),"3",(0,l.jsx)("br",{}),"\n",(0,l.jsx)("strong",{children:"Explanation: "}),'a after three repetitions become "ab',(0,l.jsx)("strong",{children:"\ncdabcdab\n"}),'cd", at which time b is a substring.']}),(0,l.jsx)("br",{})]}),"\n",(0,l.jsx)(t.h2,{id:"codeblock",children:(0,l.jsx)(t.code,{children:"CodeBlock"})}),"\n",(0,l.jsx)(t.h3,{id:"codeblock--string",children:(0,l.jsx)(t.code,{children:"CodeBlock > string"})}),"\n",(0,l.jsx)(o.Z,{children:"1 2 3"}),"\n",(0,l.jsx)(o.Z,{className:"language-yaml",title:"test",children:`link: title: front page path: /docs/`}),"\n",(0,l.jsx)(t.h3,{id:"codeblock--string-1",children:(0,l.jsx)(t.code,{children:"CodeBlock > string[]"})}),"\n",(0,l.jsx)(o.Z,{className:"language-yaml",title:"test",children:(0,l.jsxs)(t.p,{children:["link:","\n","\n"," ","title: front page","\n","\n"," ","path: /docs/","\n"]})}),"\n",(0,l.jsx)(t.h3,{id:"codeblock--element",children:(0,l.jsx)(t.code,{children:"CodeBlock > element"})}),"\n",(0,l.jsx)(o.Z,{className:"language-yaml",title:"test",children:(0,l.jsx)(i.Z,{children:"Lol bro"})}),"\n",(0,l.jsx)(t.h3,{id:"codeblock--element-1",children:(0,l.jsx)(t.code,{children:"CodeBlock > element[]"})}),"\n",(0,l.jsxs)(o.Z,{className:"language-yaml",title:"test",children:[(0,l.jsx)("a",{href:"/",children:"Front page"}),(0,l.jsx)("br",{}),(0,l.jsxs)(t.p,{children:[(0,l.jsx)("strong",{children:"Input: "}),'a = "abcd", b = "cdabcdab"']}),(0,l.jsx)("br",{}),(0,l.jsxs)(t.p,{children:[(0,l.jsx)("strong",{children:"Output: "}),"3",(0,l.jsx)("br",{}),"\n",(0,l.jsx)("strong",{children:"Explanation: "}),'a after three repetitions become "ab',(0,l.jsx)("strong",{children:"\ncdabcdab\n"}),'cd", at which time b is a substring.']}),(0,l.jsx)("br",{})]}),"\n",(0,l.jsx)(t.h2,{id:"code-blocks-with-line-numbering-tests",children:"Code blocks with line numbering tests"}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-jsx",children:'function PageLayout(props) {\n // highlight-next-line\n return ;\n}\n'})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-jsx",metastring:"showLineNumbers",children:'function PageLayout(props) {\n // highlight-next-line\n return ;\n}\n'})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-jsx",metastring:"{1,3,6} showLineNumbers",children:"function PageLayout(props) {\n console.log(\n 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',\n );\n console.log(\n 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',\n );\n console.log(\n 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',\n );\n console.log(\n 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',\n );\n console.log(\n 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',\n );\n console.log(\n 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',\n );\n console.log(\n 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',\n );\n console.log(\n 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',\n );\n console.log(\n 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',\n );\n}\n"})}),"\n",(0,l.jsx)(t.h2,{id:"code-block-wrapping-tests",children:"Code block wrapping tests"}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-bash",children:'mkdir this_is_a_loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_string_to_test_code_block_wrapping\necho "this is a long string made up of many separate words that should be broken between words when possible"\ncurl https://docusaurus.io/tests/pages/code-block-tests\n'})}),"\n",(0,l.jsxs)(c.Z,{children:[(0,l.jsx)(a.Z,{value:"short-tab-1",label:"Short tab",children:(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-bash",children:'echo "hi"\n'})})}),(0,l.jsx)(a.Z,{value:"long-tab",label:"Long tab",children:(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-bash",children:"echo this will test whether a long string that is initially hidden will have the option to wrap when made visible\n"})})}),(0,l.jsx)(a.Z,{value:"short-tab-2",label:"Short tab",children:(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-bash",children:"rm short_initially_hidden_string\n"})})})]}),"\n",(0,l.jsxs)(c.Z,{children:[(0,l.jsx)(a.Z,{value:"long-tab",label:"Long tab",children:(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-bash",children:"echo medium_length_string_will_have_the_option_to_wrap_after_window_resized_while_it_is_hidden\n"})})}),(0,l.jsx)(a.Z,{value:"short-tab",label:"Short tab",children:(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-bash",children:'echo "short_initially_hidden_string"\n'})})})]}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-jsx",metastring:"showLineNumbers",children:"import React from 'react';\nimport Layout from '@theme/Layout';\n\nexport default function MyReactPage() {\n return (\n \n

My React page

\n

\n This is a React page. Let's make this sentence bit long. Some more words\n to make sure... Some more words to make sure... Some more words to make\n sure...\n

\n
\n );\n}\n"})}),"\n",(0,l.jsx)(t.h2,{id:"magic-comments-tests",children:"Magic comments tests"}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-lua",metastring:'title="lua_sum.lua"',children:"function sum(n)\n -- highlight-next-line\n local result = 0\n for i = 1, n do\n -- highlight-start\n result = result + i\n end\n -- highlight-end\n print(result)\nend\n"})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-haskell",metastring:'title="haskell.hs"',children:"stringLength :: String -> Int\n-- highlight-next-line\nstringLength [] = 0\nstringLength (x:xs) = 1 + stringLength xs\n"})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-wasm",metastring:'title="sum_webAssembly.wasm"',children:'(module\n ;; highlight-next-line\n (func $add (param $a i32) (param $b i32) (result i32)\n local.get $a\n ;; highlight-start\n local.get $b\n i32.add)\n ;; highlight-end\n (export "add" (func $add)))\n'})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-sql",metastring:'title="sql_query.sql"',children:"-- highlight-start\nSELECT *\nFROM orders\n-- highlight-end\nWHERE customer_id IN (\n SELECT customer_id\n -- highlight-next-line\n FROM customers\n WHERE country = 'USA'\n)\n"})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-sql",metastring:'title="sql_query_block.sql"',children:"/* highlight-start */\nSELECT *\nFROM orders\n/* highlight-end */\nWHERE customer_id IN (\n SELECT customer_id\n /* highlight-next-line */\n FROM customers\n WHERE country = 'USA'\n)\n"})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-matlab",metastring:'title="matlab.m"',children:"% highlight-start\nfunction result = times2(n)\n result = n * 2;\nend\n% highlight-end\n\nx = 10;\n% highlight-next-line\ny = times2(x);\n"})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-latex",metastring:'title="latex.tex"',children:"\\begin{document}\n \\section{Triangles}\n % highlight-next-line\n \\subsection{Pythagoras' Theorem}\n Pythagoras's theorem is:\n % highlight-start\n \\begin{equation}\n c^2 = a^2 + b^2\n \\end{equation}\n % highlight-end\n\\end{document}\n"})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-vba",metastring:'title="vba.vb"',children:"Function Factorial(ByVal n As Long) As Long\n If n < 0 Then\n Err.Raise 5 ' Invalid argument\n End If\n 'highlight-next-line\n Factorial = 1 ' return value\n Dim i As Long\n ' highlight-start\n For i = 2 To n\n Factorial = Factorial * i\n Next\n ' highlight-end\nEnd Function\n"})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-vbnet",metastring:'title="vbnet.vb"',children:'\' highlight-next-line\nDim languages As New HashSet(Of String) From {\n "C#",\n "Visual Basic",\n _ \' highlight-start\n "F#",\n "PowerShell",\n "TypeScript"\n _\' highlight-end\n}\n'})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-batch",metastring:'title="cmd.bat"',children:"rem highlight-start\n@echo off\nsetlocal\nRem highlight-end\nipconfig\nREM highlight-next-line\necho Docusaurus is awesome\nnetstat\n"})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-fortran",metastring:'title="fortran.f90"',children:'! highlight-start\nprogram hello\n! highlight-end\n implicit none\n ! highlight-next-line\n print *, "Hello, World!"\nend program hello\n'})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-cobol",metastring:'title="cobol.cob"',children:'*> highlight-start\nIDENTIFICATION DIVISION.\nPROGRAM-ID. HELLO.\n*> highlight-end\nPROCEDURE DIVISION.\n *> highlight-next-line\n DISPLAY "Hello, World!".\nEND PROGRAM HELLO.\n'})}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-fsharp",metastring:'title="fsharp.fsx"',children:'(* highlight-start *)\n[]\n(* highlight-end *)\nlet main _ =\n // highlight-next-line\n printfn "Hello, World!"\n 0\n'})}),"\n",(0,l.jsx)(t.h2,{id:"html---script--style-highlighting",children:"HTML - script + style highlighting"}),"\n",(0,l.jsxs)(t.p,{children:["See ",(0,l.jsx)(t.a,{href:"https://github.com/facebook/docusaurus/issues/9517",children:"https://github.com/facebook/docusaurus/issues/9517"})]}),"\n",(0,l.jsx)(t.pre,{children:(0,l.jsx)(t.code,{className:"language-html",children:"\n \n