Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Added go,ts,java to languages list #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
465 changes: 463 additions & 2 deletions dist/editorjs-codeflask.bundle.js

Large diffs are not rendered by default.

24 changes: 5 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"name": "@calumk/editorjs-codeflask",
"name": "@samandar.boymurodov/editorjs-codeflask",
"description": "Codeflask, for EditorJS",
"version": "1.0.9",

"version": "1.0.11",
"author": "Calum Knott",
"repository": "https://github.com/calumk/editorjs-codeflask",
"repository": "https://github.com/samandar-boymurodov/editorjs-codeflask",
"license": "MIT",

"main": "./dist/editorjs-codeflask.bundle.js",
"scripts": {
"build": "webpack --mode production"
"build": "webpack --mode production",
"build:dev": "webpack --mode development --watch"
},

"dependencies": {
"codeflask": "^1.4.1",
"nice-select2": "^2.0.0",
Expand Down
72 changes: 36 additions & 36 deletions src/codeflask.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* @author Calum Knott (calum@calumk.com)
* @license The MIT License (MIT)
*/

/**
* @typedef {object} EditorJsCodeFlaskConfig
* @property {string} placeholder - placeholder for the empty EditorJsCodeFlask
* @property {boolean} preserveBlank - Whether or not to keep blank EditorJsCodeFlasks when saving editor data
*/

/**
* @typedef {Object} EditorJsCodeFlaskData
* @description Tool's input and output data format
Expand All @@ -23,27 +23,26 @@

import Prism from 'prismjs';

// Additional languages
import "prismjs/components/prism-java"
import "prismjs/components/prism-go"
import "prismjs/components/prism-typescript"

// import "prismjs-components-importer/esm"; // ALL - Massivly Increases Bundle size!

import "prismjs-components-importer/esm/prism-iecst"; // Structured Text
import "prismjs-components-importer/esm/prism-markdown";
import "prismjs-components-importer/esm/prism-json";
import "prismjs-components-importer/esm/prism-markdown";
import "prismjs-components-importer/esm/prism-json";
import "prismjs-components-importer/esm/prism-python";
import "prismjs-components-importer/esm/prism-bash";


import CodeFlask from 'codeflask';

import NiceSelect from "nice-select2/dist/js/nice-select2";
import NiceSelectStyle from "nice-select2/dist/css/nice-select2.css";
import { EXCLUDED_LANGUAGES } from "./vars";




// console.log(Prism.languages)



class EditorJsCodeFlask {
/**
* Default placeholder for EditorJsCodeFlask Tool
Expand All @@ -58,7 +57,7 @@
static get enableLineBreaks() {
return true;
}

/**
* Render plugin`s main Element and fill it with saved data
*
Expand All @@ -72,18 +71,18 @@
// console.log(data)
this.api = api;
this.readOnly = readOnly;

this._CSS = {
block: this.api.styles.block,
wrapper: 'ce-EditorJsCodeFlask',
settingsButton: this.api.styles.settingsButton,
settingsButtonActive: this.api.styles.settingsButtonActive,
};

if (!this.readOnly) {
this.onKeyUp = this.onKeyUp.bind(this);
}

/**
* Placeholder for EditorJsCodeFlask if it is first Block
* @type {string}
Expand All @@ -94,7 +93,7 @@

this._element; // used to hold the wrapper div, as a point of reference



// let x = (x === undefined) ? your_default_value : x;
this.data = {}
Expand All @@ -106,7 +105,7 @@
// console.log(this.data)

}

/**
* Check if text content is empty and set empty string to inner html.
* We need this because some browsers (e.g. Safari) insert <br> into empty contenteditanle elements
Expand All @@ -117,15 +116,15 @@
if (e.code !== 'Backspace' && e.code !== 'Delete') {
return;
}

const {textContent} = this._element;

if (textContent === '') {
this._element.innerHTML = '';
}
}


/**
* Return Tool's view
*
Expand All @@ -145,8 +144,8 @@
this._element.appendChild(editorElem)
this._element.appendChild(langdisplay)

this.data.editorInstance = new CodeFlask(editorElem, {
language: this.data.language,
this.data.editorInstance = new CodeFlask(editorElem, {
language: this.data.language,
lineNumbers : this.data.showlinenumbers,
readonly : this.readOnly
});
Expand Down Expand Up @@ -198,15 +197,15 @@
//Create and append the options
for (var i = 0; i < languages.length; i++) {
// Weirdly PrismJS doesnt expose a list of installed languages, or rather it does, but it is mixed with helper functions, which i have to clear here.
if (languages[i] == "extend" || languages[i] == "insertBefore" || languages[i] == "DFS") {
if (EXCLUDED_LANGUAGES.includes(languages[i])) {
continue;
}

var option = document.createElement("option");
option.value = languages[i];
option.text = languages[i];
if(languages[i] == this.data.language){
option.selected="selected"
if(languages[i] === this.data.language){
option.selected = "selected"
}
languagesSelect.appendChild(option);
}
Expand All @@ -232,7 +231,7 @@

settingsContainer.appendChild(languagesSelect);
new NiceSelect(languagesSelect, {searchable : true, placeholder : "Language..."});

// settingsContainer.appendChild(settingsButton);

return settingsContainer;
Expand All @@ -249,12 +248,13 @@

_updateLanguage = (lang) => {
this.data.language = lang
this._element.querySelector('.editorjs-codeFlask_LangDisplay').innerHTML = this.data.language
this.data.editorInstance.updateLanguage(this.data.language)
this._element.querySelector('.editorjs-codeFlask_LangDisplay').innerHTML = lang
this.data.editorInstance.addLanguage(lang, Prism.languages[lang])
this.data.editorInstance.updateLanguage(lang)
}





/**
* Extract Tool's data from the view
* @param {HTMLDivElement} toolsContent - EditorJsCodeFlask tools rendered view
Expand All @@ -267,10 +267,10 @@
language : this.data.language,
showlinenumbers : this.data.showlinenumbers
};

return resp
}

/**
* Returns true to notify the core that read-only mode is supported
*
Expand All @@ -280,7 +280,7 @@
return true;
}


/**
* Icon and title for displaying at the Toolbox
*
Expand All @@ -293,5 +293,5 @@
};
}
}
export { EditorJsCodeFlask as default }

export { EditorJsCodeFlask as default }
1 change: 1 addition & 0 deletions src/vars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const EXCLUDED_LANGUAGES = ["js", 'py', "ts", "txt", "md", 'plaintext', 'extend', 'insertBefore', "DFS"]