Markdown을 사용하여 단락에 클래스 이름을 정의 할 수 있습니까?
Markdown을 사용하여 단락에 클래스 이름을 정의 할 수 있습니까? 그렇다면 어떻게?
Dupe : Markdown에서 HTML 클래스 속성을 어떻게 설정합니까?
기본적으로? 아뇨하지만 ...
아니요, Markdown의 구문은 사용할 수 없습니다. Markdown Extra를 통해 ID 값 을 설정할 수 있습니다 .
원하는 경우 일반 HTML을 사용 하고 속성 markdown="1"
을 추가 하여 HTML 요소 내에서 마크 다운 변환을 계속할 수 있습니다. 그래도 Markdown Extra 가 필요합니다 .
<p class='specialParagraph' markdown='1'>
**Another paragraph** which allows *Markdown* within it.
</p>
가능한 해결책 : (테스트되지 않았으며 대상 <blockquote>
)
온라인에서 다음을 발견했습니다.
함수
function _DoBlockQuotes_callback($matches) {
...cut...
//add id and class details...
$id = $class = '';
if(preg_match_all('/\{(?:([#.][-_:a-zA-Z0-9 ]+)+)\}/',$bq,$matches)) {
foreach ($matches[1] as $match) {
if($match[0]=='#') $type = 'id';
else $type = 'class';
${$type} = ' '.$type.'="'.trim($match,'.# ').'"';
}
foreach ($matches[0] as $match) {
$bq = str_replace($match,'',$bq);
}
}
return _HashBlock(
"<blockquote{$id}{$class}>\n$bq\n</blockquote>"
) . "\n\n";
}
가격 인하
>{.className}{#id}This is the blockquote
결과
<blockquote id="id" class="className">
<p>This is the blockquote</p>
</blockquote>
원시 HTML은 실제로 마크 다운에서 완벽하게 유효합니다. 예를 들어 :
Normal *markdown* paragraph.
<p class="myclass">This paragraph has a class "myclass"</p>
HTML이 코드 블록 안에 있지 않은지 확인하십시오.
Markdown should have this capability, but it doesn't. Instead, you're stuck with language-specific Markdown supersets:
PHP: Markdown Extra
Ruby: Kramdown, Maruku
But if you need to abide by true Markdown syntax, you're stuck with inserting raw HTML, which is less ideal.
If your environment is JavaScript, use markdown-it along with the plugin markdown-it-attrs:
const md = require('markdown-it')();
const attrs = require('markdown-it-attrs');
md.use(attrs);
const src = 'paragraph {.className #id and=attributes}';
// render
let res = md.render(src);
console.log(res);
Output
<p class="className" id="id" and="attributes">paragraph</p>
Note: Be aware of the security aspect when allowing attributes in your markdown!
Disclaimer, I'm the author of markdown-it-attrs.
Here is a working example for kramdown following @Yarin's answer.
A simple paragraph with a class attribute.
{:.yourClass}
Reference: https://kramdown.gettalong.org/syntax.html#inline-attribute-lists
If your flavour of markdown is kramdown, then you can set css class like this:
{:.nameofclass}
paragraph is here
Then in you css file, you set the css like this:
.nameofclass{
color: #000;
}
As mentioned above markdown itself leaves you hanging on this. However, depending on the implementation there are some workarounds:
At least one version of MD considers <div>
to be a block level tag but <DIV>
is just text. All broswers however are case insensitive. This allows you to keep the syntax simplicity of MD, at the cost of adding div container tags.
So the following is a workaround:
<DIV class=foo>
Paragraphs here inherit class foo from above.
</div>
The downside of this is that the output code has <p>
tags wrapping the <div>
lines (both of them, the first because it's not and the second because it doesn't match. No browser fusses about this that I've found, but the code won't validate. MD tends to put in spare <p>
tags anyway.
Several versions of markdown implement the convention <tag markdown="1">
in which case MD will do the normal processing inside the tag. The above example becomes:
<div markdown="1" class=foo>
Paragraphs here inherit class foo from above.
</div>
The current version of Fletcher's MultiMarkdown allows attributes to follow the link if using referenced links.
In slim markdown use this:
markdown:
{:.cool-heading}
#Some Title
Translates to:
<h1 class="cool-heading">Some Title</h1>
If you just need a selector for Javascript purposes (like I did), you might just want to use a href
attribute instead of a class
or id
:
Just do this:
<a href="#foo">Link</a>
Markdown will not ignore or remove the href
attribute like it does with classes and ids.
So in your Javascript or jQuery you can then do:
$('a[href$="foo"]').click(function(event) {
... do your thing ...
event.preventDefault();
});
At least this works in my version of Markdown...
참고URL : https://stackoverflow.com/questions/1058933/can-i-define-a-class-name-on-paragraph-using-markdown
'Programing' 카테고리의 다른 글
수입을 조롱하는 방법 (0) | 2020.07.13 |
---|---|
유닉스에서 "텍스트 파일 사용중"메시지를 생성하는 것은 무엇입니까? (0) | 2020.07.13 |
MVC에 다시 쓴 후 GUI가 작동하지 않음 (0) | 2020.07.13 |
Apache Thrift, Google Protocol Buffers, MessagePack, ASN.1 및 Apache Avro의 주요 차이점은 무엇입니까? (0) | 2020.07.13 |
canvas.toDataURL ()을 사용하여 캔버스를 이미지로 저장하는 방법? (0) | 2020.07.13 |