我一直在学习 github markdown,我有一个关于变量和宏的问题。
是否可以定义变量或宏来防止重复打印文本块?
用例是我有一个表格,生成一个大的超链接网格 - 链接如下所示。
http://www.a-big-long-big-big-long-hyperlink/more-long-stuff?id=1234
如果我能做一次类似下面的事情那就太好了:
$link=http://www.a-big-long-big-big-long-hyperlink/more-long-stuff?id
然后在表格中的每个单元格中,我可以说类似的话
$link=1234
其他一些细胞
$link=2345
想法是:
干杯。
以下是编写参考链接的几种方法
[I'm an inline-style link](https://www.somewebsite.com)
[I'm an inline-style link with title](https://www.somewebsite.com "somewebsite's Homepage")
[I'm a reference-style link][Arbitrary case-insensitive reference text]
[I'm a relative reference to a repository file](../blob/master/LICENSE)
[You can use numbers for reference-style link definitions][1]
Or leave it empty and use the [link text itself]
Some text to show that the reference links can follow later.
[arbitrary case-insensitive reference text]: https://www.somewebsite.org
[1]: http://somewebsite.org
[link text itself]: http://www.somewebsite.com
您可以使用 Markdown 的一项称为“参考样式链接”的功能。
如果链接文本是唯一的并且仅由字母、数字、空格和标点符号组成,则为[link text][id]
或仅 [link text]
。它们不区分大小写。
然后在文档中的某处您定义什么是
id
:
[id]: http://example.com/whatever
见 https://github.com/biserkov/markdown-playground/blob/master/README.md和
https://raw.githubusercontent.com/biserkov/markdown-playground/master/README.md
这在基本 Markdown 中是不可能的,但有一些扩展可以添加宏和变量。 (示例。)
如果您仅使用 Markdown 语法而不使用括号,则可以使用括号来执行此操作
html
首先,创建变量:
[foo]: https://example1.com
[bar]: https://example2.com
然后使用括号中的名称访问变量:
I am the first [variable][foo]
它甚至可以在 StackOverflow 上运行。
我是第二个变量
GitHub Markdown(对于 .md 文件)通过
capture
有变量:
{% capture nameOfVariableToCapture %}any markdown here...{% endcapture %}
{{ nameOfVariableToCapture }} -- that prints the content of the variable
或来自
{% assign variableName = "text etc." %}
。
作为测试,我创建了 https://github.com/SeLite/SeLite.github.io/blob/master/MarkdownTest.md。您可以在 http://selite.github.io/MarkdownTest 查看其内容(忽略来自框架的页眉和页脚)。