Skip to content

Commit

Permalink
fix: Remove Code block background highlighting
Browse files Browse the repository at this point in the history
The code block highlighting code was terribly slow for large files
and is already implemented in the main app much more efficiently.
  • Loading branch information
CalebJohn committed Nov 4, 2021
1 parent 88a71e3 commit f54849e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 36 deletions.
8 changes: 2 additions & 6 deletions TIPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,8 @@ div.CodeMirror .cm-overlay.cm-rm-list-token {

## Code Blocks

```css
/* Add a background color to code blocks */
div.CodeMirror .cm-rm-code-block {
background-color: lightgrey;
}
```
Code block highlighting is implemented by the main Joplin app as of v2.3.4 and was removed from Rich Markdown versions 0.8.0 onwards.


## Colour Schemes

Expand Down
28 changes: 0 additions & 28 deletions src/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ export const blockquote_regex = /^\s*\>+\s/g;
// TODO: Extend this to get better table highlighting
export const table_regex = /^\|[^\n]+\|/g;

// Special function to apply a line class to code blocks
function codeBlock(cls: string) {
return (cm: any, line: number, state: any) => {
if (state?.outer && (state?.outer?.code || (state?.outer?.thisLine?.fencedCodeEnd))) {
cm.addLineClass(line, 'wrap', cls);
}
else {
cm.removeLineClass(line, 'wrap', cls);
}
}
}

function exec(query: RegExp, stream: any) {
query.lastIndex = stream.pos;
return query.exec(stream.string);
Expand Down Expand Up @@ -106,10 +94,6 @@ const overlays = [
regexOverlay('rm-hr line-cm-rm-hr', hr_regex, ['extraCSS']),
];

const blocks = [
codeBlock('cm-rm-code-block')
];

function validate(settings: any, values: string[]): boolean {
for (let value of values) {
if (!settings[value])
Expand All @@ -132,15 +116,3 @@ export function remove(cm: any) {
cm.removeOverlay(overlay);
}

// from and to are ignored for now becuase a change on one line
// can affect any number of other lines, this means we need to
// reprocess the entire document
export function onSourceChanged(cm: any, from: number, to: number) {
for (let i = cm.firstLine(); i <= cm.lastLine(); i++) {
const state = cm.getStateAfter(i, true);

for (let block of blocks) {
block(cm, i, state);
}
}
}
2 changes: 0 additions & 2 deletions src/richMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ module.exports = {
ImageHandlers.clearAllWidgets(this);
ImageHandlers.onSourceChanged(this, this.firstLine(), this.lastLine());
ImageHandlers.afterSourceChanges(this);
Overlay.onSourceChanged(this, this.firstLine(), this.lastLine());
if (newSettings.activeLine) {
this.setOption('styleActiveLine', { nonEmpty: true });
} else {
Expand Down Expand Up @@ -102,7 +101,6 @@ module.exports = {
const { from, to } = get_change_lines(change);

ImageHandlers.onSourceChanged(cm, from, to);
Overlay.onSourceChanged(cm, from, to);
}
function on_update(cm: any) {
ImageHandlers.afterSourceChanges(cm);
Expand Down

0 comments on commit f54849e

Please sign in to comment.