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

Code Highlight C Code and new option customStyleSheet #56

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ quizdown is easy to setup and best used in combination with existing static site

### 📚 [Documentation](./docs/)



## Stand-alone Example

Add the library to your website and initialize with default options:
Expand Down Expand Up @@ -81,7 +79,23 @@ Write questions within a `quizdown` class (edit in the [🚀quizdown editor](htt
...
```


## Additional Options

| Option | Type | Description | Default Value |
| ------ | ---- | ----------- | --- |
| startOnLoad | boolean | Parse the Quiz at loading | `True` |
| shuffleAnswers | boolean | Shuffle the answers | `True` |
| shuffleQuestions | boolean | Shuffle the questions | `False` |
| nQuestions | number | Number of questions | undefined |
| primaryColor | string | Color of the progress bar | 'steelblue' |
| secondaryColor | string | Background color of the selections | '#f2f2f2' |
| textColor | string | Color of the text | 'black' |
| passingGrade | number | Number of points to success. | undefined |
| customPassMsg | string | Success message. Only displayed if passingGrade is set and reached | 'You have passed' |
| customFailMsg | string | Failure message. Only displayed if passingGrade is set and not passed | 'You have not passed' |
| locale | string | Used language. Possible are 'de', 'en', 'es', 'fr' | null |
| enableRetry | boolean | Enable Retry button | `True` |
| customStyleSheet | string | Add an own css file for style updating | 'customQuizdown.css' |

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion public/build/extensions/quizdownHighlight.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions public/build/quizdown.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,23 @@
let node: HTMLElement;
let minHeight = 150;
let reloaded = false;
let customCssFile = ""
// let showModal = false;

// set global options
onMount(async () => {
let primaryColor: string = quiz.config.primaryColor;
let secondaryColor: string = quiz.config.secondaryColor;
let textColor: string = quiz.config.textColor;
customCssFile = quiz.config.customStyleSheet;

node.style.setProperty('--quizdown-color-primary', primaryColor);
node.style.setProperty('--quizdown-color-secondary', secondaryColor);
node.style.setProperty('--quizdown-color-text', textColor);
node.style.minHeight = `${minHeight}px`;
});
</script>

<link rel="stylesheet" href={customCssFile}>
<div class="quizdown-content" bind:this="{node}">
<Card>
<ProgressBar value="{$index}" max="{quiz.questions.length - 1}" />
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class Config {
customFailMsg: string;
locale: 'de' | 'en' | 'es' | 'fr' | null;
enableRetry: boolean;
customStyleSheet: string;

constructor(options: Config | object) {
// handle <=v0.3.0 snake_case options for backwards compatibility
Expand All @@ -49,6 +50,7 @@ export class Config {
this.customFailMsg = get(options['customFailMsg'], 'You have not passed');
this.locale = get(options['locale'], null);
this.enableRetry = get(options['enableRetry'],true);
this.customStyleSheet = get(options['customStyleSheet'], 'customQuizdown.css');
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/extensions/quizdownHighlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import plaintext from 'highlight.js/lib/languages/plaintext';
import python from 'highlight.js/lib/languages/python';
import typescript from 'highlight.js/lib/languages/typescript';
import xml from 'highlight.js/lib/languages/xml';
import c from 'highlight.js/lib/languages/c';
import type { QuizdownExtension } from '../quizdown.js';

// this does not work....
Expand All @@ -23,6 +24,7 @@ hljs.registerLanguage('plaintext', plaintext);
hljs.registerLanguage('python', python);
hljs.registerLanguage('typescript', typescript);
hljs.registerLanguage('html', xml);
hljs.registerLanguage('c', c);

function highlighter(code, language) {
const validLanguage = hljs.getLanguage(language) ? language : 'plaintext';
Expand Down