访问:0点赞:0评论:0

GitHub Markdown 语法全集测试

测试代码块

function test() {
  return 'hello world'
}
lsof -i 3000
kill -9 pid
// --- Demonstration of imports ---
 
// Importing named exports and the default export
import defaultAnimal, { person, add } from './module.js';
 
// Importing everything from the module as an alias
import * as Module from './module.js';
 
 
// --- Demonstration of exports ---
 
// Named exports
export const person = { name: "Alice", age: 30 };
 
export function add(x, y = 0) {
  return x + y;
}
 
// Default export
const defaultAnimal = { name: "Default Animal" };
export default defaultAnimal;
 
// Generator function
export function* idGenerator() {
  let id = 0;
  while (true) {
    yield id++;
  }
}
 
// Using typeof for runtime type checks
console.log(typeof person);  // object
console.log(add(2, 3));      // 5
console.log(defaultAnimal);  // { name: "Default Animal" }
 
// Emulating 'satisfies' behavior using runtime checks
function createAnimal(animal) {
  if (typeof animal.name === 'string') {
    return animal;  // Ensures the animal has a 'name' property
  }
  throw new Error("Animal must have a name");
}
 
const dog = createAnimal({ name: "Buddy", breed: "Golden Retriever" });
console.log(dog);  // { name: 'Buddy', breed: 'Golden Retriever' }
 
// Generator usage
const generator = Module.idGenerator();
console.log(generator.next().value);  // 0
console.log(generator.next().value);  // 1
console.log(generator.next().value);  // 2
 
// Handling a generic-like behavior by allowing any type and runtime checks
function identity(arg) {
  return arg;
}
 
let str = identity("Hello");
let num = identity(42);
console.log(str, num);  // "Hello", 42
 
// Emulating default generics by using default parameters
function wrapInArray(value = "") {
  return [value];
}
 
const stringArray = wrapInArray();  // Default is empty string
const numberArray = wrapInArray(42);  // Passes 42 explicitly
console.log(stringArray, numberArray);  // [""] , [42]
 
// --- for-of and for-in loops ---
 
// for-of: Iterates over iterable objects like arrays, strings, maps, etc.
const fruits = ["apple", "banana", "cherry"];
for (const fruit of fruits) {
  console.log(fruit);  // Outputs: apple, banana, cherry
}
 
// for-in: Iterates over enumerable properties of an object
const car = { make: "Tesla", model: "Model S", year: 2021 };
for (const key in car) {
  if (car.hasOwnProperty(key)) {
    console.log(`${key}: ${car[key]}`);  // Outputs key-value pairs of car object
  }
}
 
// --- IIFE (Immediately Invoked Function Expression) ---
 
(function () {
  console.log("This IIFE runs immediately after it's defined.");
  const privateVar = "I'm private inside the IIFE!";
  console.log(privateVar);  // Accessing the private variable inside the IIFE
})();
 
// --- Using a generator to loop indefinitely ---
function* infiniteGenerator() {
  let i = 0;
  while (true) {
    yield i++;
  }
}
 
const gen = infiniteGenerator();
console.log(gen.next().value);  // 0
console.log(gen.next().value);  // 1
 
// --- Async and Await ---
 
async function fetchData(url) {
  try {
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }
    const data = await response.json();
    return data;
  } catch (error) {
    console.error('There has been a problem with your fetch operation:', error);
  }
}
 
// Example usage of async function
fetchData('https://jsonplaceholder.typicode.com/todos/1')
  .then(data => console.log(data))  // Outputs fetched data
  .catch(error => console.error(error));
 
// JSDoc type annotations
/**
 * @typedef {Object} Task
 * @property {string} title
 * @property {boolean} completed
 */
 
/**
 * Create a task
 * @param {Task} task
 * @returns {Task}
 */
function createTask(task) {
  return task;
}
 
const myTask = createTask({
  title: "Learn JavaScript",
  completed: false,
});
console.log(myTask);
 
// Importing everything as a namespace (simulated for demonstration)
console.log(Module.person);  // { name: "Alice", age: 30 }
console.log(Module.add(10, 20));  // 30

1. 标题

# H1
## H2
### H3
#### H4
##### H5
###### H6

2. 文本样式

粗体 斜体 删除线 行内代码 ==高亮== (部分GFM扩展支持)

3. 列表

无序列表

  • 项目1
  • 项目2
    • 子项目2.1
    • 子项目2.2

有序列表

  1. 第一项
  2. 第二项
    1. 子项2.1
    2. 子项2.2

任务列表

  • 完成Markdown测试
  • 添加更多示例
  • 检查渲染效果

4. 链接和图片

GitHub官网

Test image 1 Test image 2 Test image 3

5. 代码块

行内代码

使用 console.log('Hello') 打印消息

代码块

function hello() {
  console.log('Hello, GitHub Markdown!');
}

6. 表格

语法描述示例
标题表格标题示例1
文本普通文本示例2
强调加粗文本示例3

7. 引用

这是引用的内容 可以多行使用

嵌套引用

8. 分隔线


或者


9. 内联HTML

点击展开详情
这是被折叠的内容

10. 脚注

这是一个脚注示例1

11. 表情符号

😄 👍 ❤️ 🚀

12. 特殊语法

自动链接

https://github.com

用户名提及

@github-user

议题引用

#123

忽略Markdown语法

使用反斜杠转义:*不会变成斜体*

特殊blockquote

TIP

Optional information to help a user be more successful. For example, try clicking the close button on the right.

⚠️ Important Warning

Critical content demanding immediate user attention due to potential risks. Please follow the instructions carefully to avoid issues.

IMPORTANT

This is an important reminder. Make sure to save your work frequently to prevent data loss.

NOTE

Highlights information that users should take into account, even when skimming. This is the default note type.

CAUTION

Negative potential consequences of an action. Please be cautious when performing this operation.

Footnotes

  1. 这里是脚注的内容

© 2025知秋

网站已运行RSS网站地图统计

次访问