From 55c6aa8c2cdbf9323ebd62599689991f4bd26a82 Mon Sep 17 00:00:00 2001 From: Blaise Date: Fri, 28 Oct 2022 15:24:50 -0500 Subject: Special treatment for diffs --- microlight.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/microlight.js b/microlight.js index 202cc0c..295cad2 100644 --- a/microlight.js +++ b/microlight.js @@ -62,6 +62,8 @@ lastTokenType, // flag determining if token is multi-character multichar, + // first token of line + firstToken, node; // running through characters and highlighting @@ -110,6 +112,8 @@ ).setAttribute('class', 'c'+( // not formatted !tokenType ? 0 : + // diff + tokenType > 10 ? tokenType : // punctuation tokenType < 3 ? 2 : // comments @@ -133,10 +137,13 @@ // initializing a new token token = ''; + // first token of line + firstToken = pos < 2 || prev1 == '\n'; + // determining the new token type (going up the // list until matching a token type start // condition) - tokenType = 11; + tokenType = 15; while (![ 1, // 0: whitespace // 1: operator or braces @@ -159,7 +166,15 @@ chr+next1 == '/*', // 8: multiline comment chr+next1 == '//', // 9: single-line comment // 10: hash-style comment - chr == '#' && next1+text[pos+1]+text[pos+2] != 'inc' + chr == '#' && next1+text[pos+1]+text[pos+2] != 'inc', + // 11: diff add + firstToken && chr == '+', + // 12: diff remove + firstToken && chr == '-', + // 13: diff compared + firstToken && (chr+next1+text[pos+1] == '+++' || chr+next1+text[pos+1] == '---'), + // 14: diff offset + firstToken && chr+next1 == '@@' ][--tokenType]); } -- cgit v1.2.3