mirror of
https://github.com/Aviortheking/Summernote-CodeWrapper.git
synced 2025-04-22 10:52:12 +00:00
Initial commit
This commit is contained in:
commit
9faf28fd96
76
.gitignore
vendored
Normal file
76
.gitignore
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
|
||||
# Created by https://www.gitignore.io/api/node,sass,code,coffeescript
|
||||
|
||||
### Code ###
|
||||
# Visual Studio Code - https://code.visualstudio.com/
|
||||
.settings/
|
||||
.vscode/
|
||||
tsconfig.json
|
||||
jsconfig.json
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
### Sass ###
|
||||
.sass-cache/
|
||||
*.css.map
|
||||
|
||||
|
||||
# End of https://www.gitignore.io/api/node,sass,code,coffeescript
|
19
.gitlab-ci.yml
Normal file
19
.gitlab-ci.yml
Normal file
@ -0,0 +1,19 @@
|
||||
image: node:latest
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- node_modules/
|
||||
|
||||
before_script:
|
||||
- npm install -g gulp
|
||||
- npm install
|
||||
|
||||
stages:
|
||||
- build_deploy
|
||||
|
||||
build_&_deploy_app:
|
||||
stage: build_deploy
|
||||
only:
|
||||
- master
|
||||
script:
|
||||
- gulp deploy
|
8
.sass-lint.yml
Normal file
8
.sass-lint.yml
Normal file
@ -0,0 +1,8 @@
|
||||
rules:
|
||||
force-element-nesting: false
|
||||
no-qualifying-elements:
|
||||
allow-element-with-class: true
|
||||
indentation:
|
||||
size: 'tab'
|
||||
no-color-literals:
|
||||
allow-rgba: true
|
92
gulpfile.js
Normal file
92
gulpfile.js
Normal file
@ -0,0 +1,92 @@
|
||||
var gulp = require('gulp');
|
||||
var gutil = require('gutil');
|
||||
var pug = require('gulp-pug');
|
||||
var sftp = require('gulp-sftp');
|
||||
var coffee = require('gulp-coffee');
|
||||
var combiner = require('stream-combiner2');
|
||||
var sourcemaps = require('gulp-sourcemaps');
|
||||
var uglifyhtml = require('gulp-html-minifier');
|
||||
var browserSync = require('browser-sync').create();
|
||||
|
||||
gulp.task('pug-process', function(){
|
||||
var res = combiner.obj([
|
||||
gulp.src('src/pug/*.pug'),
|
||||
pug(),
|
||||
uglifyhtml({collapseWhitespace: true}),
|
||||
gulp.dest('build/')
|
||||
]);
|
||||
|
||||
res.on('error', gutil.log);
|
||||
|
||||
return res;
|
||||
});
|
||||
|
||||
gulp.task('pug', ['pug-process'], function (done) {
|
||||
browserSync.reload();
|
||||
done();
|
||||
});
|
||||
|
||||
gulp.task('coffee-process', function(){
|
||||
var res = combiner.obj([
|
||||
gulp.src('src/coffee/**/*'),
|
||||
sourcemaps.init(),
|
||||
coffee({bare: true}),
|
||||
sourcemaps.write(''),
|
||||
gulp.dest('build/js')
|
||||
]);
|
||||
res.on('error', gutil.log);
|
||||
|
||||
return res;
|
||||
});
|
||||
|
||||
gulp.task('coffee', ['coffee-process'], function (done) {
|
||||
browserSync.reload();
|
||||
done();
|
||||
});
|
||||
|
||||
gulp.task('import', function() {
|
||||
var list = [
|
||||
//bootstrap
|
||||
['node_modules/bootstrap/dist/js/bootstrap.min.js', 'js/'],
|
||||
['node_modules/bootstrap/dist/js/bootstrap.min.js.map', 'js/'],
|
||||
['node_modules/bootstrap/dist/css/bootstrap.min.css', 'css/'],
|
||||
['node_modules/bootstrap/dist/css/bootstrap.min.css.map', 'css/'],
|
||||
|
||||
['node_modules/popper.js/dist/umd/popper.min.js', 'js/'],
|
||||
['node_modules/popper.js/dist/umd/popper.min.js.map', 'js/'],
|
||||
|
||||
//jquery
|
||||
['node_modules/jquery/dist/jquery.min.js', 'js/'],
|
||||
['node_modules/jquery/dist/jquery.min.js.map', 'js/'],
|
||||
|
||||
//summernote
|
||||
['src/css/summernote-bs4.css', 'css/'],
|
||||
['node_modules/summernote/dist/summernote-bs4.min.js', 'js/'],
|
||||
['node_modules/summernote/dist/summernote-bs4.min.js.map', 'js/'],
|
||||
['node_modules/summernote/dist/font/*', 'fonts/'],
|
||||
|
||||
//highlight.js
|
||||
['src/js/highlight.pack.js', 'js/'], //come with CSS, javascript, php, sql, c#, diff, json, markdown, shell session, c++, html xml, java, python
|
||||
['src/css/androidstudio.css', 'css/'],
|
||||
];
|
||||
|
||||
list.forEach(element => {
|
||||
gulp.src(element[0]).pipe(gulp.dest('./build/'+element[1])).on('error', gutil.log);
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('build', [ 'pug', 'coffee', 'import']);
|
||||
|
||||
gulp.task('default', ['build'], function() {
|
||||
browserSync.init({
|
||||
server: {
|
||||
baseDir: "build/"
|
||||
}
|
||||
});
|
||||
gulp.watch("src/pug/**/*", ['pug']);
|
||||
gulp.watch("src/coffee/**/*", ['coffee']);
|
||||
});
|
||||
|
||||
gulp.task('stop', function() {
|
||||
process.exit();
|
||||
});
|
6779
package-lock.json
generated
Normal file
6779
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
package.json
Normal file
24
package.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "summernote-codewrapper",
|
||||
"description": "write code beautiful codes snippets in summernote !",
|
||||
"version": "0.1.0",
|
||||
"private": false,
|
||||
"devDependencies": {
|
||||
"browser-sync": "^2.23.7",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-coffee": "^3.0.2",
|
||||
"gulp-html-minifier": "^0.1.8",
|
||||
"gulp-pug": "^4.0.1",
|
||||
"gulp-sftp": "^0.1.5",
|
||||
"gulp-sourcemaps": "^2.6.4",
|
||||
"gutil": "^1.6.4",
|
||||
"stream-combiner2": "^1.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"bootstrap": "^4.1.1",
|
||||
"highlight.js": "^9.12.0",
|
||||
"jquery": "^3.3.1",
|
||||
"popper.js": "^1.14.3",
|
||||
"summernote": "^0.8.10"
|
||||
}
|
||||
}
|
15
src/coffee/script.coffee
Normal file
15
src/coffee/script.coffee
Normal file
@ -0,0 +1,15 @@
|
||||
$(document).ready ->
|
||||
$('.editor').summernote {
|
||||
minHeight: 300,
|
||||
toolbar: [
|
||||
['style', ['bold', 'italic', 'underline', 'clear']],
|
||||
['font', ['strikethrough', 'superscript', 'subscript']],
|
||||
['fontsize', ['fontsize']],
|
||||
['color', ['color']],
|
||||
['para', ['ul', 'ol', 'paragraph']],
|
||||
['height', ['height']],
|
||||
['codeWrapper', ['codeWrapper']],
|
||||
['insert', ['gxcode']],
|
||||
['misc', ['codeview']]
|
||||
]
|
||||
}
|
111
src/coffee/summernote-codewrapper.coffee
Normal file
111
src/coffee/summernote-codewrapper.coffee
Normal file
@ -0,0 +1,111 @@
|
||||
(
|
||||
((factory) ->
|
||||
if typeof define is 'function' and define.amd
|
||||
define ['jquery'], factory
|
||||
else if typeof module is 'object' and module.exports
|
||||
module.exports = factory require 'jquery'
|
||||
else
|
||||
factory window.jQuery
|
||||
return
|
||||
) (($) ->
|
||||
$.extend $.summernote.options, {
|
||||
codewrapper: {
|
||||
menu: [
|
||||
'Update',
|
||||
'javascript',
|
||||
'css',
|
||||
'html'
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
$.extend $.summernote.plugins, {
|
||||
'codeWrapper': (context) ->
|
||||
this.events = {
|
||||
'summernote.enter': (u, e, $editable) ->
|
||||
selection = window.getSelection()
|
||||
correct = selection.anchorNode.nodeName is "CODE" or selection.anchorNode.parentNode.nodeName is "CODE"
|
||||
if correct
|
||||
e.preventDefault()
|
||||
range = window.getSelection().getRangeAt 0
|
||||
range.deleteContents()
|
||||
range.insertNode document.createElement('br')
|
||||
range.addRange 4
|
||||
range.collapse()
|
||||
return
|
||||
|
||||
'summernote.keydown': (u, e) ->
|
||||
selection = window.getSelection()
|
||||
correct = selection.anchorNode.nodeName is "CODE" or selection.anchorNode.parentNode.nodeName is "CODE"
|
||||
if e.key is 'Tab' and correct
|
||||
e.preventDefault()
|
||||
range = selection.getRangeAt 0
|
||||
range.deleteContents()
|
||||
range.insertNode document.createTextNode(' ')
|
||||
range.collapse()
|
||||
return
|
||||
}
|
||||
|
||||
ui = $.summernote.ui
|
||||
options = context.options
|
||||
|
||||
context.memo 'button.codeWrapper', ->
|
||||
button = ui.buttonGroup [
|
||||
ui.button {
|
||||
container: false
|
||||
contents: '<i /> Code'
|
||||
tooltip: 'Code Wrapper'
|
||||
data: {
|
||||
toggle: 'dropdown'
|
||||
}
|
||||
}
|
||||
ui.dropdown {
|
||||
items: options.codewrapper.menu
|
||||
click: (e) ->
|
||||
button = e.target.innerText
|
||||
highlight = window.getSelection()
|
||||
correct = highlight.anchorNode.nodeName is "CODE" or highlight.anchorNode.parentNode.nodeName is "CODE"
|
||||
if button is "Update"
|
||||
$('pre code').each (i, code) ->
|
||||
node = document.createElement 'code'
|
||||
code.childNodes.forEach (el) ->
|
||||
if el.nodeName is '#text' then node.innerHTML += el.wholeText
|
||||
else if el.nodeName is 'BR' then node.innerHTML += '<br />'
|
||||
else node.innerHTML += el.innerText
|
||||
return
|
||||
node.classList = code.classList
|
||||
node.classList.remove 'hljs'
|
||||
parent = code.parentNode
|
||||
parent.removeChild code
|
||||
if hljs then hljs.highlightBlock node
|
||||
parent.appendChild node
|
||||
return
|
||||
else if correct then null
|
||||
else
|
||||
pre = document.createElement 'pre'
|
||||
pre.setAttribute 'autocomplete', 'off'
|
||||
pre.setAttribute 'spellcheck', false
|
||||
code = document.createElement 'code'
|
||||
code.classList.add button
|
||||
code.innerText = highlight
|
||||
pre.appendChild code
|
||||
range = highlight.getRangeAt 0
|
||||
range.deleteContents()
|
||||
range.insertNode pre
|
||||
if hljs then hljs.highlightBlock code
|
||||
range.collapse()
|
||||
return
|
||||
}
|
||||
]
|
||||
|
||||
button.render()
|
||||
|
||||
@destroy = ->
|
||||
@$panel.remove()
|
||||
@$panel = null
|
||||
return
|
||||
return
|
||||
}
|
||||
return
|
||||
)
|
||||
)
|
66
src/css/androidstudio.css
Normal file
66
src/css/androidstudio.css
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
Date: 24 Fev 2015
|
||||
Author: Pedro Oliveira <kanytu@gmail . com>
|
||||
*/
|
||||
|
||||
.hljs {
|
||||
color: #a9b7c6;
|
||||
background: #282b2e;
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.hljs-number,
|
||||
.hljs-literal,
|
||||
.hljs-symbol,
|
||||
.hljs-bullet {
|
||||
color: #6897BB;
|
||||
}
|
||||
|
||||
.hljs-keyword,
|
||||
.hljs-selector-tag,
|
||||
.hljs-deletion {
|
||||
color: #cc7832;
|
||||
}
|
||||
|
||||
.hljs-variable,
|
||||
.hljs-template-variable,
|
||||
.hljs-link {
|
||||
color: #629755;
|
||||
}
|
||||
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color: #808080;
|
||||
}
|
||||
|
||||
.hljs-meta {
|
||||
color: #bbb529;
|
||||
}
|
||||
|
||||
.hljs-string,
|
||||
.hljs-attribute,
|
||||
.hljs-addition {
|
||||
color: #6A8759;
|
||||
}
|
||||
|
||||
.hljs-section,
|
||||
.hljs-title,
|
||||
.hljs-type {
|
||||
color: #ffc66d;
|
||||
}
|
||||
|
||||
.hljs-name,
|
||||
.hljs-selector-id,
|
||||
.hljs-selector-class {
|
||||
color: #e8bf6a;
|
||||
}
|
||||
|
||||
.hljs-emphasis {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hljs-strong {
|
||||
font-weight: bold;
|
||||
}
|
1
src/css/summernote-bs4.css
Normal file
1
src/css/summernote-bs4.css
Normal file
File diff suppressed because one or more lines are too long
2
src/js/highlight.pack.js
Normal file
2
src/js/highlight.pack.js
Normal file
File diff suppressed because one or more lines are too long
28
src/pug/index.pug
Normal file
28
src/pug/index.pug
Normal file
@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
html(lang="en")
|
||||
head
|
||||
meta(charset="UTF-8")
|
||||
meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
||||
meta(http-equiv="X-UA-Compatible", content="ie=edge")
|
||||
title Summernote Code Wrapper
|
||||
|
||||
link(rel="stylesheet" href="css/bootstrap.min.css")
|
||||
link(rel="stylesheet" href="css/androidstudio.css")
|
||||
link(rel="stylesheet", href="css/summernote-bs4.css")
|
||||
body
|
||||
.container
|
||||
.row
|
||||
.editor.col-md-6
|
||||
.col-md-6.markdown-body#result
|
||||
|
||||
|
||||
|
||||
script(src="js/jquery.min.js")
|
||||
script(src="js/popper.min.js")
|
||||
script(src="js/bootstrap.min.js")
|
||||
script(src="js/highlight.pack.js")
|
||||
script(src="js/summernote-bs4.min.js")
|
||||
script(src="js/summernote-codewrapper.js")
|
||||
script(src="js/script.js")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user