Skip to content

Commit

Permalink
feat: spring24 Apex updates (#51)
Browse files Browse the repository at this point in the history
null coalesce operator
new namespaces

fix: "this" variables

fix: method names starting with "get" or "set" now highlighted correctly
Before, the keyword highlighter wasn't checking for word boundaries (may
be a bug with main library)
  • Loading branch information
dschach committed Feb 28, 2024
1 parent 133be56 commit fb5c5e6
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 83 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ on:
push:
branches:
- main
#paths:
# - 'src/**'
workflow_dispatch:

permissions:
contents: write
pull-requests: write
id-token: write
jobs:
release-please:
# Only run for non-Dependabot PRs
# if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 David Schach
Copyright (c) David Schach

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@

[![NPM](https://nodei.co/npm/highlightjs-apex.png)](https://www.npmjs.com/package/highlightjs-apex)

[![npm](https://img.shields.io/npm/v/highlightjs-apex)](https://www.npmjs.com/package/highlightjs-apex)
[![npm](https://img.shields.io/npm/dt/highlightjs-apex)](https://www.npmjs.com/package/highlightjs-apex)
![Salesforce Version](https://img.shields.io/badge/Spring_'24-0d9dda?style=flat&logo=salesforce&logoColor=white&label=Salesforce%20Release)
[![npm version](https://img.shields.io/npm/v/highlightjs-apex)](https://www.npmjs.com/package/highlightjs-apex)
[![npm downloads](https://img.shields.io/npm/dt/highlightjs-apex)](https://www.npmjs.com/package/highlightjs-apex)
![install size](https://badgen.net/packagephobia/install/highlightjs-apex)
[![GitHub](https://img.shields.io/github/license/highlightjs/highlightjs-apex)](https://github.com/highlightjs/highlightjs-apex/blob/main/LICENSE.md)
![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/highlightjs-apex)
[![License](https://img.shields.io/github/license/highlightjs/highlightjs-apex)](https://github.com/highlightjs/highlightjs-apex/blob/main/LICENSE.md)
[![CDN download](https://badgen.net/badge/jsDelivr/download/blue?icon=jsdelivr)](https://cdn.jsdelivr.net/npm/highlightjs-apex/dist/apex.min.js)

<!-- [![jsDelivr CDN downloads](https://badgen.net/jsdelivr/hits/gh/highlightjs/highlightjs-apex?label=jsDelivr+CDN&color=purple)](https://www.jsdelivr.com/package/gh/highlightjs/highlightjs-apex) -->

[![open issues](https://badgen.net/github/open-issues/highlightjs/highlightjs-apex?label=issues)](https://github.com/highlightjs/highlightjs-apex/issues)

## Demo

The screenshot was captured from a webpage using `apex.min.js` from the `dist` folder and the main `highlight.min.js` library.
(Code is from [Salesforce Trigger Framework](https://dschach.github.io/salesforce-trigger-framework/))
![Demo](assets/ApexHighlighting.png)
Feel free to use any css library you'd like!

## Apex code requirements

This library will highlight Apex as used in Apex classes and triggers.

## SOQL requirements

To highlight a SOQL query, it MUST be enclosed in square brackets (`[` and `]`). While creating a SOQL parser as a standalone sub-language (like javascript in html/Visualforce) would be ideal, this would require users to install both packages in a project and would get too messy. Each language can contain the other, so dependencies in the parsing become unwieldy.

## Usage

Simply include the Highlight.js library in your webpage or Node app, then load this module. For more complex usage, see [highlight.js usage](https://github.com/highlightjs/highlight.js#basic-usage).
Expand All @@ -26,12 +38,16 @@ Simply include the Highlight.js library in your webpage or Node app, then load t

Simply load this module after loading Highlight.js. You'll use the minified version found in the `dist` directory. This module is just a CDN build of the language, so it will register itself as the Javascript is loaded.

For more details see [Highlight.js main page](https://github.com/highlightjs/highlight.js#highlightjs).

```html
<script type="text/javascript" src="/path/to/highlight.min.js"></script>
<script type="text/javascript" src="/path/to/apex.min.js"></script>
<!-- <link rel="stylesheet" href="https://unpkg.com/highlightjs/styles/vs.css" /> -->
<!-- Use any stylesheet you'd like - though Apex developers may want to use the custom theme based on MavensMate's Monokai -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlightjs-apex/src/styles/monokai-sublime-apex.css" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/highlightjs-apex/src/styles/monokai-sublime-apex.css" />

<script type="text/javascript">
hljs.highlightAll();
Expand All @@ -48,17 +64,36 @@ This will find and highlight code inside of `<pre><code>` tags; it tries to dete
</pre>
```

For more details see [Highlight.js main page](https://github.com/highlightjs/highlight.js#highlightjs).
#### Ignoring a Code Block

To skip highlighting of a code block completely, use the `nohighlight` class:

```html
<pre><code class="nohighlight">...</code></pre>
```

### Using directly from jsDelivr

```html
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/highlight.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/highlightjs-apex/dist/apex.min.js"></script>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/highlightjs-apex/dist/apex.min.js"></script>
```

- More info: <https://www.jsdelivr.com/>

### Using directly from the unpkg CDN

```html
<script src="https://unpkg.com/@highlightjs/cdn-assets@11.9.0/highlight.min.js"></script>
<script
type="text/javascript"
src="https://unpkg.com/highlightjs-apex/dist/apex.min.js"></script>
```

- More info: <https://unpkg.com/>

### With Node or another build system

If you're using Node / Webpack / Rollup / Browserify, etc, simply require the language module, then register it with Highlight.js.
Expand Down
2 changes: 1 addition & 1 deletion demo/testcode.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script charset="UTF-8" src="../dist/apex.min.js"></script>
<link rel="stylesheet" href="./testcode.css" />
<!-- <link rel="stylesheet" href="../src/styles/monokai-sublime-apex.css" /> -->
<link rel="stylesheet" href="vs.css" />
<link rel="stylesheet" href="vs.css" />
<script>
hljs.debugMode();
hljs.highlightAll();
Expand Down

0 comments on commit fb5c5e6

Please sign in to comment.