을 얻는 방법을 플레이하여 추가 등 모든 html <p> 태그?
-
11-09-2019 - |
문제
내가 사용하는 장고의 태그 패키지를 변환하는 플레로 html.하는 방법이 있 사용자 지정 HTML 작가 추가하는 class 특성을 각 <p>
태그?
용 클래스 directive 를 위해 각각의 단락,그러나 나는 이것을 자동화하는 과정입니다.
예를 들어,저는 이 재구성 텍스트:
hello
=====
A paragraph of text.
변환하여 html.
<h1>hello</h1>
<p class="specialClass">A paragraph of text.</p>
그 이유는 내가 삽입하려는 클래스가 아 하이픈 붙이기 라이브러리 는 작동을 추가해서 하이픈하는 모든 범주와 함께"하이픈으로 연결"클래스입니다.나의가 있습니다 하이픈 클래스 컨테이너에 태그하지만,모든 어린이들이 상속에 하이픈 클래스입니다.나 자바스크립트를 사용하여 동적으로 추가 등,하지만 제가 생각될 수 있는 간단한 방법으로 그것을 할 수 플레.
도움을 주셔서 감사합니다,
Joe
해결책
당신은 말을하지 않습니다 왜 당신이 원하는 클래스를 추가하려면 모든 단락이지만,그것은 쉬울 수 있습니다 가 다른 방법으로 접근하고 있습니다.예를 들어,만약 당신이 시도하고 있는 스타일을 단락에 사용할 수 있습니다 다른 CSS 기술을 선택하려면 모든 단락에서 출력:
CSS:
div.resttext p {
/* all the styling you want... */
}
HTML:
<div class='resttext'>
<p>Blah</p>
<p>Bloo</p>
</div>
업데이트:이후 사용 하려고 합니다.hyphenator.js 을,나를 사용하는 것이 좋습니다 것 그 selectorfunction
설정하는 요소를 선택한 다르게:
Hyphenator.config({
selectorfunction: function () {
/* Use jQuery to find all the REST p tags. */
return $('div.resttext p');
}
});
Hyphenator.run();
다른 팁
서브 클래스 내장 html4css1
작가, 사용 이것 참조로 ..
from docutils.writers import html4css1
class MyHTMLWriter(html4css1.Writer):
"""
This docutils writer will use the MyHTMLTranslator class below.
"""
def __init__(self):
html4css1.Writer.__init__(self)
self.translator_class = MyHTMLTranslator
class MyHTMLTranslator(html4css1.HTMLTranslator):
def visit_paragraph(self, node):
self.section_level += 1
self.body.append(self.starttag(node, 'p', CLASS='specialClass'))
def depart_paragraph(self, node):
self.section_level -= 1
self.body.append('</p>\n')
그런 다음 다음과 같이 사용하십시오.
from docutils.core import publish_string
print publish_string("*This* is the input text", writer=MyHTMLWriter())
제휴하지 않습니다 StackOverflow