如何使用 Marked.js 存储使用三引号反引号字符串
我使用 Marked.js 来呈现我们想要存储的代码(最终作为 JSON)。但是,我无法获得三重反勾约定来正确渲染。我确信我的用户错误,但我如何才能让以下内容正常工作?
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<div id="content"></div>
<script>
let str = marked.parse("here is the body of arguments ```\n\nclass User\n def say_my_name\n puts 'my name'\n end\nend```");
document.getElementById('content').innerHTML = str;
</script>
它为我呈现如下:
I'm using marked.js to render code that we want to store (ultimately as JSON). However, the I can't get triple-back-ticked convention to render correctly. I'm sure user error on my part but how would I to get the following to work?
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<div id="content"></div>
<script>
let str = marked.parse("here is the body of arguments ```\n\nclass User\n def say_my_name\n puts 'my name'\n end\nend```");
document.getElementById('content').innerHTML = str;
</script>
which renders for me like:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你拥有的是
但这是无效的。代码围栏应始终位于新行:
What you have is
But that is not valid. The code fences should always be on a new line:
你的换行符在前三个反引号周围混合在一起:
看看现在是等宽字体了吗?
You've got the newlines mixed up around the first trio of backticks:
See how it's monospace now?