Tidy

Tidy

HTML 문서를 다루다 보면 태그가 어긋나 있거나 정리하고 싶은 문서가 꼭 생겨요. Tidy는 그런 HTML을 **정리하고(clean) 복구(repair)**해 주는 유틸리티의 PHP 바인딩이에요. 정리뿐 아니라 문서 트리를 탐색하는 기능도 있어요.

출처: Tidy

본문

Tidy는 Tidy HTML clean and repair 유틸리티의 바인딩이에요. HTML, XHTML, XML 문서를 정리하고 그 외에 조작할 수 있을 뿐 아니라, 문서 트리를 탐색할 수도 있어요. 심지어 그 안에 내장된 PHP나 ASP 같은 스크립트 언어가 있는 문서도 객체 지향 구조로 다룰 수 있어요.

설치·설정(Installing/Configuring)

  • 요구 사항(Requirements)
  • 설치(Installation)
  • 런타임 설정(Runtime Configuration)
  • 사전 정의 상수(Predefined Constants)
  • 예제(Examples) — Tidy 예제(Tidy example)

tidy 클래스

  • tidy — tidy 클래스
  • tidy::body — tidy 파싱 트리의 <body> 태그에서 시작하는 tidyNode 객체를 반환해요(Returns a tidyNode object starting from the tag of the tidy parse tree).
  • tidy::cleanRepair — 파싱한 마크업에 설정된 정리·복구 작업을 실행해요(Execute configured cleanup and repair operations on parsed markup).
  • tidy::__construct — 새 tidy 객체를 생성해요(Constructs a new tidy object).
  • tidy::diagnose — 파싱하고 복구한 마크업에 설정된 진단을 실행해요(Run configured diagnostics on parsed and repaired markup).
  • tidy::$errorBuffer — 지정한 문서 파싱 중 발생한 경고와 오류를 반환해요(Return warnings and errors which occurred parsing the specified document).
  • tidy::getConfig — 현재 Tidy 구성을 가져와요(Get current Tidy configuration).
  • tidy::getHtmlVer — 지정한 문서의 감지된 HTML 버전을 가져와요(Get the Detected HTML version for the specified document).
  • tidy::getOpt — tidy 문서의 지정한 구성 옵션 값을 반환해요(Returns the value of the specified configuration option for the tidy document).
  • tidy::getOptDoc — 주어진 옵션 이름의 문서를 반환해요(Returns the documentation for the given option name).
  • tidy::getRelease — Tidy 라이브러리의 릴리스 날짜(버전)를 가져와요(Get release date (version) for Tidy library).
  • tidy::getStatus — 지정한 문서의 상태를 가져와요(Get status of specified document).
  • tidy::head — tidy 파싱 트리의 <head> 태그에서 시작하는 tidyNode 객체를 반환해요(Returns a tidyNode object starting from the tag of the tidy parse tree).
  • tidy::html — tidy 파싱 트리의 <html> 태그에서 시작하는 tidyNode 객체를 반환해요(Returns a tidyNode object starting from the tag of the tidy parse tree).
  • tidy::isXhtml — 문서가 XHTML 문서인지 나타내요(Indicates if the document is a XHTML document).
  • tidy::isXml — 문서가 일반적인(non HTML/XHTML) XML 문서인지 나타내요(Indicates if the document is a generic (non HTML/XHTML) XML document).
  • tidy::parseFile — 파일이나 URI의 마크업을 파싱해요(Parse markup in file or URI).
  • tidy::parseString — 문자열에 저장된 문서를 파싱해요(Parse a document stored in a string).
  • tidy::repairFile — 파일을 복구하고 문자열로 반환해요(Repair a file and return it as a string).
  • tidy::repairString — 선택적으로 제공된 구성 파일을 사용해 문자열을 복구해요(Repair a string using an optionally provided configuration file).
  • tidy::root — tidy 파싱 트리의 루트를 나타내는 tidyNode 객체를 반환해요(Returns a tidyNode object representing the root of the tidy parse tree).

tidyNode 클래스

  • tidyNode — tidyNode 클래스
  • tidyNode::__construct — 직접 인스턴스화를 막는 private 생성자(Private constructor to disallow direct instantiation).
  • tidyNode::getNextSibling — 현재 노드의 다음 형제 노드를 반환해요(Returns the next sibling node of the current node).
  • tidyNode::getParent — 현재 노드의 부모 노드를 반환해요(Returns the parent node of the current node).
  • tidyNode::getPreviousSibling — 현재 노드의 이전 형제 노드를 반환해요(Returns the previous sibling node of the current node).
  • tidyNode::hasChildren — 노드에 자식이 있는지 검사해요(Checks if a node has children).
  • tidyNode::hasSiblings — 노드에 형제가 있는지 검사해요(Checks if a node has siblings).
  • tidyNode::isAsp — 이 노드가 ASP인지 검사해요(Checks if this node is ASP).
  • tidyNode::isComment — 노드가 주석을 나타내는지 검사해요(Checks if a node represents a comment).
  • tidyNode::isHtml — 노드가 요소 노드인지 검사해요(Checks if a node is an element node).
  • tidyNode::isJste — 이 노드가 JSTE인지 검사해요(Checks if this node is JSTE).
  • tidyNode::isPhp — 노드가 PHP인지 검사해요(Checks if a node is PHP).
  • tidyNode::isText — 노드가 텍스트(마크업 없음)를 나타내는지 검사해요(Checks if a node represents text (no markup)).

Tidy 함수(Tidy Functions)

  • ob_tidyhandler — 버퍼를 복구하는 ob_start 콜백 함수(ob_start callback function to repair the buffer).
  • tidy_access_count — 지정한 문서에서 만난 Tidy 접근성 경고 수를 반환해요(Returns the Number of Tidy accessibility warnings encountered for specified document).
  • tidy_config_count — 지정한 문서에서 만난 Tidy 구성 오류 수를 반환해요(Returns the Number of Tidy configuration errors encountered for specified document).
  • tidy_error_count — 지정한 문서에서 만난 Tidy 오류 수를 반환해요(Returns the Number of Tidy errors encountered for specified document).
  • tidy_get_output — 파싱한 tidy 마크업을 나타내는 문자열을 반환해요(Return a string representing the parsed tidy markup).
  • tidy_warning_count — 지정한 문서에서 만난 Tidy 경고 수를 반환해요(Returns the Number of Tidy warnings encountered for specified document).

더 알아보기

  • Tidy 라이브러리의 구성 옵션 문서 위치가 옮겨졌다는 사용자 메모가 있어요. 최신 구성 옵션은 https://api.html-tidy.org/에서 확인할 수 있어요.
  • ob_tidyhandler를 쓰면 출력 버퍼 단계에서 HTML을 자동으로 정리할 수 있어요.