Markdown 代码块语言声明列表

文章目录

markdown 代码块如何指定语言?有哪些语言可以指定?

在撰写技术文档或分享代码时,使用 Markdown 格式可以极大地提升可读性与简洁性。然而,很多人在编写代码块时,常常会忘记如何正确声明代码的语言名称,这不仅影响格式,还会降低代码展示效果。本文整理了一份常见编程语言的 Markdown 代码块语言声明速查表,并附带常见文件扩展名,帮助你快速选择正确的语言标识。无论你是技术博主、开发者,还是学习者,这份清单都能让你在编写 Markdown 文档时事半功倍。

Markdown 代码块语言声明列表

语言名称Markdown 语言声明常见文件名
1C Enterprise1c-enterprise*.bsl
4D4d*.4dm
ABAPabap*.abap
ABNFabnf*.abnf
AGS Scriptags-script, ags*.asc
AMPLampl*.ampl
ANTLRantlr*.g4
API Blueprintapi-blueprint*.apib
APLapl*.apl
ASN.1asn.1*.asn
ASPasp, aspx, aspx-vb*.asp
ATSats, ats2*.dats
ActionScriptactionscript, actionscript3, as3*.as
Adaada, ada95, ada2005*.adb
Adobe Font Metricsadobe-font-metrics, acfm, amfm*.afm
Agdaagda*.agda
Alloyalloy*.als
Alpine Abuildalpine-abuild, abuild, apkbuildAPKBUILD
Altium Designeraltium-designer, altium*.OutJob
AngelScriptangelscript*.as
Ant Build Systemant-build-systemant.xml
ApacheConfapacheconf, aconf, apache*.apacheconf, .htaccess
Apexapex*.cls
Apollo Guidance Computerapollo-guidance-computer*.agc
AppleScriptapplescript, osascript*.applescript
Arcarc*.arc
AsciiDocasciidoc*.asciidoc
AspectJaspectj*.aj
Assemblyassembly, asm, nasm*.asm
Asymptoteasymptote*.asy
Augeasaugeas*.aug
AutoHotkeyautohotkey, ahk*.ahk
AutoItautoit, au3, AutoIt3, AutoItScript*.au3
Awkawk*.awk
Ballerinaballerina*.bal
Batchfilebatchfile, bat, batch, dosbatch, winbatch*.bat
Befungebefunge*.befunge
BibTeXbibtex*.bib
Bisonbison*.bison
BitBakebitbake*.bb
Bladeblade*.blade
BlitzBasicblitzbasic, b3d, blitz3d, blitzplus, bplus*.bb
BlitzMaxblitzmax, bmax*.bmx
Bluespecbluespec*.bsv
Booboo*.boo
Brainfuckbrainfuck*.b
Brightscriptbrightscript*.brs
Cc*.c
C#c#, csharp*.cs
C++c++, cpp*.cpp
C-ObjDumpc-objdump*.c-objdump
C2hs Haskellc2hs-haskell, c2hs*.chs
CLIPSclips*.clp
CMakecmake*.cmake, CMakeLists.txt
COBOLcobol*.cob
COLLADAcollada*.dae
CSONcson*.cson
CSScss*.css
CSVcsv*.csv
CWebcweb*.w
Cabal Configcabal-config, Cabal*.cabal, cabal.config
Cap’n Protocap’n-proto*.capnp
CartoCSScartocss, Carto*.mss
Ceylonceylon*.ceylon
Chapelchapel, chpl*.chpl
Charitycharity*.ch
ChucKchuck*.ck
Cirrucirru*.cirru
Clarionclarion*.clw
Cleanclean*.icl
Clickclick*.click
Clojureclojure*.clj, riemann.config
Closure Templatesclosure-templates, soy*.soy
Cloud Firestore Security Rulescloud-firestore-security-rulesfirestore.rules
CoNLL-Uconll-u, CoNLL, CoNLL-X*.conllu
CodeQLcodeql, ql*.ql
CoffeeScriptcoffeescript, coffee, coffee-script*.coffee, Cakefile
ColdFusioncoldfusion, cfm, cfml*.cfm
ColdFusion CFCcoldfusion-cfc, cfc*.cfc
Common Lispcommon-lisp, lisp*.lisp
Common Workflow Languagecommon-workflow-language, cwl*.cwl
Component Pascalcomponent-pascal, delphi, objectpascal*.cp
Coolcool*.cl
Coqcoq*.coq
Cpp-ObjDumpcpp-objdump, c++-objdump*.cppobjdump
Creolecreole*.creole
Crystalcrystal*.cr
Csoundcsound, csound-orc*.orc
Csound Documentcsound-document, csound-csd*.csd
Csound Scorecsound-score, csound-sco*.sco
Cudacuda*.cu
Cycriptcycript*.cy
Cythoncython, pyrex*.pyx
Dd*.d
D-ObjDumpd-objdump*.d-objdump
DIGITAL Command Languagedigital-command-language, dcl*.com
DMdm, byond*.dm
DNS Zonedns-zone*.zone
DTracedtrace, dtrace-script*.d
Dafnydafny*.dfy
Darcs Patchdarcs-patch, dpatch*.darcspatch
Dartdart*.dart
DataWeavedataweave*.dwl
Dhalldhall*.dhall
Diffdiff, udiff*.diff
DirectX 3D Filedirectx-3d-file*.x
Dockerfiledockerfile*.dockerfile, Dockerfile
Dogescriptdogescript*.djs
Dylandylan*.dylan
Ee*.E
EBNFebnf*.ebnf
ECLecl*.ecl
ECLiPSeeclipse*.ecl
EJSejs*.ejs
EMLeml*.eml
EQeq*.eq
Eagleeagle*.sch
Easybuildeasybuild*.eb
Ecere Projectsecere-projects*.epj
EditorConfigeditorconfig, editor-config.editorconfig
Edje Data Collectionedje-data-collection*.edc
Eiffeleiffel*.e
Elixirelixir*.ex, mix.lock
Elmelm*.elm
Emacs Lispemacs-lisp, elisp, emacs*.el, .abbrev_defs
EmberScriptemberscript*.em
Erlangerlang*.erl, Emakefile
F#f#, fsharp*.fs
F*f*, fstar*.fst
FIGlet Fontfiglet-font, FIGfont*.flf
FLUXflux*.fx
Factorfactor*.factor, .factor-boot-rc
Fancyfancy*.fy, Fakefile
Fantomfantom*.fan
Faustfaust*.dsp
Filebench WMLfilebench-wml*.f
Filterscriptfilterscript*.fs
Formattedformatted*.for
Forthforth*.fth
Fortranfortran*.f
Fortran Free Formfortran-free-form*.f90
FreeMarkerfreemarker, ftl*.ftl
Fregefrege*.fr
Futharkfuthark*.fut
G-codeg-code*.g
GAMLgaml*.gaml
GAMSgams*.gms
GAPgap*.g
GCC Machine Descriptiongcc-machine-description*.md
GDBgdb*.gdb
GDScriptgdscript*.gd
GEDCOMgedcom*.ged
GLSLglsl*.glsl
GNgn*.gn, .gn
Game Maker Languagegame-maker-language*.gml
Geniegenie*.gs
Genshigenshi, xml+genshi, xml+kid*.kid
Gentoo Ebuildgentoo-ebuild*.ebuild
Gentoo Eclassgentoo-eclass*.eclass
Gerber Imagegerber-image, rs-274x*.gbr
Gettext Cataloggettext-catalog, pot*.po
Gherkingherkin, cucumber*.feature
Git Attributesgit-attributes, gitattributes.gitattributes
Git Configgit-config, gitconfig, gitmodules*.gitconfig, .gitconfig
Glyphglyph*.glf
Glyph Bitmap Distribution Formatglyph-bitmap-distribution-format*.bdf
Gnuplotgnuplot*.gp
Gogo, golang*.go
Gologolo*.golo
Gosugosu*.gs
Gracegrace*.grace
Gradlegradle*.gradle
Grammatical Frameworkgrammatical-framework, gf*.gf
Graph Modeling Languagegraph-modeling-language*.gml
GraphQLgraphql*.graphql
Graphviz (DOT)dot*.dot
Groovygroovy*.groovy, Jenkinsfile
Groovy Server Pagesgroovy-server-pages, gsp*.gsp
HAProxyhaproxy*.cfg, haproxy.cfg
HCLhcl, terraform*.hcl
HLSLhlsl*.hlsl
HTMLhtml, xhtml*.html
HTML+Djangohtml+django, django, html+jinja, htmldjango*.jinja
HTML+ECRhtml+ecr, ecr*.ecr
HTML+EEXhtml+eex, eex*.eex
HTML+ERBhtml+erb, erb*.erb
HTML+PHPhtml+php*.phtml
HTML+Razorhtml+razor, razor*.cshtml
HTTPhttp*.http
HXMLhxml*.hxml
Hackhack*.hack
Hamlhaml*.haml
Handlebarshandlebars, hbs, htmlbars*.handlebars
Harbourharbour*.hb
Haskellhaskell*.hs
Haxehaxe*.hx
HiveQLhiveql*.q
HolyCholyc*.hc
Hyhy, hylang*.hy
HyPhyhyphy*.bf
IDLidl*.pro
IGOR Proigor-pro, igor, igorpro*.ipf
INIini, dosini*.ini, buildozer.spec
IRC logirc-log, irc*.irclog
Idrisidris*.idr
Ignore Listignore-list, ignore, gitignore, git-ignore*.gitignore, .atomignore
Inform 7inform-7, i7, inform7*.ni
Inno Setupinno-setup*.iss
Ioio*.io
Iokeioke*.ik
Isabelleisabelle*.thy
Isabelle ROOTisabelle-rootROOT
Jj*.ijs
JFlexjflex*.flex
JSONjson*.json, .arcconfig
JSON with Commentsjson-with-comments, jsonc*.jsonc, .babelrc
JSON5json5*.json5
JSONLDjsonld*.jsonld
JSONiqjsoniq*.jq
JSXjsx*.jsx
Jasminjasmin*.j
Javajava*.java
Java Propertiesjava-properties*.properties
Java Server Pagesjava-server-pages, jsp*.jsp
JavaScriptjavascript, js, node*.js, Jakefile
JavaScript+ERBjavascript+erb*.js.erb
Jisonjison*.jison
Jison Lexjison-lex*.jisonlex
Joliejolie*.ol
Jsonnetjsonnet*.jsonnet
Juliajulia*.jl
Jupyter Notebookjupyter-notebook*.ipynb, Notebook
KRLkrl*.krl
KiCad Layoutkicad-layout, pcbnew*.kicad_pcb, fp-lib-table
KiCad Legacy Layoutkicad-legacy-layout*.brd
KiCad Schematickicad-schematic*.sch
Kitkit*.kit
Kotlinkotlin*.kt
LFElfe*.lfe
LLVMllvm*.ll
LOLCODElolcode*.lol
LSLlsl*.lsl
LTspice Symbolltspice-symbol*.asy
LabVIEWlabview*.lvproj
Lassolasso, lassoscript*.lasso
Lattelatte*.latte
Leanlean*.lean
Lessless*.less
Lexlex, flex*.l
LilyPondlilypond*.ly
Limbolimbo*.b
Linker Scriptlinker-script*.ld, ld.script
Linux Kernel Modulelinux-kernel-module*.mod
Liquidliquid*.liquid
Literate Agdaliterate-agda*.lagda
Literate CoffeeScriptliterate-coffeescript, litcoffee*.litcoffee
Literate Haskellliterate-haskell, lhaskell, lhs*.lhs
LiveScriptlivescript, live-script, ls*.ls, Slakefile
Logoslogos*.xm
Logtalklogtalk*.lgt
LookMLlookml*.lookml
LoomScriptloomscript*.ls
Lualua*.lua, .luacheckrc
Mm, mumps*.mumps
M4m4*.m4
M4Sugarm4sugar, autoconf*.m4, configure.ac
MATLABmatlab, octave*.matlab
MAXScriptmaxscript*.ms
MLIRmlir*.mlir
MQL4mql4*.mq4
MQL5mql5*.mq5
MTMLmtml*.mtml
MUFmuf*.muf
Macaulay2macaulay2, m2*.m2
Makefilemakefile, bsdmake, make, mf*.mak, BSDmakefile
Makomako*.mako
Markdownmarkdown, pandoc*.md, contents.lr
Markomarko, markojs*.marko
Maskmask*.mask
Mathematicamathematica, mma*.mathematica
Maven POMmaven-pompom.xml
Maxmax, max/msp, maxmsp*.maxpat
MediaWikimediawiki*.mediawiki
Mercurymercury*.m
Mesonmesonmeson.build
Metalmetal*.metal
Microsoft Developer Studio Projectmicrosoft-developer-studio-project*.dsp
MiniDminid*.minid
Mirahmirah*.druby
Modelicamodelica*.mo
Modula-2modula-2*.mod
Modula-3modula-3*.i3
Module Management Systemmodule-management-system*.mms, descrip.mmk
Monkeymonkey*.monkey
Moocodemoocode*.moo
MoonScriptmoonscript*.moon
Motorola 68K Assemblymotorola-68k-assembly, m68k*.asm
Musemuse, amusewiki*.muse
Myghtymyghty*.myt
NASLnasl*.nasl
NCLncl*.ncl
NEONneon, ne-on*.neon
NLnl*.nl
NPM Confignpm-config, npmrc.npmrc
NSISnsis*.nsi
Nearleynearley*.ne
Nemerlenemerle*.n
NetLinxnetlinx*.axs
NetLinx+ERBnetlinx+erb*.axs.erb
NetLogonetlogo*.nlogo
NewLispnewlisp*.nl
Nextflownextflow*.nf, nextflow.config
Nginxnginx*.nginxconf, nginx.conf
Nimnim*.nim, nim.cfg
Ninjaninja*.ninja
Nitnit*.nit
Nixnix, nixos*.nix
Nunu, nush*.nu, Nukefile
NumPynumpy*.numpy
OCamlocaml*.ml
ObjDumpobjdump*.objdump
Object Data Instance Notationobject-data-instance-notation*.odin
ObjectScriptobjectscript*.cls
Objective-Cobjective-c, obj-c, objc, objectivec*.m
Objective-C++objective-c++, obj-c++, objc++, objectivec++*.mm
Objective-Jobjective-j, obj-j, objectivej, objj*.j
Odinodin, odinlang, odin-lang*.odin
Omgroflomgrofl*.omgrofl
Opaopa*.opa
Opalopal*.opal
Open Policy Agentopen-policy-agent*.rego
OpenCLopencl*.cl
OpenEdge ABLopenedge-abl, progress, openedge, abl*.p
OpenQASMopenqasm*.qasm
OpenRC runscriptopenrc-runscript, openrc
OpenSCADopenscad*.scad
OpenStep Property Listopenstep-property-list*.plist
OpenType Feature Fileopentype-feature-file, AFDKO*.fea
Orgorg*.org
Oxox*.ox
Oxygeneoxygene*.oxygene
Ozoz*.oz
P4p4*.p4
PHPphp, inc*.php, .php
PLSQLplsql*.pls
PLpgSQLplpgsql*.pgsql
POV-Ray SDLpov-ray-sdl, pov-ray, povray*.pov
Panpan*.pan
Papyruspapyrus*.psc
Parrotparrot*.parrot
Parrot Assemblyparrot-assembly, pasm*.pasm
Parrot Internal Representationparrot-internal-representation, pir*.pir
Pascalpascal*.pas
Pawnpawn*.pwn
Pep8pep8*.pep
Perlperl, cperl*.pl, Makefile.PL
Picpic*.pic
Picklepickle*.pkl
PicoLisppicolisp*.l
PigLatinpiglatin*.pig
Pikepike*.pike
PlantUMLplantuml*.puml
Podpod*.pod
Pod 6pod-6*.pod
PogoScriptpogoscript*.pogo
Ponypony*.pony
PostCSSpostcss*.pcss
PostScriptpostscript, postscr*.ps
PowerBuilderpowerbuilder*.pbt
PowerShellpowershell, posh, pwsh*.ps1
Prismaprisma*.prisma
Processingprocessing*.pde
Proguardproguard*.pro
Prologprolog*.pl
Propeller Spinpropeller-spin*.spin
Protocol Bufferprotocol-buffer, protobuf*.proto
Public Keypublic-key*.asc
Pugpug*.jade
Puppetpuppet*.pp, Modulefile
Pure Datapure-data*.pd
PureBasicpurebasic*.pb
PureScriptpurescript*.purs
Pythonpython, python3, rusthon*.py, .gclient
Python consolepython-console, pycon
Python tracebackpython-traceback*.pytb
QMLqml*.qml
QMakeqmake*.pro
Quakequakem3makefile
Rr, R, Rscript, splus*.r, .Rprofile
RAMLraml*.raml
RDocrdoc*.rdoc
REALbasicrealbasic*.rbbas
REXXrexx, arexx*.rexx
RHTMLrhtml, html+ruby*.rhtml
RMarkdownrmarkdown*.rmd
RPCrpc, rpcgen, oncrpc, xdr*.x
RPM Specrpm-spec, specfile*.spec
RUNOFFrunoff*.rnh
Racketracket*.rkt
Ragelragel, ragel-rb, ragel-ruby*.rl
Rakuraku, perl6, perl-6*.6pl
Rascalrascal*.rsc
Raw token dataraw-token-data, raw*.raw
Readline Configreadline-config, inputrc, readline.inputrc
Reasonreason*.re
Rebolrebol*.reb
Redred, red/system*.red
Redcoderedcode*.cw
Regular Expressionregular-expression, regexp, regex*.regexp
Ren’Pyren’py, renpy*.rpy
RenderScriptrenderscript*.rs
Rich Text Formatrich-text-format*.rtf
Ringring*.ring
Riotriot*.riot
RobotFrameworkrobotframework*.robot
Roffroff, groff, mdoc, nroff, troff*.roff, eqnrc
Roff Manpageroff-manpage*.1
Rougerouge*.rg
Rubyruby, jruby, macruby, rake, rb, rbx*.rb, .irbrc
Rustrust*.rs
SASsas*.sas
SCSSscss*.scss
SMTsmt*.smt2
SPARQLsparql*.sparql
SQFsqf*.sqf
SQLsql*.sql
SQLPLsqlpl*.sql
SRecode Templatesrecode-template*.srt
SSH Configssh-configssh-config
STONston*.ston
SVGsvg*.svg
SWIGswig*.i
Sagesage*.sage
SaltStacksaltstack, saltstate, salt*.sls
Sasssass*.sass
Scalascala*.scala
Scamlscaml*.scaml
Schemescheme*.scm
Scilabscilab*.sci
Selfself*.self
ShaderLabshaderlab*.shader
Shellshell, sh, shell-script, bash, zsh*.sh, .bash_aliases
ShellSessionshellsession, console*.sh-session
Shenshen*.shen
Sievesieve*.sieve
Slashslash*.sl
Sliceslice*.ice
Slimslim*.slim
SmPLsmpl, coccinelle*.cocci
Smalismali*.smali
Smalltalksmalltalk, squeak*.st
Smartysmarty*.tpl
Soliditysolidity
SourcePawnsourcepawn, sourcemod*.sp
Spline Font Databasespline-font-database*.sfd
Squirrelsquirrel*.nut
Stanstan*.stan
Standard MLstandard-ml, sml*.ML
Starlarkstarlark, bazel, bzl*.bzl, BUCK
Statastata*.do
Stylusstylus*.styl
SubRip Textsubrip-text*.srt
SugarSSsugarss*.sss
SuperCollidersupercollider*.sc
Sveltesvelte*.svelte
Swiftswift*.swift
SystemVerilogsystemverilog*.sv
TI Programti-program*.8xp
TLAtla*.tla
TOMLtoml*.toml, Cargo.lock
TSQLtsql*.sql
TSXtsx*.tsx
TXLtxl*.txl
Tcltcl*.tcl, owh
Tcshtcsh*.tcsh
TeXtex, latex*.tex
Teatea*.tea
Terraterra*.t
Texinfotexinfo*.texinfo
Texttext, fundamental*.txt, COPYING
Textiletextile*.textile
Thriftthrift*.thrift
Turingturing*.t
Turtleturtle*.ttl
Twigtwig*.twig
Type Languagetype-language, tl*.tl
TypeScripttypescript, ts*.ts
Unified Parallel Cunified-parallel-c*.upc
Unity3D Assetunity3d-asset*.anim
Unix Assemblyunix-assembly*.s
Unouno*.uno
UnrealScriptunrealscript*.uc
UrWeburweb, Ur/Web, Ur*.ur
Vv, vlang*.v
VBAvba, vb6*.bas
VBScriptvbscript*.vbs
VCLvcl*.vcl
VHDLvhdl*.vhdl
Valavala*.vala
Verilogverilog*.v
Vim Snippetvim-snippet, SnipMate, UltiSnip, NeoSnippet*.snip
Vim scriptvim-script, vim, viml, nvim*.vim, .gvimrc
Visual Basic .NETvbnet, vb.net*.vb
Voltvolt*.volt
Vuevue*.vue
Wavefront Materialwavefront-material*.mtl
Wavefront Objectwavefront-object*.obj
Web Ontology Languageweb-ontology-language*.owl
WebAssemblywebassembly, wast, wasm*.wast
WebIDLwebidl*.webidl
WebVTTwebvtt*.vtt
Wget Configwget-config, wgetrc.wgetrc
Windows Registry Entrieswindows-registry-entries*.reg
Wollokwollok*.wlk
World of Warcraft Addon Dataworld-of-warcraft-addon-data*.toc
X BitMapx-bitmap, xbm*.xbm
X Font Directory Indexx-font-directory-indexencodings.dir
X PixMapx-pixmap, xpm*.xpm
X10x10, xten*.x10
XCxc*.xc
XComposexcompose.XCompose
XMLxml, rss, xsd, wsdl*.xml, .classpath
XML Property Listxml-property-list*.plist
XPagesxpages*.xsp-config
XProcxproc*.xpl
XQueryxquery*.xquery
XSxs*.xs
XSLTxslt, xsl*.xslt
Xojoxojo*.xojo_code
Xtendxtend*.xtend
YAMLyaml, yml*.yml, .clang-format
YANGyang*.yang
YARAyara*.yar
YASnippetyasnippet, snippet, yas*.yasnippet
Yaccyacc*.y
ZAPzap*.zap
ZILzil*.zil
Zeekzeek, bro*.zeek
ZenScriptzenscript*.zs
Zephirzephir*.zep
Zigzig*.zig
Zimplzimpl*.zimpl
cURL Configcurl-config, curlrc.curlrc
desktopdesktop*.desktop
dircolorsdircolors*.dircolors, .dir_colors
eCec*.ec
ednedn*.edn
fishfish*.fish
mIRC Scriptmirc-script*.mrc
mcfunctionmcfunction*.mcfunction
mupadmupad*.mu
nanorcnanorc*.nanorc, .nanorc
nesCnesc*.nc
oocooc*.ooc
qq*.q
reStructuredTextrestructuredtext, rst*.rst
sedsed*.sed
wdlwdl*.wdl
wispwisp*.wisp
xBasexbase, advpl, clipper, foxpro*.prg

