2016-10-05 4 views
1

이 구문은 매우 유사하므로 사용자 지정 구문 강조 표시를하고 HTML 구문에서 일부 코드 조각을 복사했습니다. 태그 안의 텍스트를 강조하는 방법을 알아 내려고 노력하고 있습니다.숭고한 텍스트 사용자 정의 구문 강조 표시

- match: "(</?)([a-zA-Z0-9:]+)" 
    captures: 
    1: punctuation.definition.tag.begin.html 
    2: entity.name.tag.other.html 
    push: 
    - meta_scope: meta.tag.other.html 
    - match: '>' 
     scope: punctuation.definition.tag.end.html 
     pop: true 
    - match: '.' 
     scope: string.quoted.single.html 

Samle 텍스트 : 여기 내 정의입니다

<file bash> 
Some bash code block 
Some bash code block 
</file> 

내 코드는 괄호 <>filebash 키워드를 강조하지만 내부 블록에 색상을 추가하는 방법을 알아낼 수 없습니다 . 궁극적으로 나는 블록 주석이나 비슷한 것으로 써서 눈에 will 것이다. 어떤 제안?

닫는 태그가없는 태그에 대한 강조 표시를 추가하지 않는 솔루션이 필요합니다. 예를 들어 내가 작업하고있는 태그에는 등 </tag>이없는 닫는 태그를 사용하지 않는 태그가 있습니다. 정규 표현식에서 제외 태그를 추가하여 태그를 열고 닫을 수 있지만 열린 태그 만있는 경우에는 사용할 수 없습니다. 태그

<tag without close> 
This should not be a comment. 

<file bash> 
This should be a comment. 
</file> 

This also should not be a comment. 

만 작은 선택은 대부분 메타 데이터, 위의 <tag>처럼 사용할 수 있습니다.

답변

1

편도, interiors of both <style> and <script> are managed의 방법은 느슨하게 인 with_prototype을 사용하는 방법을 기반으로합니다. ([a-zA-Z0-9:]+) 여기에 바로 디커플링 match 상태와 with_prototype 조건에 모두, 당신은 귀하의 질문에 있던대로, 유효한 태그 이름과 일치하고, \2 나중에 해당 그룹을 일치시키는 데 사용되는

- match: '(?:^\s+)?(<)([a-zA-Z0-9:]+)\b(?![^>]*/>)' 
    captures: 
    1: punctuation.definition.tag.begin.html 
    2: entity.name.tag.other.html 
    push: 
    - match: '(</)(\2)(>)' 
     captures: 
     1: punctuation.definition.tag.begin.html 
     2: entity.name.tag.other.html 
     3: punctuation.definition.tag.end.html 
     pop: true 
    - match: '>' 
     scope: punctuation.definition.tag.end.html 
     push: 
     - match: '.' 
      scope: comment.block.html 
     with_prototype: 
     - match: (?=</\2) 
      pop: true 
     - include: main 
    - match: '.' 
     scope: string.quoted.single.html 

참고. with_protoype은 현재 컨텍스트의 모든 항목에 적용되는 패턴을 정의합니다. 여기서는 덧글의 일부로 취급하지 않고 </file>에 도달하면 pop을 강조 표시하는 데 사용합니다. with_prototype

- include: main 문은 당신의 코멘트-같은 콘텐츠 내의 태그 외부 <file> 태그처럼 작동되도록합니다. 예를 들어 <hello><file>과 똑같은 역할을합니다. 당신이 끝 태그와 일치하지 않는 태그가있는 경우

<file bash> 
Some bash code block 
<hello stuff> 
Some bash code block 
</hello> 
Some bash code block 
</file> 

, 당신과 같이, 스택까지 높은 해당 태그에 대한 특정 동작을 정의하여이 동작을 재정의 할 수 있습니다

- match: '(?:^\s+)?(<)(hello)\b(?![^>]*/>)' 
    captures: 
    1: punctuation.definition.tag.begin.html 
    2: entity.name.tag.other.html 
    push: 
    - match: '>' 
     scope: punctuation.definition.tag.end.html 
     pop: true 
    - match: '.' 
     scope: string.quoted.single.html 

이 값이 match: '(?:^\s+)?(<)([a-zA-Z0-9:]+)\b(?![^>]*/>)' 줄보다 빠르면 모든 <hello> 태그는 주석이 포함 된 강조 표시를 호출하지 않습니다.

이 텍스트는 comment.block.html이 아닙니다. 일부 bash는 코드 블록 일부 bash는 코드 블록 일부 bash는 코드 블록

+0

와우,이 환상적이고 내가 찾던보다 훨씬 더 고급입니다! 설명에 감사 드리며, 학습에 도움이됩니다. 이 코드는 닫는 태그가없는 경우를 제외하고는 99 %의 경우에 훌륭하게 작동합니다. – user1781482

+0

어떤 시나리오에서 마치 닫는 태그가없는 코멘트 인 것처럼 강조하고 싶습니까? @ user1781482 –

+0

그 생각은 열린 태그와 닫힌 태그 사이의 모든 것을 위협으로 위협하는 것 같습니다. 열린 태그 만 있지만 닫는 태그가없는 경우에는 블록이 없습니다. – user1781482

관련 문제