highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.68k stars 3.59k forks source link

(C) Don't highlight C++ std types #4103

Open data-man opened 2 months ago

data-man commented 2 months ago

Describe the issue C++ std types are highlighted in C sources.

Which language seems to have the issue? C.

Are you using highlight or highlightAuto? highlight.

Expected behavior C++ std types should't be highlighted in C sources.

Additional context From src/languages/c.js:

  const KEYWORDS = {
    keyword: C_KEYWORDS,
    type: C_TYPES,
    literal: 'true false NULL',
    // TODO: apply hinting work similar to what was done in cpp.js
    built_in: 'std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream '
      + 'auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set '
      + 'unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos '
      + 'asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp '
      + 'fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper '
      + 'isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow '
      + 'printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp '
      + 'strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan '
      + 'vfprintf vprintf vsprintf endl initializer_list unique_ptr',
  };

Why?

joshgoebel commented 2 months ago

C++ std types should't be highlighted in C sources.

Agree - no doubt left over from when we forked c from the cpp grammar. How many of these would that remove if we cleaned this up?

Dxuian commented 2 months ago

can this be assigned to me ?

Dxuian commented 2 months ago

ive added a PR @joshgoebel please review

data-man commented 1 month ago

How many of these would that remove if we cleaned this up?

Would be nice to add all functions and types from https://en.cppreference.com/w/c/header. And support https://en.cppreference.com/w/c/23.