FAQ

1. 如何在 Markdown 中指定代码块的语言? 在 Markdown 中,代码块使用三个反引号 (```) 包围代码内容,并在第一行的反引号后加上所使用的编程语言。例如: ```python print(“Hello, World!”) ```

2. Markdown 代码块如何指定语言声明? 在编写代码块时,只需在代码块的开头声明语言名称,例如 ```python、```javascript 来指定 Python 或 JavaScript 代码,帮助实现语法高亮。

3. Markdown 代码块如何设置样式? Markdown 代码块样式主要依赖于渲染引擎。不同的平台可能对代码块进行不同的样式处理,如语法高亮、背景颜色、缩进等。你可以使用 CSS 自定义代码块样式。

4. Markdown 代码块支持哪些编程语言? Markdown 支持多种编程语言,包括但不限于:Python、JavaScript、HTML、CSS、C++、Shell 等。你可以在代码块开头声明你需要的语言,如 ```python。

5. Markdown 代码块如何显示行号? Markdown 原生不支持行号显示功能,但可以通过一些插件或自定义 CSS 来实现。比如使用一些渲染工具(如 highlight.js)来添加行号功能。

6. Markdown 代码块如何折叠? Markdown 本身不支持代码块折叠功能,但可以通过一些第三方插件或工具(如 Typora、Hexo 等)为代码块添加折叠功能。

7. Markdown 代码块缩进如何设置? Markdown 代码块缩进可以通过两个方式设置:使用 4 个空格或 1 个制表符(Tab 键)来缩进每一行代码。

8. Markdown 代码块如何高亮代码? Markdown 中的代码高亮功能依赖于语法解析器或渲染引擎。通过在代码块声明语言,如 ```python,就可以为该语言代码块进行语法高亮。

9. 如何在 Markdown 代码块中添加滚动条? 如果代码块内容较长,可通过 CSS 设置 overflow: auto; 来实现滚动条显示,使代码块在页面中不占用太多空间。

10. 如何在 Markdown 代码块中显示 Shell 终端效果? 在代码块中声明 ```shell 或 ```bash 来编写 Shell 脚本的代码,从而显示 Shell 终端效果。

11. Markdown 代码块如何自动换行? Markdown 默认不处理代码块的自动换行。可以通过自定义 CSS 样式来添加 white-space: pre-wrap; 属性,使代码块自动换行。

12. 如何在 Markdown 代码块中显示 C++ 代码? 在代码块的开头声明 ```cpp 或 ```c++ 来指明代码块中的语言是 C++,这样会对 C++ 代码进行适当的语法高亮。

13. Markdown 代码块如何换行? 要在 Markdown 代码块中换行,可以直接按 Enter 键或使用 \n 转义字符来表示换行。

14. Markdown 代码块是否支持中文符号? Markdown 代码块是支持中文符号的。不过需要注意的是,某些语言解析器可能对中文符号处理不当,因此测试结果可能因平台而异。

15. 如何在 Markdown 中创建一个可以显示终端输出的代码块? 使用 ```shell 或 ```bash 来创建一个代码块,该代码块将模拟显示终端的输出样式,适用于编写 Shell 脚本示例。

16. Markdown 代码块如何加粗? Markdown 中的加粗使用两个星号(**)或两个下划线(__)包围文本来实现。但在代码块中不支持加粗,所有内容将以纯文本形式显示。

17. Markdown 代码块如何打 * ? 如果要在代码块中显示星号(*),直接输入即可,因为代码块内的内容不会被解析成 Markdown 样式,所有内容都将按原样显示。

18. 如何在 Markdown 中显示代码块的代码块? 为了在 Markdown 代码块中显示代码块,可以使用转义字符或在代码块内嵌套反引号(`)。

19. 如何为 Markdown 代码块添加终端效果? 你可以通过在代码块声明 ```shell 或 ```bash 来模拟终端效果,显示 Shell 脚本的代码和输出。

20. Markdown 代码块支持自动语法高亮吗? 支持自动语法高亮,前提是你必须在代码块的开头正确声明所使用的编程语言,如 ```python 或 ```javascript。

小结

通过掌握 Markdown 代码块的语言声明格式,编写技术文档和代码示例将变得更加流畅和高效。这份速查表覆盖了多种主流编程语言及其常见文件扩展名,让你在使用 Markdown 编写文档时,轻松查找需要的代码块语言声明。如果你想提升自己的文档编写效率,建议将这份清单收藏起来,随时使用,助你更快速地处理代码格式问题。


也可以看看