2013-10-24 7 views
1

나는이 html 발췌 문장을 가지고 있습니다. 나는 태그를 제거하려면이확대 HTML 태그 제거

<html> 
    <body> 
     <div class="content">lorem ipsum</div> 
    </body> 
</html> 

내가 발견하지 못했습니다 enlive 도우미 함수가 될 그 조각을 구문 분석 원하고 자바 스크립트 태그

<html> 
    <body> 
     <div class="content">lorem ipsum</div> 
     <script src="/js/jquery.js" type="text/javascript"></script> 
     <script src="/js/bootstrap.min.js" type="text/javascript"></script> 
    </body> 
</html> 

없이 HTML을 방출한다.

예를 들어 해결책을 찾아 냈습니다. 그래서 나는이 코드를 작성하고 난 nil returning 기능을 사용하는 것입니다 조건부로 렌더링 된 페이지의 일부 태그를 제거해야 할 때 JS는

(html/deftemplate template-about "../resources/public/build/about/index.html" 
    [] 
    [:script] (fn js-clear [& args] nil) 
) 

답변

2

내 일반적인 접근 방식을 사라졌다. 특정 경우 인스턴스

(html/defsnippet upgrade-plan "page_templates/upgrade-plan.html" [:#upgradePlanSection] 
    [pending-invoice ... ] 
    ... 
    [:#delayedPlanWarning] #(when pending-invoice 
          (html/at % 
            [:#delayedPlanWarning] (html/remove-attr :style) 
            [:.messagesText] (html/html-content (tower/t :plans/pending-invoice 
                       (:id pending-invoice))))) 
    ... 

들어

pending-invoice 함수가 nil를 반환 이후 delayedPlanWarning 요소가 렌더링되는 HTML에서 제거 nil 경우. 당신이 발광 여분의 구문 분석 및 신경 쓰지 않는 경우

+0

고맙습니다. – calvin91

0

, 다음은 잘 할 것이다 : 전체 태그를 제거 할 때

(def orig (html-resource (java.io.StringReader. "<html> 
<body> 
    <div class=\"content\">lorem ipsum</div> 
    <script src=\"/js/jquery.js\" type=\"text/javascript\"></script> 
    <script src=\"/js/bootstrap.min.js\" type=\"text/javascript\"></script> 
</body> 
</html>"))) 
(def stripped (transform orig [(keyword "script")] (substitute ""))) 
(apply str (emit* stripped)) 
0

, 당신은 단지 당신의 변화로 nil를 사용해야합니다.

귀하의 경우에는
(deftemplate tester1 
      (java.io.StringReader. "<html><body><div class=\"content\">...") 
      [] 
      [:script] nil) 

(template1) 

, 당신은 당신이 사용하고있는 자원과 StringReader을 대체 할 것이다.