gpt4 book ai didi

escaping - GNU m4 : escaping backticks (`)

转载 作者:行者123 更新时间:2023-12-04 14:43:32 25 4
gpt4 key购买 nike

一个简单的GNU m4问题,但是我找不到正确的答案。我想在代码部分的开始/结束处打印一个markdown header :

```
echo Hello
```

如何创建包含3个反引号的GNU M4宏?就像是
define(`md_code',````')
md_code
echo Hello
md_code

最佳答案

在M4邮件列表上得到了Eric Blake的答复:http://lists.gnu.org/archive/html/m4-discuss/2015-04/msg00004.html

changequote is your friend. This will do it:


define(`md_code', changequote([, 
])[changequote([,])```changequote(`,')]changequote(`,'))

I have to change quotes twice: once around the macro definition, since the definition itself intends to use (backticks) in an unbalanced manner; and again in the macro expansion, since the expansion will output backticks in an unbalanced manner; for each changed quote, the original quotes must be restored. This assumes that the default quoting stays at (backticks) ' throughout the m4 run.

Although in your case, I'd recommend using changequote up front to something else, and globally write your input under those quoting rules instead of the default (backticks) ' quoting rules. Remember that autoconf intentionally went with [ ] as the quoting characters, because they were much likely to be balanced in output, as opposed to (backticks) and ' not occurring in balanced pairs in shell scripts. In fact, choosing 2- or 3-byte quoting strings is even less ambiguous, although it then requires more typing.

关于escaping - GNU m4 : escaping backticks (`),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29522699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com