Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Syntax Highlighting Change #37

Merged
merged 3 commits into from
Mar 6, 2024
Merged

Conversation

signus
Copy link
Contributor

@signus signus commented Feb 21, 2024

Adds the ability to modify the DOM to change the PrismJS class utilized in the query-code block to update with the new class and remove the previously used class prior to adding the new one. This can help to ease formatting for visibilty as well as promote syntax definitions for the other target query languages.

Additionally this adds the external source for prism-kusto.min.js and prism-sql.min.js whereby the default language select for all other languages should be SQL as most target languages are rather SQL-like.

In the future this mechanism can be improved upon to include more languages as well as to add an Enum to map the target languages to the specific PrismJS class name.

Adds the ability to modify the DOM to change the PrismJS class utilized
in the `query-code` block to update with the new class and remove the
previously used class prior to adding the new one. This can help to ease
formatting for visibilty as well as promote syntax definitions for the
other target query languages.
@M3NIX
Copy link
Collaborator

M3NIX commented Feb 23, 2024

@signus Thank you for the pull request! I really do like the idea.
Instead of using a big switch statement I would suggest that we use a simple javascript object with the backend as keys and the language as values. If the backend is not found as a key we set a default language.

So something like that:

let backend = getSelectValue("select-backend");
let language = "";
let prev_language = "";
let default_language = "language-sql"

// ... code to find the previous language

const languageMap = {
  "azure" : "language-kusto",
  "ibm-qradar-aql": "language-sql",
  "microsoft365defender": "language-kusto",
  "splunk": "language-splunk-spl",
  "qradar": "language-sql"
};

language = languageMap[backend] ? languageMap[backend] : default_language;

Copy link
Collaborator

@M3NIX M3NIX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adjust switch statement as suggested

Utilizes a map for handling the selection of the PrismJS language class
instead of the original switch statement for brevity.
@signus
Copy link
Contributor Author

signus commented Feb 23, 2024

Much appreciate the feedback! The switch statement was not desired, so thank you for helping to speed up that adjustment!

@signus signus requested a review from M3NIX March 5, 2024 16:38
@M3NIX M3NIX merged commit 69b1678 into magicsword-io:main Mar 6, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants