-
Notifications
You must be signed in to change notification settings - Fork 278
CSSUtils, HTMLUtils
This page discusses lower level parsing utilities in Brackets used by utilities
such as CSSUtils
, HTMLUtils
, and JSUtils
.
The 2 main usages are:
- Parsing Block of Code
- Determining State of Current Position
Parsing a block of text (usually an entire file) is necessary to enumerate certain elements such as:
- CSS selectors
- JS functions
-
<style>
blocks -
<script>
blocks
The block of text being parsed can be large, so this code needs to be performant.
- CSSUtils
findMatchingRules()
extractAllSelectors()
- JSUtils
findAllMatchingFunctionsInText()
- HTMLUtils
findBlocks()
findStyleBlocks()
To determine the token, type, state, etc. of current position in document, text before and after current position is parsed.
- EditorCommandHandlers
blockComment()
lineComment()
- CSSCodeHints
insertHint()
- CSSUtils
getInfoAtPos()
findSelectorAtDocumentPos()
- HTMLUtils
getTagAttributes()
getTagInfo()
Following are the common ways of parsing in Brackets:
-
TokenUtils
:getInitialContext()
,moveNextToken()
,movePrevToken()
- Using
mode.token()
withCodeMirror.StringStream
Written using CodeMirror mode, state, and token API. Tokens and states are generated by CodeMirror modes defined in src/thirdparty/CodeMirror2/mode folder.
- EditorCommandHandlers
blockComment()
lineComment()
- CSSCodeHints
insertHint()
- CSSUtils
getInfoAtPos()
findSelectorAtDocumentPos()
- HTMLUtils
getTagAttributes()
getTagInfo()
findBlocks()
findStyleBlocks()
Uses CodeMirror Mode API.
- CSSUtils
findMatchingRules()
extractAllSelectors()
- JSUtils
findAllMatchingFunctionsInText()
Implementation details in CSS Context API implementation spec.
CodeMirror modes, states, and tokens change over time due to more granular states being added. These change can break parsing code, so beware when upgrading CodeMirror.
The SVG Code Hints extension may be merged into core soon, so a new XMLUtils
utility may be introduced.