跳到主內容

程式區塊測試

過時的測試頁面 - MDX v1

這個測試頁面已相當過時: MDX v2 小寫標籤不再以 v1 的方式替代。


class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello, World");
}
}

請參閱

Code block prism 語言測試

程式區塊在 additionalLanguages[] 中是否有正確的 prism 語言大小寫(小寫或大寫)

php
<?php
$x=15;
$y=30;
$z=$x+$y;
echo "Sum: ",$z;
?>
PHP
<?php
$x=15;
$y=30;
$z=$x+$y;
echo "Sum: ",$z;
?>
pHp
<?php
$x=15;
$y=30;
$z=$x+$y;
echo "Sum: ",$z;
?>

請參閱

pre

pre > string

pre 內的多行文字將變成單行文字,但無妨(https://github.com/mdx-js/mdx/issues/1095)

1 2 3

1 2 3

pre > string[]

1 2 3

pre > element

https://127.0.0.1:3000
Lol bro

pre > element[]

Front page

Input: a = "abcd", b = "cdabcdab" Output: 3 Explanation: a after three repetitions become "ab cdabcdabcd", at which time b is a substring.

pre > code > element

Hey bro

code

code > string

1 2 3 link: title: 首頁 path: /docs/

code > string[]

link title: 首頁 path: /docs/

code > element

https://127.0.0.1:3000
Lol bro

code > element[]

首頁

輸入:a = "abcd",b = "cdabcdab"


輸出3
說明:三次重複後的 a 會變成「ab cdabcdab cd」,此時 b 為子字串。


CodeBlock

CodeBlock > string

1 2 3
test
link:
title: front page
path: /docs/

CodeBlock > string[]

link: title: front page path: /docs/

CodeBlock > element

https://127.0.0.1:3000
Lol bro

CodeBlock > element[]

Front page

Input: a = "abcd", b = "cdabcdab"


Output: 3
Explanation: a after three repetitions become "ab cdabcdab cd", at which time b is a substring.


附行號測試的程式區塊

function PageLayout(props) {
return <Layout title="Awesome Docusaurus page" description="Test Test Test Test Test Test Test Test Test Test Test Test Test Test ">;
}
function PageLayout(props) {
return <Layout title="Awesome Docusaurus page" description="Test Test Test Test Test Test Test Test Test Test Test Test Test Test ">;
}
function PageLayout(props) {
console.log(
'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',
);
console.log(
'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',
);
console.log(
'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',
);
console.log(
'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',
);
console.log(
'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',
);
console.log(
'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',
);
console.log(
'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',
);
console.log(
'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',
);
console.log(
'Test Test Test Test Test Test Test Test Test Test Test Test Test Test ',
);
}

程式區塊換行測試

mkdir this_is_a_loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_string_to_test_code_block_wrapping
echo "this is a long string made up of many separate words that should be broken between words when possible"
curl https://docusaurus.dev.org.tw/tests/pages/code-block-tests
echo "hi"
echo medium_length_string_will_have_the_option_to_wrap_after_window_resized_while_it_is_hidden
import React from 'react';
import Layout from '@theme/Layout';

export default function MyReactPage() {
return (
<Layout>
<h1>My React page</h1>
<p>
This is a React page. Let's make this sentence bit long. Some more words
to make sure... Some more words to make sure... Some more words to make
sure...
</p>
</Layout>
);
}

特殊註解測試

lua_sum.lua
function sum(n)
local result = 0
for i = 1, n do
result = result + i
end
print(result)
end
haskell.hs
stringLength :: String -> Int
stringLength [] = 0
stringLength (x:xs) = 1 + stringLength xs
sum_webAssembly.wasm
(module
(func $add (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.add)
(export "add" (func $add)))
sql_query.sql
SELECT *
FROM orders
WHERE customer_id IN (
SELECT customer_id
FROM customers
WHERE country = 'USA'
)
matlab.m
function result = times2(n)
result = n * 2;
end

x = 10;
y = times2(x);
latex.tex
\begin{document}
\section{Triangles}
\subsection{Pythagoras' Theorem}
Pythagoras's theorem is:
\begin{equation}
c^2 = a^2 + b^2
\end{equation}
\end{document}
vba.vb
Function Factorial(ByVal n As Long) As Long
If n < 0 Then
Err.Raise 5 ' Invalid argument
End If
Factorial = 1 ' return value
Dim i As Long
For i = 2 To n
Factorial = Factorial * i
Next
End Function
vbnet.vb
Dim languages As New HashSet(Of String) From {
"C#",
"Visual Basic",
"F#",
"PowerShell",
"TypeScript"
}
cmd.bat
@echo off
setlocal
ipconfig
echo Docusaurus is awesome
netstat
fortran.f90
program hello
implicit none
print *, "Hello, World!"
end program hello
cobol.cob
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
PROCEDURE DIVISION.
DISPLAY "Hello, World!".
END PROGRAM HELLO.
fsharp.fsx
[<EntryPoint>]
let main _ =
printfn "Hello, World!"
0

HTML - script + style 標記

參閱 https://github.com/facebook/docusaurus/issues/9517

<html lang="en">
<head>
<script>
const name = 'Formidable';
console.log(name);
</script>
<style>
.some-class {
border: solid red thick;
}
</style>
</head>
</html>

空程式區塊特殊情況

空行內程式區塊:``

單一空白行內程式區塊:

空程式區塊

空 1 行程式區塊

空 2 行程式區塊

空實況程式區塊

實況編輯器

結果
載入中...