3 ms·
Aren't html code highlighters using regex? Isn't vscode using TextMate regex for color highlithing?
by The_rationalist 6y ago
Aren't html code highlighters using regex? Isn't vscode using TextMate regex for color highlithing?
- layer8 6y agoYou can usually use regexes for tokenization, which is sufficient for syntax highlighting, but you generally can’t use regexes for parsing (nested structures).
- chrismorgan 6y agoMost code highlighters do. They’re normally close enough to accurate for highlighting purposes (though they will commonly have some uncommon constructs that they get wrong), but they tend to fall apart when you try to use that for much more; for example, indentation when you use regular expressions to parse your HTML tends to start falling apart if you take what XML users might consider “shortcuts” (such as omitting optional end tags).
- The_rationalist 6y agoValid HTML allow optional end tags? For example?
- lifthrasiir 6y ago`<script>` is an usual example that you can't self-close and absolutely need to be followed by `</script>` in HTML5. In general though self-closing tag has no effect in HTML5 anyway, `<script>` is just an example where the usual heuristic specified by HTML5 doesn't help you at all (since it switches the lexer state).
- deleted 6y ago[deleted]
- chrismorgan 6y agohttps://html.spec.whatwg.org/multipage/syntax.html#optional-tags https://html.spec.whatwg.org/multipage/syntax.html#optional-... describes which elements have optional start and end tags. This document is valid: <!doctype html> <title>Hello,</title> <p>World! <ul> <li>A <li>B </ul> <table> <tr> <th>C <td>D <td>E <tfoot> <tr> <th>F <td>G <td>H </table> And is precisely equivalent to this document in the canonical serialisation: <!DOCTYPE html><html><head><title>Hello,</title> </head><body><p>World! </p><ul> <li>A </li><li>B </li></ul> <table> <tbody><tr> <th>C </th><td>D </td><td>E </td></tr></tbody><tfoot> <tr> <th>F </th><td>G </th><td>H </td></tr></tfoot></table></body></html>