而不用斜体斜体字吗

而不用斜体斜体字吗

本文介绍了markdown-我可以在下划线处加下划线,而不用斜体斜体字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在其中带有下划线的文本。

I want to have text that has underscores in it.

这不是代码,所以我不想使用代码格式。

It's not code and so I don't want to use code format.

我想停止降价处理,将其视为斜体显示的指令。

I want to stop markdown treating it as an instruction to italicize it.

我可以逃脱_each_underscore(见!)与 \ 一起使用,但我总共有20个人,从源头上看这很丑陋,难以维护且不太干燥。

I can escape _each_underscore (see!) with \ but I have a total of 20 and that looks ugly in the source, hard to maintain and not very DRY.

还有其他选择吗?

推荐答案

某些Markdown实现–特别是Stack Overflow的服务器端C#版本(其中)和客户端JavaScript版本,例如–出于您所描述的原因而偏离了Markdown规范。

Some Markdown implementations – in particular Stack Overflow's server-side C# version MarkdownSharp (where it's optional behavior) and client-side JavaScript version PageDown, but also e.g. GitHub's flavor – have deviated from the Markdown spec for the very reason you describe.

有关Stack Overflow的历史记录,请参见两篇博客文章和。

For some history on this as far as Stack Overflow goes, see the two blog posts Three Markdown Gotchas and Markdown, One Year Later.

由于这是对降价的普遍批评,因此可能会有更多的实现方式或者让用户可以设置此行为,或者完全使用更严格的版本。因此,这取决于您使用的是什么实现。

Since this is a commonly uttered criticism of Markdown, there are probably more implementations that either make this behavior user-settable, or just go with the stricter version altogether. So it depends on what implementation you're using.

如果您使用的是基于John Gruber原始Perl实现的端口(即大量的regex替换 版本),您应该可以轻松进行此更改。相关函数可能称为 _DoItalicsAndBold (原始Perl版本,Showdown / PageDown), DoItalicsAndBold (MarkdownSharp), _do_italics_and_bold (python-markdown2)或类似版本。

If you're using a port that is based on John Gruber's original Perl implementation (i.e. the "tons of regex replacements" version), it should be fairly easy to make this change yourself. The relevant function is likely called _DoItalicsAndBold (original Perl version, Showdown/PageDown), DoItalicsAndBold (MarkdownSharp), _do_italics_and_bold (python-markdown2) or similar.

请查看我们的用于在堆栈溢出中使用的更严格的正则表达式:

Look at our PageDown version of that function for the stricter regular expressions that are used here on Stack Overflow:

function _DoItalicsAndBold(text) {

    // <strong> must go first:
    text = text.replace(/([\W_]|^)(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\2([\W_]|$)/g,
    "$1<strong>$3</strong>$4");

    text = text.replace(/([\W_]|^)(\*|_)(?=\S)([^\r\*_]*?\S)\2([\W_]|$)/g,
    "$1<em>$3</em>$4");

    return text;
}

这篇关于markdown-我可以在下划线处加下划线,而不用斜体斜体字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 11:42