如何为内置的markdown标签应用样式? [英] How to apply style for the inbuilt markdown tags?

查看:260
本文介绍了如何为内置的markdown标签应用样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习reactjs,并且试图创建一个文本编辑器,在该文本编辑器中我想对根据开始和结束索引选择的文本进行缩进.

I am learning reactjs and I am trying to create a text editor where I want to do indentation for the text which is selected based on the start and end index.

我可以获取所选的文本,并且我可以使用带标记的包来应用粗体,斜体,例如**表示粗体,_表示斜体等,但是我不能应用text-decoration表示标记的标签.

I can get the selected text, and I can apply bold, italic using marked package like ** for bold and _ for italic, etc, but I cannot apply styles like text-align, text-decoration for the marked tags.

如何为标记的标签应用样式?还有其他方法吗?

How can I apply styles for the marked tags? Is there any other way to do this?

推荐答案

您将需要定义CSS规则以对生成的HTML进行样式设置.如果您希望样式仅应用于单个段落(或段落的子集),则可能需要在Markdown中使用原始HTML来在段落上定义类,或者至少定义内联样式.

You would need to define CSS rules to style the generated HTML. If you want a style to apply only to a single paragraph (or a subset of paragraphs), then you may need to use raw HTML in your Markdown to define a class on the paragraph or at least define an inline style.

作为原始的语法规则状态(添加了强调):

As the original syntax rules state (emphasis added):

Markdown的语法仅用于一个目的:用作网络写作的格式.

Markdown’s syntax is intended for one purpose: to be used as a format for writing for the web.

Markdown不能替代HTML,甚至不能替代HTML.它的语法非常小,仅对应于很小的HTML标签子集.这个想法不是要创建一种使插入HTML标记更容易的语法.我认为HTML标记已经很容易插入. Markdown的想法是使其易于阅读,编写和编辑散文. HTML是一种发布格式; Markdown是一种书写格式.因此, Markdown的格式语法仅解决可以以纯文本格式传达的问题 .

Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text.

对于Markdown语法未涵盖的任何标记,只需使用HTML本身即可.

For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.

由于Markdown不是发布格式",因此Markdown无法提供一种样式/布局文本的方式.也就是说,您可以包括原始HTML(并且HTML是一种发布格式),这并非没有可能.例如,以下原始HTML将缩进一个段落:

As Markdown is not a "publishing format," providing a way to style/layout your text is out-of-scope for Markdown. That said, it is not impossible as you can include raw HTML (and HTML is a publishing format). For example, the following raw HTML will indent a paragraph:

<p style="padding-left:4em">A paragraph which is indented.<p>

或者,如果您在CSS中定义了某些样式:

Or, if you have some styles defined in CSS:

.indent {
    padding-left: 4em;
}

然后,您可以使用原始HTML将该类分配给段落:

Then you could use raw HTML to assign that class to a paragraph:

<p class="indent">A paragraph which is indented.<p>

以这种方式进行操作的不利之处在于,按照规则,Markdown文本不会在块级原始HTML标记内进行处理.这意味着您的链接以及粗体和斜体文本也需要使用原始HTML进行格式化.

The downside of doing it this way is that, as per the rules, Markdown text is not processed inside block-level raw HTML tags. Which means your links and bold and italic text will also need to be formatted with raw HTML.

另一种可能性是使用最初由 Markuru 引入的非标准属性列表. > Markdown的实施,后来被 a

Another possibility is to use the non-standard Attribute Lists originally introduced by the Markuru implementation of Markdown and later adopted by a few others (there may be more, but I'm only aware of these four). In that case, you could assign a class to a Markdown paragraph (avoiding the need for raw HTML) and then use CSS to define a layout for the class. However, you absolutely must be using one of the few implementations which actually support the non-standard feature and your documents are no longer portable to other systems.

这篇关于如何为内置的markdown标签应用样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