问题描述
我已经用尽了我的研究,尝试了许多无效的方法,希望我能忽略某种简单的解决方案:
I have exhausted my research and tried many methods to no effect and am hoping I'm overlooking some kind of simple solution:
我正在使用Jekyll网站生成用于电子邮件的HTML文件,并且需要对特殊字符(例如破折号和智能引号)使用HTML实体,以避免符号解释不正确(内容类型/字符集)由于复杂性,有时会从电子邮件头中剥离出来.)
I am using a Jekyll site to produce HTML files for e-mail and need to use HTML entities for special characters (such as em-dashes and smart quotes) in order to avoid improper symbol interpretation (the content-type/charset is at times stripped out of the e-mail head due to complexities I won't get into here.)
我的问题是当解析为HTML输出时,解析我的Markdown似乎会将所有书面的HTML实体转换为特殊字符,而我无法使用通用方法进行转义.当我在markdown中键入’
以产生正确的卷曲引号时,它会转换为HTML中的’
符号(而不是在HTML中保留’
).如果我尝试使用反引号将其转义,它将不会在HTML中转换&rsquo
,但是会将其放置在标记内,这会导致它呈现为’
而不是’
.有没有一种方法可以保留键入的HTML实体以保留特殊字符,或者甚至可以更好地在解析时将特殊字符转换为HTML实体(在HTML中)?
My problem is that parsing my Markdown appears to convert all of my written HTML entities into the special characters when output as HTML, and I am unable to escape with common methods. When I type ’
into markdown to produce a right curly quote it is converted to the ’
symbol within my HTML (instead of retaining ’
in my HTML). If I try to escape it with back-ticks it will not convert &rsquo
in the HTML but it places it within <code>
tags which cause it to render as ’
and not ’
. Is there a way to retain typed-out HTML entities for special characters or -- even better -- convert special characters into to HTML entities (in the HTML) when parsed?
我正在与Jekyll一起使用Kramdown markdown解析器.我什至在将Kramdown中的entity_output
选项指定为: as_input
时都没有成功.任何帮助深表感谢!
I am using the Kramdown markdown parser with Jekyll. I have even gone as far as specifying the entity_output
option in Kramdown to : as_input
without success. Any help is much appreciated!
推荐答案
文档状态如下:
--entity-output ARG
Defines how entities are output
The possible values are :as_input (entities are output in the same
form as found in the input), :numeric (entities are output in numeric
form), :symbolic (entities are output in symbolic form if possible) or
:as_char (entities are output as characters if possible, only available
on Ruby 1.9).
Default: :as_char
Used by: HTML converter, kramdown converter
因此,让我们尝试以下选项:
So lets try those options:
$ kramdown --version
1.11.1
$ kramdown
‘foo’
<p>‘foo’</p>
$ kramdown --entity-output=as_input
‘foo’
<p>‘foo’</p>
$ kramdown --entity-output=symbolic
‘foo’
<p>‘foo’</p>
$ kramdown --entity-output=numeric
‘foo’
<p>‘foo’</p>
$ kramdown --entity-output=as_char
‘foo’
<p>‘foo’</p>
$ ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
请注意,我拥有Kramdown 1.11版和Ruby 1.9版.如果您使用的是较早版本,则可能无法正常工作.
Notice that I have Kramdown version 1.11 and Ruby version 1.9. if you have earlier versions, then things may not work properly.
这篇关于解析Markdown时保留HTML实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!