Skip to content

Commit

Permalink
Upgrade PrismJS to 1.25.0 (#7)
Browse files Browse the repository at this point in the history
* Upgraded PrismJS to 1.25.0
* Replaced line breaks transoformation according to @mlanin changes in forked repository
* Made highest priority for @annotation styles
  • Loading branch information
GreenAsh authored Nov 11, 2021
1 parent c702d91 commit 02f4f23
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 45 deletions.
2 changes: 1 addition & 1 deletion dist/feedback.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html><html lang="en"><head><title>miro-code-highlighter-plugin feedback</title><script src="https://miro.com/app/static/sdk.1.1.js"></script><link rel="stylesheet" href="https://unpkg.com/mirotone/dist/styles.css"/><script src="https://browser.sentry-cdn.com/6.14.0/bundle.min.js" integrity="sha384-1FVbcJ5cSGdCrMNyUndHGSl0WlS+Cq5zaYdfnVF7NqkkQpU+7plvm0NomKbzcD//" crossorigin="anonymous"></script><script>Sentry.init({
dsn: 'https://[email protected]/1831923',
release: '[email protected].15'
release: '[email protected].16'
});</script></head><body><div class="grid"><div class="cs11 ce12 grid" style="text-align: right"><button class="button-icon" style="width:40px; height: 40px;"></button> <button class="button-icon button-icon-small icon-close" type="button" onclick="miro.board.ui.closeModal();"></button></div><div class="cs2 ce11 form-group"><textarea id="feedback_area" class="textarea" placeholder="Please write your feedback here" rows="4" maxlength="1000"></textarea></div><div class="cs5 ce8"><button class="button button-primary" onclick="sendFeedback()">Send Feedback</button></div></div></body></html><script>function sendFeedback() {
try {
const feedbackText = document.getElementById('feedback_area').value;
Expand Down
4 changes: 2 additions & 2 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html><html lang="en"><head><title>miro-code-syntax-highlighter-plugin</title><script src="https://miro.com/app/static/sdk.1.1.js"></script><script src="https://browser.sentry-cdn.com/6.14.0/bundle.min.js" integrity="sha384-1FVbcJ5cSGdCrMNyUndHGSl0WlS+Cq5zaYdfnVF7NqkkQpU+7plvm0NomKbzcD//" crossorigin="anonymous"></script><script>Sentry.init({
dsn: 'https://[email protected]/1831923',
release: '[email protected].15'
});</script><script src="syntax-highlighter-miro-plugin.js?v0.5.15"></script></head><body><p><b>This is the main miro plugin page.</b> It's useful only within https://miro.com</p></body></html>
release: '[email protected].16'
});</script><script src="syntax-highlighter-miro-plugin.js?v0.5.16"></script></head><body><p><b>This is the main miro plugin page.</b> It's useful only within https://miro.com</p></body></html>
4 changes: 2 additions & 2 deletions dist/settings.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"><title>Color Highlighter Settings</title><link rel="stylesheet" href="https://unpkg.com/mirotone/dist/styles.css"/><script src="https://browser.sentry-cdn.com/6.14.0/bundle.min.js" integrity="sha384-1FVbcJ5cSGdCrMNyUndHGSl0WlS+Cq5zaYdfnVF7NqkkQpU+7plvm0NomKbzcD//" crossorigin="anonymous"></script><script>Sentry.init({
dsn: 'https://[email protected]/1831923',
release: '[email protected].15'
});</script><script src="https://miro.com/app/static/sdk.1.1.js"></script></head><body><div class="grid"><div class="cs2 ce10"><h3 class="h3">Code syntax highlighter Settings</h3></div><div class="cs11 ce12 grid"><button class="button-icon button-icon-small icon-help" type="button" onclick="location.href='feedback.html';"></button> <button class="button-icon button-icon-small icon-close" type="button" onclick="miro.board.ui.closeModal();"></button></div><div class="cs1 ce12" style="height: 10px;">&nbsp;</div><div class="cs2 ce4">Default language</div><div class="cs5 ce11"><select id="languages" class="select"></select></div><div class="cs2 ce4">Theme</div><div class="cs5 ce11"><select id="themes_select" class="select"></select></div></div></body></html><script src="syntax-highlighter-settings.js?v0.5.15"></script>
release: '[email protected].16'
});</script><script src="https://miro.com/app/static/sdk.1.1.js"></script></head><body><div class="grid"><div class="cs2 ce10"><h3 class="h3">Code syntax highlighter Settings</h3></div><div class="cs11 ce12 grid"><button class="button-icon button-icon-small icon-help" type="button" onclick="location.href='feedback.html';"></button> <button class="button-icon button-icon-small icon-close" type="button" onclick="miro.board.ui.closeModal();"></button></div><div class="cs1 ce12" style="height: 10px;">&nbsp;</div><div class="cs2 ce4">Default language</div><div class="cs5 ce11"><select id="languages" class="select"></select></div><div class="cs2 ce4">Theme</div><div class="cs5 ce11"><select id="themes_select" class="select"></select></div></div></body></html><script src="syntax-highlighter-settings.js?v0.5.16"></script>
2 changes: 1 addition & 1 deletion dist/syntax-highlighter-miro-plugin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/syntax-highlighter-settings.js

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@
"license": "MIT",
"dependencies": {
"@sentry/browser": "^6.14.1",
"prismjs": "^1.17.1",
"react": "^16.9.12",
"react-dom": "^16.9.12"
"prismjs": "^1.25.0"
},
"devDependencies": {
"@sentry/typescript": "^5.20.1",
"@types/prismjs": "^1.16.0",
"@types/react": "^16.9.12",
"@types/react-dom": "^16.9.4",
"copy-webpack-plugin": "^9.0.1",
"html-webpack-plugin": "^5.5.0",
"raw-loader": "^4.0.2",
Expand Down
59 changes: 40 additions & 19 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
import {default as highlighter} from 'code-highlighter/prism'
import {ThemeContext} from "./code-highlighter/prism/themes/interfaces";
import {themeRegistry} from "./code-highlighter/prism/themes";

highlighter.highlight('java', `public class MineSweeper
{\tprivate int[][] myTruth;
\tprivate boolean[][] myShow;
\t
\tpublic void cellPicked(int row, int col)
\t{\tif( inBounds(row, col) && !myShow[row][col] )
\t\t{\tmyShow[row][col] = true;
\t\t
\t\t\tif( myTruth[row][col] == 0)
\t\t\t{\tfor(int r = -1; r <= 1; r++)
\t\t\t\t\tfor(int c = -1; c <= 1; c++)
\t\t\t\t\t\tcellPicked(row + r, col + c);
\t\t\t}\t
\t\t}
\t}
\t
\tpublic boolean inBounds(int row, int col)
\t{\treturn 0 <= row && row < myTruth.length && 0 <= col && col < myTruth[0].length;
\t}
ThemeContext.getInstance().currentTheme = themeRegistry.getTheme('okaida');
highlighter.highlight('java', `package org.springframework.boot.actuate.cache;
/**
* test
*/
@EndpointWebExtension(endpoint = CachesEndpoint.class)
public class CachesEndpointWebExtension {
private final CachesEndpoint delegate;
public CachesEndpointWebExtension(CachesEndpoint delegate) {
this.delegate = delegate;
}
@ReadOperation
public WebEndpointResponse<CacheEntry> cache(@Selector String cache, @Nullable String cacheManager) {
try {
CacheEntry entry = this.delegate.cache(cache, cacheManager);
int status = (entry != null) ? WebEndpointResponse.STATUS_OK : WebEndpointResponse.STATUS_NOT_FOUND;
return new WebEndpointResponse<>(entry, status);
}
catch (NonUniqueCacheException ex) {
return new WebEndpointResponse<>(WebEndpointResponse.STATUS_BAD_REQUEST);
}
}
@DeleteOperation
public WebEndpointResponse<Void> clearCache(@Selector String cache, @Nullable String cacheManager) {
try {
boolean cleared = this.delegate.clearCache(cache, cacheManager);
int status = (cleared ? WebEndpointResponse.STATUS_NO_CONTENT : WebEndpointResponse.STATUS_NOT_FOUND);
return new WebEndpointResponse<>(status);
}
catch (NonUniqueCacheException ex) {
return new WebEndpointResponse<>(WebEndpointResponse.STATUS_BAD_REQUEST);
}
}
}`).then(value => console.log(value)).catch(reason => console.error(reason));
13 changes: 1 addition & 12 deletions src/code-highlighter/prism/prism-dom-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,7 @@ export class PrismDOMProcessor implements DOMProcessor {
}

private static replacesBreaks(html:string): string {
let result = html.replace(/\n/gm, '</p><p>');
if (result.startsWith('</p>')){
result = result.substring(4);
} else {
result = '<p>' + result;
}
if (result.endsWith('<p>')){
result = result.substring(0, result.length - 3);
} else {
result += '</p>';
}
return result;
return html.replace(/(?:\r\n|\r|\n)/g, '<br>');
}

private transform(parent: Node, out: Node) {
Expand Down
17 changes: 16 additions & 1 deletion src/code-highlighter/prism/themes/ThemeImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,28 @@ export class ThemeImpl implements Theme {
return;
}
let classNames = className.replace(/-/g, '_').split(' ');
const annotationClass = 'annotation';
let hasAnnotation = false;
classNames.forEach(value => {
if (value === 'token'){
if (value === 'token') {
return;
}
// remember if we had annotanion in class names
// apply annotation styles later
if (value === annotationClass) {
hasAnnotation = true;
return;
}
this.mergeStyle(value, element, true);
this.mergeStyle(`${lang}_${value}`, element, false);
});

// java @annotation elements after prism conversion will have class name: "token annotation punctuation"
// so the "punctuation" styles are always overrides "annotation" ones.
if (hasAnnotation) {
this.mergeStyle(annotationClass, element, true);
this.mergeStyle(`${lang}_${annotationClass}`, element, false);
}
}

private mergeStyle(className: string, element: HTMLElement, warn: boolean){
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require("copy-webpack-plugin");

version = '0.5.15'
version = '0.5.16'

module.exports = {
mode: 'production',
Expand Down

0 comments on commit 02f4f23

Please sign in to comment.