- MathJax是什么
- MathJax AsciiMath Support
- 入门指南
- MathJax Output Formats
- Loading MathJax Dynamically
- 安装和测试MathJax
- The MathJax Community
- Modifying Math on the Page
- 加载和配置MathJax
- What’s New in MathJax v2.0
- MathJax API
- Common Configurations
- What’s New in MathJax v1.1
- Describing HTML snippets
- Configuration Objects
- Migrating from MathJax v1.0 to v1.1
- CSS Style Objects
- Using MathJax in popular web platforms
- Converting to MathJax from jsMath
- Glossary
- MathJax TeX and LaTeX Support
- The MathJax Processing Model
- MathJax MathML Support
- The MathJax Startup Sequence
- Synchronizing your code with MathJax
Describing HTML snippets
A number of MathJax configuration options allow you to specify an HTML snippet using a JavaScript object. This lets you include HTML in your configuration files even though they are not HTML files themselves. The format is fairly simple, but flexible enough to let you represent complicated HTML trees.
An HTML snippet is an array consisting of a series of elements that format the HTML tree. Those elements are one of two things: either a string, which represents text to be included in the snippet, or an array, which represents an HTML tag to be included. In the latter case, the array consists of three items: a string that is the tag name (e.g., “img”), an optional object that gives attributes for the tag (as described below), and an optional HTML snippet array that gives the contents of the tag.
When attributes are provided, they are given as name:value pairs, with the name giving the attribute name, and value giving its value. For example
[["img",{src:"/images/mypic.jpg"}]]
represents an HTML snippet that includes one element: an <img> tag with src set to /images/mypic.jpg. That is, this is equivalent to
<img src="/images/mypic.jpg">
Note that the snippet has two sets of square brackets. The outermost one is for the array that holds the snippet, and the innermost set is because the first (and only) element in the snippet is a tag, not text. Note that the code ["img",{src:"/images/mypic.jpg"}] is invalid as an HTML snippet. It would represent a snippet that starts with “img” as text in the snippet (not a tag), but the second item is neither a string nor an array, and so is illegal. This is a common mistake that should be avoided.
A more complex example is the following:
[ "Please read the ", ["a",{href:"instructions.html"},["instructions"]], " carefully before proceeding" ]
which is equivalent to
please read the <a href="instructions.html">instructions</a> carefully before proceeding.
A final example shows how to set style attributes on an object:
[["span", { id:"mySpan", style: {color:"red", "font-weight":"bold"} }, [" This is bold text shown in red "] ]]
which is equivalent to
<span id="mySpan" style="color: red; font-weight: bold;"> This is bold text shown in red </span>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论