Skip to content
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
2 changes: 1 addition & 1 deletion build/codeflask.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/codeflask.module.js

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import * as prism from 'prismjs';

export as namespace codeflask

export type LanguageDefinition = {
[token: string]: prism.LanguageDefinition | RegExp
}

export interface CodeFlaskOptions {
language?: string
Expand All @@ -16,14 +12,14 @@ export interface CodeFlaskOptions {
areaId?: string
ariaLabelledby?: string
readonly?: boolean
highLighter?: function
}

export default class CodeFlask {
constructor(selectorOrElement: Element | string, opts: CodeFlaskOptions)

updateCode(newCode: string): void
updateLanguage(newLanguage: string): void
addLanguage(name: string, options: LanguageDefinition): void

getCode(): string
onUpdate(callback: (code: string) => void): void
Expand Down
10 changes: 1 addition & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,16 @@
"prepublishOnly": "npm install && npm run build"
},
"dependencies": {
"@types/prismjs": "^1.9.1",
"prismjs": "^1.14.0"
},
"devDependencies": {
"chai": "^4.1.2",
"chromedriver": "^2.38.3",
"micro": "^9.3.0",
"mocha": "^5.1.1",
"rollup": "^0.58.1",
"rollup-plugin-buble": "^0.19.2",
"rollup-plugin-commonjs": "^9.1.0",
"rollup-plugin-node-resolve": "^3.0.3",
"rollup-plugin-uglify": "^3.0.0",
"serve": "^7.0.0",
"wdio-chromedriver-service": "^0.1.3",
"wdio-mocha-framework": "^0.5.13",
"wdio-spec-reporter": "^0.1.4",
"webdriverio": "^4.12.0"
"rollup-plugin-uglify": "^3.0.0"
},
"repository": {
"type": "git",
Expand Down
20 changes: 9 additions & 11 deletions src/codeflask.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { editorCss } from './styles/editor'
import { injectCss } from './styles/injector'
import { defaultCssTheme } from './styles/theme-default'
import { escapeHtml } from './utils/html-escape'
import Prism from 'prismjs'

export default class CodeFlask {
constructor (selectorOrElement, opts) {
Expand Down Expand Up @@ -52,8 +51,8 @@ export default class CodeFlask {

this.runOptions()
this.listenTextarea()
this.populateDefault()
this.updateCode(this.code)
this.populateDefault(this.opts.noInitialCallback)
this.updateCode(this.code,this.opts.noInitialCallback)
}

createWrapper () {
Expand Down Expand Up @@ -100,6 +99,7 @@ export default class CodeFlask {
this.opts.areaId = this.opts.areaId || null
this.opts.ariaLabelledby = this.opts.ariaLabelledby || null
this.opts.readonly = this.opts.readonly || null
this.opts.noInitialCallback = this.opts.noInitialCallback || false;

// if handleTabs is not either true or false, make it true by default
if (typeof this.opts.handleTabs !== 'boolean') {
Expand Down Expand Up @@ -146,6 +146,7 @@ export default class CodeFlask {
if (this.opts.readonly) {
this.enableReadonlyMode()
}
this.opts.highLighter=this.opts.highLighter||function(){}
}

updateLineNumbersCount () {
Expand Down Expand Up @@ -371,13 +372,13 @@ export default class CodeFlask {
return [')', '}', ']', '>'].includes(char) || (['\'', '"'].includes(char) && !hasSelection)
}

updateCode (newCode) {
updateCode (newCode,preventCallback) {
this.code = newCode
this.elTextarea.value = newCode
this.elCode.innerHTML = escapeHtml(newCode)
this.highlight()
this.setLineNumber()
setTimeout(this.runUpdate.bind(this), 1)
if (! preventCallback) setTimeout(this.runUpdate.bind(this), 1)
}

updateLanguage (newLanguage) {
Expand All @@ -388,16 +389,13 @@ export default class CodeFlask {
this.highlight()
}

addLanguage (name, options) {
Prism.languages[name] = options
}

populateDefault () {
this.updateCode(this.code)
populateDefault (preventCallback) {
this.updateCode(this.code,preventCallback)
}

highlight () {
Prism.highlightElement(this.elCode, false)
this.opts.highLighter(this.elCode, false)
}

onUpdate (callback) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/css-supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export function cssSupports (property, value) {
return CSS.supports(property, value)
}

if (typeof document === 'undefined') {
if (typeof(document) !== 'object' || typeof(document.body) !== 'object' || document.body == null || typeof(document.body.style) !== 'object' || document.body.style == null ) {
return false;
}

Expand Down