mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 02:14:31 +02:00
Fixed some issues in markdown CKEDITOR plugin and remove BBCode plugin.
This commit is contained in:
parent
be8f074ca5
commit
d11a436e74
6 changed files with 26 additions and 1396 deletions
|
@ -1,168 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<!--
|
||||
Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
|
||||
For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>BBCode plugin playground – CKEditor Sample</title>
|
||||
<script src="../../../ckeditor.js"></script>
|
||||
<link href="../../../samples/old/sample.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#editables
|
||||
{
|
||||
float:left;
|
||||
width: 49%
|
||||
}
|
||||
|
||||
#preview
|
||||
{
|
||||
width: 50%;
|
||||
float:right;
|
||||
}
|
||||
|
||||
#console
|
||||
{
|
||||
height: 300px;
|
||||
padding: 5px 10px;
|
||||
border: solid 3px #555;
|
||||
overflow: auto;
|
||||
color: #000;
|
||||
transition: border-color 0.5s;
|
||||
font-family: Monaco, monospace;
|
||||
font-size: 13px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
#console.updated {
|
||||
border-color: #0B0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1 class="samples">
|
||||
CKEditor Sample — BBCode plugin playground
|
||||
</h1>
|
||||
<div id="main">
|
||||
<div class="description">
|
||||
<p>
|
||||
This sample shows how to configure CKEditor to output <a href="http://en.wikipedia.org/wiki/BBCode">BBCode</a> format instead of HTML.
|
||||
Please note that the editor configuration was modified to reflect what is needed in a BBCode editing environment.
|
||||
Smiley images, for example, were stripped to the emoticons that are commonly used in some BBCode dialects.
|
||||
</p>
|
||||
<p>
|
||||
Please note that currently there is no standard for the BBCode markup language, so its implementation
|
||||
for different platforms (message boards, blogs etc.) can vary. This means that before using CKEditor to
|
||||
output BBCode you may need to adjust the implementation to your own environment.
|
||||
</p>
|
||||
<p>
|
||||
A snippet of the configuration code can be seen below; check the source of this page for
|
||||
a full definition:
|
||||
</p>
|
||||
<pre class="samples">
|
||||
CKEDITOR.inline( 'editor1', {
|
||||
<strong>extraPlugins : 'bbcode',</strong>
|
||||
<i>(below configurations details omitted:)</i>
|
||||
toolbar : ...,
|
||||
fontSize_sizes : ...,
|
||||
smiley_images : ...,
|
||||
smiley_descriptions : ...
|
||||
});</pre>
|
||||
</div>
|
||||
|
||||
<div id="editables">
|
||||
<textarea id="editor1">
|
||||
[img]http://a.cksource.com/f/1/img/logo-ckeditor.gif[/img]
|
||||
"[b]Little Red Riding Hood[/b]" is a famous [url=http://en.wikipedia.org/wiki/Fairy_tale]fairy tale[/url] about a young girl's encounter with a wolf. The story has been changed considerably in its history and subject to numerous modern adaptations and readings.
|
||||
[list]
|
||||
[*]Chinese: [i]小紅帽[/i]
|
||||
[*]Italian: [i]Cappuccetto Rosso[/i]
|
||||
[*]Spanish: [i]Caperucita Roja[/i]
|
||||
[/list]
|
||||
[quote]It is about a girl called [color=#FF0000]Little Red Riding Hood :)[/color], after the red [url=http://en.wikipedia.org/wiki/Hood_%28headgear%29]hooded[/url] [url=http://en.wikipedia.org/wiki/Cape]cape[/url] or [url=http://en.wikipedia.org/wiki/Cloak]cloak[/url] she wears.
|
||||
The girl walks through the woods to deliver food to her sick grandmother. A wolf wants to eat the girl but is afraid to do so in public. He approaches the girl, and she naïvely tells him where she is going.
|
||||
He suggests the girl pick some flowers, which she does. In the meantime, he goes to the grandmother's house and gains entry by pretending to be the girl. He swallows the grandmother whole, and waits for the girl, disguised as the grandmother. When the girl arrives, she notices he looks very strange to be her grandma. In most retellings, this eventually culminates with Little Red Riding Hood saying, "My, what big teeth you have!"
|
||||
To which the wolf replies, "The better to eat you with," and swallows her whole, too.[/quote]
|
||||
The above version most widely known today is based on the [url=http://en.wikipedia.org/wiki/Brothers_Grimm]Brothers Grimm[/url] variant.
|
||||
</textarea>
|
||||
</div>
|
||||
<div id="preview">
|
||||
<h3 for="console">BBCode Output: </h3>
|
||||
<pre id="console">
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<hr>
|
||||
<p>
|
||||
CKEditor - The text editor for the Internet - <a class="samples" href="https://ckeditor.com/">https://ckeditor.com</a>
|
||||
</p>
|
||||
<p id="copy">
|
||||
Copyright © 2003-2019, <a class="samples" href="https://cksource.com/">CKSource</a> - Frederico
|
||||
Knabben. All rights reserved.
|
||||
</p>
|
||||
</div>
|
||||
<script>
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var editor = CKEDITOR.replace( 'editor1', {
|
||||
extraPlugins: 'bbcode',
|
||||
// Remove unused plugins.
|
||||
removePlugins: 'bidi,dialogadvtab,div,filebrowser,flash,format,forms,horizontalrule,iframe,justify,liststyle,pagebreak,showborders,stylescombo,table,tabletools,templates',
|
||||
// Width and height are not supported in the BBCode format, so object resizing is disabled.
|
||||
disableObjectResizing: true,
|
||||
height: 250,
|
||||
toolbar: [
|
||||
['Source', '-', 'Save', 'NewPage', '-', 'Undo', 'Redo'],
|
||||
['Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
|
||||
['Link', 'Unlink', 'Image'],
|
||||
'/',
|
||||
['FontSize', 'Bold', 'Italic', 'Underline'],
|
||||
['NumberedList', 'BulletedList', '-', 'Blockquote'],
|
||||
['TextColor', '-', 'Smiley', 'SpecialChar', '-', 'Maximize']
|
||||
],
|
||||
// Define font sizes in percent values.
|
||||
fontSize_sizes: '30/30%;50/50%;100/100%;120/120%;150/150%;200/200%;300/300%',
|
||||
// Strip CKEditor smileys to those commonly used in BBCode.
|
||||
smiley_images: [
|
||||
'regular_smile.png', 'sad_smile.png', 'wink_smile.png', 'teeth_smile.png', 'tongue_smile.png',
|
||||
'embarrassed_smile.png', 'omg_smile.png', 'whatchutalkingabout_smile.png', 'angel_smile.png',
|
||||
'shades_smile.png', 'cry_smile.png', 'kiss.png'
|
||||
],
|
||||
smiley_descriptions: [
|
||||
'smiley', 'sad', 'wink', 'laugh', 'cheeky', 'blush', 'surprise',
|
||||
'indecision', 'angel', 'cool', 'crying', 'kiss'
|
||||
]
|
||||
} );
|
||||
|
||||
function updatePreview() {
|
||||
var consoleEl = CKEDITOR.document.getById( 'console' );
|
||||
consoleEl.addClass( 'updated' );
|
||||
setTimeout( function() { consoleEl.removeClass( 'updated' ); }, 500 );
|
||||
// IE needs <br>, it doesn't even understand new lines.
|
||||
consoleEl.setHtml( editor.getData().replace( /\n\r?/g, '<br>' ) );
|
||||
}
|
||||
|
||||
function checkUpdatePreview() {
|
||||
setTimeout( function() {
|
||||
if ( editor.checkDirty() ) {
|
||||
updatePreview();
|
||||
editor.resetDirty();
|
||||
}
|
||||
}, 0 );
|
||||
}
|
||||
|
||||
editor.on( 'instanceReady', updatePreview );
|
||||
editor.on( 'key', checkUpdatePreview );
|
||||
editor.on( 'selectionChange', checkUpdatePreview );
|
||||
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,5 +1,8 @@
|
|||
/**
|
||||
* This software is licensed under MIT License
|
||||
* A markdown output plugin for CKEDITOR.
|
||||
* Uses showdown.js for conversion and DOMPurifier for HTML filtering.
|
||||
*
|
||||
* This software is licensed under MIT License.
|
||||
*
|
||||
* Copyright (c) 2019 Jan Böhmer
|
||||
*
|
||||
|
@ -24,14 +27,15 @@
|
|||
|
||||
(function() {
|
||||
|
||||
var unchangedData = null;
|
||||
|
||||
function overrideDataProcessor(editor)
|
||||
{
|
||||
//Both showdown and DOMPurify must be loaded
|
||||
if(typeof(showdown) == 'undefined') return;
|
||||
if (typeof(DOMPurify) == 'undefined') return;
|
||||
|
||||
//If the dataprocessor were already be overriden do nothing
|
||||
if(editor.dataProcessor.markdown) return;
|
||||
|
||||
var converter = new showdown.Converter();
|
||||
//Set some useful options on Showdown
|
||||
converter.setFlavor('github');
|
||||
|
@ -42,25 +46,26 @@
|
|||
|
||||
editor.dataProcessor = {
|
||||
toDataFormat: function(html, fixForBody) {
|
||||
html = html.replace(/(\r\n|\n|\r)/gm,"");
|
||||
//html = html.replace(/(\r\n|\n|\r)/gm,"");
|
||||
html = html.replace('<br>', '\n');
|
||||
//Support for strikethrough
|
||||
//Support for strikethrough in markdown
|
||||
html = html.replace('<s>', '<del>').replace('</s>', '</del>');
|
||||
return converter.makeMarkdown(html);
|
||||
},
|
||||
toHtml: function(data) {
|
||||
if(unchangedData) {
|
||||
data = unchangedData;
|
||||
unchangedData = null;
|
||||
}
|
||||
//Strip html tags from data.
|
||||
//This is useful, to convert unsupported HTML feauters to plain text and adds an basic XSS protection
|
||||
//The HTML is inside an iframe so an XSS attack can not do much harm.
|
||||
data = DOMPurify.sanitize(data);
|
||||
|
||||
return tmp = converter.makeHtml(data);
|
||||
toHtml: function(data){
|
||||
//Convert markdown to HTML and remove unsafe things from it.
|
||||
var unsafe = converter.makeHtml(data);
|
||||
return DOMPurify.sanitize(unsafe);
|
||||
},
|
||||
//Mark this dataprocessor
|
||||
markdown: true
|
||||
};
|
||||
|
||||
//Set the original data
|
||||
if(editor.markdown_unchangedData) {
|
||||
editor.setData(editor.markdown_unchangedData);
|
||||
editor.markdown_unchangedData = null;
|
||||
}
|
||||
}
|
||||
|
||||
CKEDITOR.plugins.add( 'markdown', {
|
||||
|
@ -129,20 +134,19 @@
|
|||
var config = editor.config;
|
||||
|
||||
var rootPath = this.path;
|
||||
//We override the dataprocessor later (after we loaded t
|
||||
unchangedData = editor.getData();
|
||||
//We override the dataprocessor later (after we loaded the needes scripts), sow we need the save untouched data now.
|
||||
editor.markdown_unchangedData = editor.getData();
|
||||
|
||||
if (typeof(showdown) == 'undefined') {
|
||||
CKEDITOR.scriptLoader.load(rootPath + 'js/showdown.min.js', function() {
|
||||
overrideDataProcessor(editor);
|
||||
editor.setData(unchangedData);
|
||||
});
|
||||
}, CKEDITOR, true);
|
||||
}
|
||||
|
||||
if (typeof(DOMPurify) == 'undefined') {
|
||||
CKEDITOR.scriptLoader.load(rootPath + 'js/purify.min.js', function() {
|
||||
overrideDataProcessor(editor);
|
||||
});
|
||||
overrideDataProcessor()
|
||||
}, CKEDITOR, true);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -151,5 +155,4 @@
|
|||
overrideDataProcessor(editor);
|
||||
}
|
||||
} );
|
||||
|
||||
} )();
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<!--
|
||||
Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
|
||||
For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>BBCode Plugin — CKEditor Sample</title>
|
||||
<script src="../../../ckeditor.js"></script>
|
||||
<script src="../../../samples/old/sample.js"></script>
|
||||
<link rel="stylesheet" href="../../../samples/old/sample.css">
|
||||
<meta name="ckeditor-sample-required-plugins" content="sourcearea">
|
||||
<meta name="ckeditor-sample-name" content="Output for BBCode">
|
||||
<meta name="ckeditor-sample-group" content="Additional Plugins">
|
||||
<meta name="ckeditor-sample-description" content="Configuring CKEditor to produce BBCode tags instead of HTML.">
|
||||
</head>
|
||||
<body>
|
||||
<h1 class="samples">
|
||||
<a href="../../../samples/old/index.html">CKEditor Samples</a> » BBCode Plugin
|
||||
</h1>
|
||||
<div class="warning deprecated">
|
||||
This sample is not maintained anymore. Check out its <a href="https://ckeditor.com/docs/ckeditor4/latest/examples/bbcode.html">brand new version in CKEditor Examples</a>.
|
||||
</div>
|
||||
<div class="description">
|
||||
<p>
|
||||
This sample shows how to configure CKEditor to output <a href="http://en.wikipedia.org/wiki/BBCode">BBCode</a> format instead of HTML.
|
||||
Please note that the editor configuration was modified to reflect what is needed in a BBCode editing environment.
|
||||
Smiley images, for example, were stripped to the emoticons that are commonly used in some BBCode dialects.
|
||||
</p>
|
||||
<p>
|
||||
Please note that currently there is no standard for the BBCode markup language, so its implementation
|
||||
for different platforms (message boards, blogs etc.) can vary. This means that before using CKEditor to
|
||||
output BBCode you may need to adjust the implementation to your own environment.
|
||||
</p>
|
||||
<p>
|
||||
A snippet of the configuration code can be seen below; check the source of this page for
|
||||
a full definition:
|
||||
</p>
|
||||
<pre class="samples">
|
||||
CKEDITOR.replace( 'editor1', {
|
||||
<strong>extraPlugins: 'bbcode',</strong>
|
||||
toolbar: [
|
||||
[ 'Source', '-', 'Save', 'NewPage', '-', 'Undo', 'Redo' ],
|
||||
[ 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat' ],
|
||||
[ 'Link', 'Unlink', 'Image' ],
|
||||
'/',
|
||||
[ 'FontSize', 'Bold', 'Italic', 'Underline' ],
|
||||
[ 'NumberedList', 'BulletedList', '-', 'Blockquote' ],
|
||||
[ 'TextColor', '-', 'Smiley', 'SpecialChar', '-', 'Maximize' ]
|
||||
],
|
||||
... <i>some other configurations omitted here</i>
|
||||
}); </pre>
|
||||
</div>
|
||||
<form action="../../../samples/sample_posteddata.php" method="post">
|
||||
<p>
|
||||
<label for="editor1">
|
||||
Editor 1:
|
||||
</label>
|
||||
<textarea cols="80" id="editor1" name="editor1" rows="10">This is some [b]sample text[/b]. You are using [url=https://ckeditor.com/]CKEditor[/url].</textarea>
|
||||
<script>
|
||||
|
||||
// Replace the <textarea id="editor"> with an CKEditor
|
||||
// instance, using the "bbcode" plugin, shaping some of the
|
||||
// editor configuration to fit BBCode environment.
|
||||
CKEDITOR.replace( 'editor1', {
|
||||
extraPlugins: 'bbcode',
|
||||
// Remove unused plugins.
|
||||
removePlugins: 'bidi,dialogadvtab,div,filebrowser,flash,format,forms,horizontalrule,iframe,justify,liststyle,pagebreak,showborders,stylescombo,table,tabletools,templates',
|
||||
// Width and height are not supported in the BBCode format, so object resizing is disabled.
|
||||
disableObjectResizing: true,
|
||||
// Define font sizes in percent values.
|
||||
fontSize_sizes: "30/30%;50/50%;100/100%;120/120%;150/150%;200/200%;300/300%",
|
||||
toolbar: [
|
||||
[ 'Source', '-', 'Save', 'NewPage', '-', 'Undo', 'Redo' ],
|
||||
[ 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat' ],
|
||||
[ 'Link', 'Unlink', 'Image', 'Smiley', 'SpecialChar' ],
|
||||
'/',
|
||||
[ 'Bold', 'Italic', 'Underline' ],
|
||||
[ 'FontSize' ],
|
||||
[ 'TextColor' ],
|
||||
[ 'NumberedList', 'BulletedList', '-', 'Blockquote' ],
|
||||
[ 'Maximize' ]
|
||||
],
|
||||
// Strip CKEditor smileys to those commonly used in BBCode.
|
||||
smiley_images: [
|
||||
'regular_smile.png', 'sad_smile.png', 'wink_smile.png', 'teeth_smile.png', 'tongue_smile.png',
|
||||
'embarrassed_smile.png', 'omg_smile.png', 'whatchutalkingabout_smile.png', 'angel_smile.png',
|
||||
'shades_smile.png', 'cry_smile.png', 'kiss.png'
|
||||
],
|
||||
smiley_descriptions: [
|
||||
'smiley', 'sad', 'wink', 'laugh', 'cheeky', 'blush', 'surprise',
|
||||
'indecision', 'angel', 'cool', 'crying', 'kiss'
|
||||
]
|
||||
});
|
||||
|
||||
</script>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" value="Submit">
|
||||
</p>
|
||||
</form>
|
||||
<div id="footer">
|
||||
<hr>
|
||||
<p>
|
||||
CKEditor - The text editor for the Internet - <a class="samples" href="https://ckeditor.com/">https://ckeditor.com</a>
|
||||
</p>
|
||||
<p id="copy">
|
||||
Copyright © 2003-2019, <a class="samples" href="https://cksource.com/">CKSource</a> - Frederico
|
||||
Knabben. All rights reserved.
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue