문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
잡개발자:심심풀이:도쿠위키:search_highlighter [2025/11/28 11:05] carlito76 |
잡개발자:심심풀이:도쿠위키:search_highlighter [2026/02/26 18:40] (현재) carlito76 |
||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| {{htmlmetatags> | {{htmlmetatags> | ||
| - | metatag-description=(HTML Character Entity, HTML Character, HTML Entity) | + | metatag-description=(도쿠위키, DokuWiki, 위키, Wiki, 플러그인, |
| - | metatag-og: | + | metatag-og: |
| }} | }} | ||
| - | ====== | + | ====== |
| - | FIXME | + | ===== 기능 설명 ===== |
| + | * 검색어 하이라이트 시 플러그인에서 생성한 태그와 충돌이 나는 경우가 발생함 | ||
| + | * 검색어 하이라이트 처리를 백엔드 대신에 프론트엔드에서 하도록 커스터마이징 | ||
| + | |||
| + | ===== 커스터마이징 ===== | ||
| + | <sxh php; gutter: true; first-line: 276; highlight: [308]; title: inc/ | ||
| + | function html_show($txt=null){ | ||
| + | global $ID; | ||
| + | global $REV; | ||
| + | global $HIGH; | ||
| + | global $INFO; | ||
| + | global $DATE_AT; | ||
| + | //disable section editing for old revisions or in preview | ||
| + | if($txt || $REV){ | ||
| + | $secedit = false; | ||
| + | }else{ | ||
| + | $secedit = true; | ||
| + | } | ||
| + | |||
| + | if (!is_null($txt)){ | ||
| + | // | ||
| + | echo '< | ||
| + | echo p_locale_xhtml(' | ||
| + | echo '< | ||
| + | $html = html_secedit(p_render(' | ||
| + | if($INFO[' | ||
| + | echo $html; | ||
| + | echo '< | ||
| + | echo '</ | ||
| + | |||
| + | }else{ | ||
| + | if ($REV||$DATE_AT){ | ||
| + | $data = array(' | ||
| + | Event:: | ||
| + | } | ||
| + | $html = p_wiki_xhtml($ID, | ||
| + | $html = html_secedit($html, | ||
| + | if($INFO[' | ||
| + | //$html = html_hilight($html, | ||
| + | echo $html; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <sxh javascript; gutter: true; highlight: [1-78]; title: conf/ | ||
| + | jQuery(function() { | ||
| + | // 검색어 파라미터 | ||
| + | var phrases = []; | ||
| + | var search = window.location.search; | ||
| + | if (search) { | ||
| + | var params = search.substring(1).split('&' | ||
| + | for (var i = 0; i < params.length; | ||
| + | var pair = params[i].split(' | ||
| + | var key = decodeURIComponent(pair[0]); | ||
| + | if (key === ' | ||
| + | var value = decodeURIComponent(pair[1].replace(/ | ||
| + | phrases.push(value); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | if (phrases.length === 0) return; | ||
| + | |||
| + | // 검색어 정규식 | ||
| + | var escaped = []; | ||
| + | for (var j = 0; j < phrases.length; | ||
| + | escaped.push(phrases[j].replace(/ | ||
| + | } | ||
| + | var regex = new RegExp(' | ||
| + | |||
| + | // 제외 리스트 | ||
| + | var exclude_list = [ | ||
| + | ' | ||
| + | , ' | ||
| + | , ' | ||
| + | ]; | ||
| + | var exclude_selector = exclude_list.join(', | ||
| + | |||
| + | // 허용 리스트 | ||
| + | var allow_list = [ | ||
| + | ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | , ' | ||
| + | ]; | ||
| + | |||
| + | // 하이라이트 함수 | ||
| + | function html_hilight($node) { | ||
| + | $node.contents().each(function() { | ||
| + | var node = this; | ||
| + | if (node.nodeType === 3) { | ||
| + | var txt = node.nodeValue; | ||
| + | if (regex.test(txt)) { | ||
| + | regex.lastIndex = 0; | ||
| + | jQuery(node).replaceWith(txt.replace(regex, | ||
| + | } | ||
| + | } else if (node.nodeType === 1) { | ||
| + | var $this = jQuery(node); | ||
| + | if (!$this.is(exclude_selector)) { | ||
| + | var tag = node.tagName.toLowerCase(); | ||
| + | if (allow_list.indexOf(tag) !== -1) { | ||
| + | html_hilight($this); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | }); | ||
| + | } | ||
| + | |||
| + | // 하이라이트 함수 실행 | ||
| + | var $target = jQuery(" | ||
| + | if ($target.length > 0) { | ||
| + | html_hilight($target); | ||
| + | } | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | ===== 플러그인 제작 시 ===== | ||
| + | * 기능 사용 여부 설정 | ||
| + | * 하이라이트 색상 선택 | ||
| + | * 하이라이트 제외 플러그인 선택 | ||
| + | * SyntaxHighlighter4 Plugin | ||
| + | * PlantUML Parser Plugin | ||
| + | * Tag Plugin | ||
| + | |||
| + | {{tag>" | ||