-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
runMode
method that provides syntax highlighting for static h…
…tml content.
- Loading branch information
Showing
6 changed files
with
105 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>PG CodeMirror Static View Playground</title> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> | ||
<link href="style.css" rel="stylesheet"> | ||
<script src="pg-codemirror-editor.js" defer></script> | ||
<script src="static-view.js" defer></script> | ||
</head> | ||
|
||
<body> | ||
<div class="container my-3"> | ||
<h1>PG CodeMirror Static View Playground</h1> | ||
<div class="input-group mb-3"> | ||
<button class="btn btn-primary" id="load-file" type="button">Load File</button> | ||
<input type="file" name="problem-file" class="form-control"> | ||
</div> | ||
<input type="hidden" name="view-source"> | ||
<div><pre class="pg-codemirror-view m-0 h-100 p-3 border border-secondary overflow-scroll"></pre></div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* global PGCodeMirrorEditor */ | ||
|
||
const codeMirrorElt = document.querySelector('.pg-codemirror-view'); | ||
|
||
if (codeMirrorElt instanceof HTMLElement) { | ||
const sourceInput = document.getElementsByName('view-source')[0]; | ||
PGCodeMirrorEditor.runMode(sourceInput.value, codeMirrorElt); | ||
|
||
document.getElementById('load-file')?.addEventListener('click', () => { | ||
const file = document.getElementsByName('problem-file')[0]?.files?.[0]; | ||
if (file) { | ||
const reader = new FileReader(); | ||
reader.readAsText(file); | ||
reader.addEventListener('load', () => { | ||
sourceInput.value = reader.result; | ||
PGCodeMirrorEditor.runMode(sourceInput.value, codeMirrorElt); | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
import { tags as t } from '@lezer/highlight'; | ||
import { HighlightStyle, syntaxHighlighting } from '@codemirror/language'; | ||
|
||
export const lightTheme = syntaxHighlighting( | ||
HighlightStyle.define([ | ||
{ tag: t.meta, color: '#404740' }, | ||
{ tag: t.link, textDecoration: 'underline' }, | ||
{ tag: t.heading, textDecoration: 'underline', fontWeight: 'bold' }, | ||
{ tag: t.emphasis, fontStyle: 'italic' }, | ||
{ tag: t.strong, fontWeight: 'bold' }, | ||
{ tag: t.strikethrough, textDecoration: 'line-through' }, | ||
{ tag: t.keyword, color: '#708' }, | ||
{ tag: [t.atom, t.bool, t.url, t.contentSeparator, t.labelName], color: '#219' }, | ||
{ tag: [t.literal, t.inserted], color: '#164' }, | ||
{ tag: [t.string, t.deleted], color: '#a11' }, | ||
{ tag: [t.regexp, t.escape, t.special(t.string)], color: '#e40' }, | ||
{ tag: t.definition(t.variableName), color: '#00f' }, | ||
{ tag: t.variableName, color: '#30a' }, | ||
{ tag: t.local(t.variableName), color: '#30a' }, | ||
{ tag: [t.typeName, t.namespace], color: '#085' }, | ||
{ tag: t.className, color: '#167' }, | ||
{ tag: [t.special(t.variableName), t.macroName], color: '#256' }, | ||
{ tag: t.definition(t.propertyName), color: '#00c' }, | ||
{ tag: [t.processingInstruction, t.inserted], color: '#05a' }, | ||
{ tag: t.comment, color: '#940' }, | ||
{ tag: t.invalid, color: '#f00' } | ||
]), | ||
{ fallback: true } | ||
); | ||
export const lightHighlightStyle = HighlightStyle.define([ | ||
{ tag: t.meta, color: '#404740' }, | ||
{ tag: t.link, textDecoration: 'underline' }, | ||
{ tag: t.heading, textDecoration: 'underline', fontWeight: 'bold' }, | ||
{ tag: t.emphasis, fontStyle: 'italic' }, | ||
{ tag: t.strong, fontWeight: 'bold' }, | ||
{ tag: t.strikethrough, textDecoration: 'line-through' }, | ||
{ tag: t.keyword, color: '#708' }, | ||
{ tag: [t.atom, t.bool, t.url, t.contentSeparator, t.labelName], color: '#219' }, | ||
{ tag: [t.literal, t.inserted], color: '#164' }, | ||
{ tag: [t.string, t.deleted], color: '#a11' }, | ||
{ tag: [t.regexp, t.escape, t.special(t.string)], color: '#e40' }, | ||
{ tag: t.definition(t.variableName), color: '#00f' }, | ||
{ tag: t.variableName, color: '#30a' }, | ||
{ tag: t.local(t.variableName), color: '#30a' }, | ||
{ tag: [t.typeName, t.namespace], color: '#085' }, | ||
{ tag: t.className, color: '#167' }, | ||
{ tag: [t.special(t.variableName), t.macroName], color: '#256' }, | ||
{ tag: t.definition(t.propertyName), color: '#00c' }, | ||
{ tag: [t.processingInstruction, t.inserted], color: '#05a' }, | ||
{ tag: t.comment, color: '#940' }, | ||
{ tag: t.invalid, color: '#f00' } | ||
]); | ||
|
||
export const lightTheme = syntaxHighlighting(lightHighlightStyle, { fallback: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters