Language keywords highlighted even where they should not

#67 · closed · 3 comments

View on GitHub ↗

ablenesi

See the following python example: ``` python import polars as pl def transform_dataframe(df: pl.DataFrame, max_seq_len: int, end_action_value: int) -> pl.DataFrame: end_val = pl.lit(end_action_value) max_len = pl.lit(max_seq_len) df_with_ends = df.with_columns( end_indices=pl.col("actionType").list.eval( pl.int_range(0, pl.len()).filter(pl.element() == end_val) ) ) df_exploded = df_with_ends.explode("end_indices") start_offset = (pl.col("end_indices") + 1 - max_len).clip(lower_bound=0) slice_len = pl.col("end_indices") - start_offset + 1 list_cols = ["actionType", "engagementTimeMs", "actionTweetIds"] for col in list_cols: df_exploded = df_exploded.with_columns( pl.col(col).list.slice(start_offset, slice_len).alias(col) ) result = df_exploded.select(["userId", "actionType", "engagementTimeMs", "actionTweetIds"]) return result ``` `in` keyword is highlighted in multiple places `int`, `int_range`; ||| |-|-| |<img width="995" height="1230" alt="Image" src="https://github.com/user-attachments/assets/e4c433a5-ac87-4501-92e9-c63119f9a186" />|<img width="1001" height="1282" alt="Image" src="https://github.com/user-attachments/assets/72845a4b-e556-4ed5-b6bd-6daec62924eb" /> dev.snipme:highlights-jvm:1.0.0 dev.snipme:highlights:1.0.0 Example setup theme... ``` kotlin val keywordColor = HorizonTheme.dynamicColors.orange800 val currentTheme = HorizonTheme.variant val isDarkMode = isDarkMode() val highlights = remember(codeBlockLiteral, language, currentTheme) { val syntaxLanguage = language?.let(SyntaxLanguage::getByName) ?: return@remember listOf() Highlights.Builder( code = codeBlockLiteral, language = syntaxLanguage, theme = SyntaxThemes.darcula(darkMode = isDarkMode) .copy(keyword = keywordColor.toRgb()), ).build().getHighlights() } val code = remember(codeBlockLiteral, highlights) { buildAnnotatedString { append(codeBlockLiteral) highlights.forEach { highlight -> addStyle( style = SpanStyle( color = (highlight as? ColorHighlight)?.rgb?.let(::rgbToColor) ?: Color.Unspecified, fontWeight = (highlight as? BoldHighlight)?.let { FontWeight.Bold }, ), start = highlight.location.start, end = highlight.location.end, ) } } } ```

Comments

tmaxxdd

@ablenesi Hi Thank you for this reproduction. I will have a look

ablenesi

Nice, thanks for working on resolution, looking forward to the release containing this fix;

tmaxxdd

@ablenesi The version 1.1.0 with fix has been released